make unknown string a member

This commit is contained in:
wellenvogel 2021-11-22 11:21:27 +01:00
parent 1d24fd3732
commit 6201644e60
2 changed files with 12 additions and 10 deletions

View File

@ -374,7 +374,7 @@ GwXDRFoundMapping GwXDRMappings::getMapping(GwXDRCategory category,int selector,
}
return rt;
}
#define MAX_UNKNOWN 200
bool GwXDRMappings::addUnknown(GwXDRCategory category,int selector,int field,int instance){
if (unknown.size() >= 200) return false;
unsigned long uk=((int)category) &0x7f;
@ -388,16 +388,14 @@ bool GwXDRMappings::addUnknown(GwXDRCategory category,int selector,int field,int
return true;
}
char * GwXDRMappings::getUnMapped(){
const int ESIZE=13;
int sz=(unknown.size()+1)*ESIZE;
char *rt=new char[sz];
*rt=0;
char *ptr=rt;
const char * GwXDRMappings::getUnMapped(){
if (unknowAsString == NULL) unknowAsString=new char[(MAX_MAPPINGS+1)*ESIZE];
*unknowAsString=0;
char *ptr=unknowAsString;
for (auto it=unknown.begin();it!=unknown.end();it++){
snprintf(ptr,ESIZE-1,"%lu,",*it);
*(ptr+ESIZE-1)=0;
while (*ptr != 0) ptr++;
}
return rt;
return unknowAsString;
}

View File

@ -164,13 +164,18 @@ class GwXDRFoundMapping{
}
};
//the class GwXDRMappings is not intended to be deleted
//the deletion will leave memory leaks!
class GwXDRMappings{
static const int MAX_UNKNOWN=200;
static const int ESIZE=13;
private:
GwLog *logger;
GwConfigHandler *config;
GwXDRMapping::N138Map n183Map;
GwXDRMapping::N2KMap n2kMap;
std::unordered_set<unsigned long> unknown;
char *unknowAsString=NULL;
GwXDRFoundMapping selectMapping(GwXDRMapping::MappingList *list,int instance,const char * key);
bool addUnknown(GwXDRCategory category,int selector,int field=0,int instance=-1);
public:
@ -180,8 +185,7 @@ class GwXDRMappings{
//the returned mapping will exactly contain one mapping def
GwXDRFoundMapping getMapping(String xName,String xType,String xUnit);
GwXDRFoundMapping getMapping(GwXDRCategory category,int selector,int field=0,int instance=-1);
//returns a newly created buffer - user must destroy!
char * getUnMapped();
const char * getUnMapped();
};