how to typedef array of 4 char to be used in map template
-
Hi Mainframe data big endian which I am trying to typedef 4 bytes I would rather not do it as int I tried the following typedef char ESDID[4] where ESDID would represent 4 bytes I also have this type ESDID in structure and would like to use it as a key for example
struct syminfo
{
unsigned char recordtype;
unsigned char recordtypeflag;
ESDID symesdid;
BYTE seclen[4];
ESDID eseclen;
char* symname;};
I am getting all sort of comple errors when I map it
syminfo* exsympointer = (syminfo*)procpointer->buffer;
procpointer->extsymcollector.insert(std::pair(exsympointer->symesdid, \*exsympointer));
The map is define as such
map extsymcollector;
I think thesee aerror are from the way I tried to typdef ESDID if also tried to set as an struct type struct ESDID { char x[4]; }; either way I get errors
-
Hi Mainframe data big endian which I am trying to typedef 4 bytes I would rather not do it as int I tried the following typedef char ESDID[4] where ESDID would represent 4 bytes I also have this type ESDID in structure and would like to use it as a key for example
struct syminfo
{
unsigned char recordtype;
unsigned char recordtypeflag;
ESDID symesdid;
BYTE seclen[4];
ESDID eseclen;
char* symname;};
I am getting all sort of comple errors when I map it
syminfo* exsympointer = (syminfo*)procpointer->buffer;
procpointer->extsymcollector.insert(std::pair(exsympointer->symesdid, \*exsympointer));
The map is define as such
map extsymcollector;
I think thesee aerror are from the way I tried to typdef ESDID if also tried to set as an struct type struct ESDID { char x[4]; }; either way I get errors
But you need the values of ESDID characters as key for the map. something like this could do the trick
struct ESDID
{
char c[4];
uint32_t operator()(){return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//..
map m;
//..
syminfo s1;
m.insert( pair(s1.symesdid(), s1) );"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
But you need the values of ESDID characters as key for the map. something like this could do the trick
struct ESDID
{
char c[4];
uint32_t operator()(){return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//..
map m;
//..
syminfo s1;
m.insert( pair(s1.symesdid(), s1) );"In testa che avete, Signor di Ceprano?" -- Rigoletto
A few questions first of I am not on your level of C++ but i am getting there so my first question is anytime you code a key as a structure you need code to tell it how to handle, format, compare that key ? is that right ? second my data is big edian so DC F'10' lays out in storage 00000000 00000000 00000000 0000000A so the code shifts thngs back to little edian as int x = 10 would be A0000000 00000000 00000000 00000000 your map statement below the structure why can it not be map m;
-
A few questions first of I am not on your level of C++ but i am getting there so my first question is anytime you code a key as a structure you need code to tell it how to handle, format, compare that key ? is that right ? second my data is big edian so DC F'10' lays out in storage 00000000 00000000 00000000 0000000A so the code shifts thngs back to little edian as int x = 10 would be A0000000 00000000 00000000 00000000 your map statement below the structure why can it not be map m;
Quote:
so my first question is anytime you code a key as a structure you need code to tell it how to handle, format, compare that key ? is that right ?
Generally speaking, you haven't. However, in your scenario, you have to, because the key you need is the value stored inside the characters, not the reference to the struct.
Quote:
second my data is big edian so DC F'10' lays out in storage 00000000 00000000 00000000 0000000A so the code shifts thngs back to little edian as int x = 10 would be A0000000 00000000 00000000 00000000
Kind of that. Note you actually don't even need the key being big-endian.
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
Quote:
so my first question is anytime you code a key as a structure you need code to tell it how to handle, format, compare that key ? is that right ?
Generally speaking, you haven't. However, in your scenario, you have to, because the key you need is the value stored inside the characters, not the reference to the struct.
Quote:
second my data is big edian so DC F'10' lays out in storage 00000000 00000000 00000000 0000000A so the code shifts thngs back to little edian as int x = 10 would be A0000000 00000000 00000000 00000000
Kind of that. Note you actually don't even need the key being big-endian.
"In testa che avete, Signor di Ceprano?" -- Rigoletto
Ok thank you again I am at work now I will compile it afterwards I have another map with a key made up of few elements in a structure Had compile errors but I think if I do what you just did insert code in the the structure with a for lack of a better term dummy in-line call in the structure with the operator()() {}; I may be able to straighten it out a lot of this code I can use on the z/os mainframe so I am hoping outside of a few #ifdef _MSVC_ for the big Edian to little Edian conversion it will compile with the XL C\C++ compiler it too has a STL library thank you again
-
Quote:
so my first question is anytime you code a key as a structure you need code to tell it how to handle, format, compare that key ? is that right ?
Generally speaking, you haven't. However, in your scenario, you have to, because the key you need is the value stored inside the characters, not the reference to the struct.
Quote:
second my data is big edian so DC F'10' lays out in storage 00000000 00000000 00000000 0000000A so the code shifts thngs back to little edian as int x = 10 would be A0000000 00000000 00000000 00000000
Kind of that. Note you actually don't even need the key being big-endian.
"In testa che avete, Signor di Ceprano?" -- Rigoletto
Hi I inserted the definitions you provided however I am still getting compile errors
struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xstddef(127,22): error C2676: binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator
1> with
1> [
1> _Ty=ESDID
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xstddef(126): message : while compiling class template member function 'bool std::less::operator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Ty=ESDID
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xutility(1518): message : see reference to function template instantiation 'bool std::less::operator ()(const _Ty &,const _Ty &) const' being compiled
1> with
1> [
1> _Ty=ESDID
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xmemory(1380): message : see reference to class template instantiation 'std::less' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xmemory(1380): message : see reference to variable template 'const bool is_empty_v >' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\map(75): message : see reference to class template instantiation 'std::_Tree>' being compiled
1> with
1> [
1> _Kty=ESDID,
1> _Ty=extsymbol,
1> _Pr=std::less,
1> _Alloc=std::allocator>
1> ]here is my definition of type extsymbol not quite sure where the error is from
struct extsymbol
{unsigned char recordtype; unsigned char recordtypeflag; BYTE reserved1\[4\]; ESDID SYMESDID; BYTE reserved2\[4\]; BYTE align\[4\]; BYTE seclen\[4\]; ESDID sumower; BYTE reserved3\[8\]; BYTE nmeoffset\[4\]; BYTE nmelen\[4\]; BYTE aliasoffset\[4\]; BYTE alisnmelen; char symname\[63\];
};
Here is the code the references extsymbo
-
Hi I inserted the definitions you provided however I am still getting compile errors
struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xstddef(127,22): error C2676: binary '<': 'const _Ty' does not define this operator or a conversion to a type acceptable to the predefined operator
1> with
1> [
1> _Ty=ESDID
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xstddef(126): message : while compiling class template member function 'bool std::less::operator ()(const _Ty &,const _Ty &) const'
1> with
1> [
1> _Ty=ESDID
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xutility(1518): message : see reference to function template instantiation 'bool std::less::operator ()(const _Ty &,const _Ty &) const' being compiled
1> with
1> [
1> _Ty=ESDID
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xmemory(1380): message : see reference to class template instantiation 'std::less' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xmemory(1380): message : see reference to variable template 'const bool is_empty_v >' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\map(75): message : see reference to class template instantiation 'std::_Tree>' being compiled
1> with
1> [
1> _Kty=ESDID,
1> _Ty=extsymbol,
1> _Pr=std::less,
1> _Alloc=std::allocator>
1> ]here is my definition of type extsymbol not quite sure where the error is from
struct extsymbol
{unsigned char recordtype; unsigned char recordtypeflag; BYTE reserved1\[4\]; ESDID SYMESDID; BYTE reserved2\[4\]; BYTE align\[4\]; BYTE seclen\[4\]; ESDID sumower; BYTE reserved3\[8\]; BYTE nmeoffset\[4\]; BYTE nmelen\[4\]; BYTE aliasoffset\[4\]; BYTE alisnmelen; char symname\[63\];
};
Here is the code the references extsymbo
-
This
Quote:
procpointer->extsymcollector.insert({ exsympointer->SYMESDID, *exsympointer });
should be instead
procpointer->extsymcollector.insert({ exsympointer->SYMESDID(), *exsympointer });
"In testa che avete, Signor di Ceprano?" -- Rigoletto
That gives a error of type mismatch me thinks I need a == operator inside struct esdid to tell it how to do the insert I THINK ( because ) you are the expert anytime you try to insert a type struct the insert method needs to know how to compare therefore I think compare operators I.E == , < , >
-
That gives a error of type mismatch me thinks I need a == operator inside struct esdid to tell it how to do the insert I THINK ( because ) you are the expert anytime you try to insert a type struct the insert method needs to know how to compare therefore I think compare operators I.E == , < , >
-
That (probably) gives type mismatch because you declared the map this way
map
But you shouldn't do that. Instead you should declare it like
map
"In testa che avete, Signor di Ceprano?" -- Rigoletto
now I am I am getting this
\]
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '1': no conversion from 'ESDID' to 'std::pair'
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '2': no conversion from 'syminfo' to 'std::pair'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xtree(1283,10): message : see declaration of 'std::_Tree>::insert'
1> with
1> [
1> _Kty=uint32_t,
1> _Ty=syminfo,
1> _Pr=std::less,
1> _Alloc=std::allocator>
1> ] -
now I am I am getting this
\]
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '1': no conversion from 'ESDID' to 'std::pair'
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '2': no conversion from 'syminfo' to 'std::pair'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\include\xtree(1283,10): message : see declaration of 'std::_Tree>::insert'
1> with
1> [
1> _Kty=uint32_t,
1> _Ty=syminfo,
1> _Pr=std::less,
1> _Alloc=std::allocator>
1> ] -
Did you try
procpointer->extsymcollector.insert(std::pair(exsympointer->SYMESDID(), *exsympointer ));
?
"In testa che avete, Signor di Ceprano?" -- Rigoletto
-
But you need the values of ESDID characters as key for the map. something like this could do the trick
struct ESDID
{
char c[4];
uint32_t operator()(){return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//..
map m;
//..
syminfo s1;
m.insert( pair(s1.symesdid(), s1) );"In testa che avete, Signor di Ceprano?" -- Rigoletto
The complier was screaming for < operator so I give it what wants hope this works got a clean complie
const struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
BOOL operator< (const ESDID x) const { return c < x.c; }
}; -
The complier was screaming for < operator so I give it what wants hope this works got a clean complie
const struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
BOOL operator< (const ESDID x) const { return c < x.c; }
};That compiles. However it is probably NOT what you want (both the key of the map and the
<
operator use the address of thec
array). RunESDID e1, e2;
// init e1, e2 with the same content
e1.c[0] = e1.c[1] = e1.c[2] = e1.c[3] = 'A';
e2.c[0] = e2.c[1] = e2.c[2] = e2.c[3] = 'A';cout << std::boolalpha;
cout << "(e1 < e2) " << (e1 < e2) << "\n";
cout << "(e2 < e1) " << (e2 < e1) << "\n";and watch the resulting output. Can you spot the problem? You can do something like this:
struct ESDID
{
char c[4];
// overload of the cast operator
operator uint32_t () const { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//...
syminfo s1;
map m;
m.insert( pair(s1.symesdid, s1) );Note the key of the map uses the content of the
c
array."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
The complier was screaming for < operator so I give it what wants hope this works got a clean complie
const struct ESDID
{
char c[4];
uint32_t operator()() { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
BOOL operator< (const ESDID x) const { return c < x.c; }
}; -
That compiles. However it is probably NOT what you want (both the key of the map and the
<
operator use the address of thec
array). RunESDID e1, e2;
// init e1, e2 with the same content
e1.c[0] = e1.c[1] = e1.c[2] = e1.c[3] = 'A';
e2.c[0] = e2.c[1] = e2.c[2] = e2.c[3] = 'A';cout << std::boolalpha;
cout << "(e1 < e2) " << (e1 < e2) << "\n";
cout << "(e2 < e1) " << (e2 < e1) << "\n";and watch the resulting output. Can you spot the problem? You can do something like this:
struct ESDID
{
char c[4];
// overload of the cast operator
operator uint32_t () const { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
//...
syminfo s1;
map m;
m.insert( pair(s1.symesdid, s1) );Note the key of the map uses the content of the
c
array."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
Alternatively you could use a union?
const struct ESDID
{
union
{
char c[4];
uint32_t i;
} x;
bool operator< (const ESDID e) const { return x.i < e.x.i; }
}; -
thanks richard I dont see in the map documentation when using the insert method with key of type struct '<' operator must be overloaded by the user
Actually there is (see std::map - cppreference.com[^]):
template<
class Key,
class T,
class Compare = std::less,
class Allocator = std::allocator>class map;
As it should be, because the
std::map
is a sorted container."In testa che avete, Signor di Ceprano?" -- Rigoletto
-
I understand the compare wont work correctly however what I dont see where the cast operator () is being used> Is dynamic cast used with pair i.e <> the same as the () operator ()
-
Actually there is (see std::map - cppreference.com[^]):
template<
class Key,
class T,
class Compare = std::less,
class Allocator = std::allocator>class map;
As it should be, because the
std::map
is a sorted container."In testa che avete, Signor di Ceprano?" -- Rigoletto