|
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 <uint32_t, syminfo> m;
syminfo s1;
m.insert( pair<uint32_t, syminfo>(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 <esdid, syminfo=""> 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
|
|
|
|
|
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
|
|
|
|
|
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<ESDID>::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<ESDID>::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<ESDID>' 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<std::less<ESDID> >' 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<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>' being compiled
1> with
1> [
1> _Kty=ESDID,
1> _Ty=extsymbol,
1> _Pr=std::less<ESDID>,
1> _Alloc=std::allocator<std::pair<const ESDID,extsymbol>>
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 extsymbol
case 0x0020:
{
extsymbol* exsympointer = (extsymbol*)procpointer->buffer;
procpointer->extsymcollector.insert({ exsympointer->SYMESDID, *exsympointer });
procpointer->extsymcollector.insert({ exsympointer->SYMESDID, *exsympointer });
}
|
|
|
|
|
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 (probably) gives type mismatch because you declared the map this way
map<ESDID, syminfo>
But you shouldn't do that. Instead you should declare it like
map <uint32_t, syminfo>
"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<const uint32_t,syminfo>'
1>C:\SYSADATA\SYSADATA\SYSADATA\getnextsource.cpp(213,36): message : Element '2': no conversion from 'syminfo' to 'std::pair<const uint32_t,syminfo>'
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<std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,false>>::insert'
1> with
1> [
1> _Kty=uint32_t,
1> _Ty=syminfo,
1> _Pr=std::less<uint32_t>,
1> _Alloc=std::allocator<std::pair<const uint32_t,syminfo>>
1> ]
|
|
|
|
|
Did you try
procpointer->extsymcollector.insert(std::pair<uint32_t, syminfo>(exsympointer->SYMESDID(), *exsympointer )); ?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
still getting type mismatch will have to look at this after work think it maybe using compare operators in the struct thank you
|
|
|
|
|
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 the c array).
Run
ESDID e1, e2;
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];
operator uint32_t () const { return ((c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]); };
};
syminfo s1;
map <uint32_t, syminfo> m;
m.insert( pair<uint32_t, syminfo>(s1.symesdid, s1) );
Note the key of the map uses the content of the c array.
"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 ()
|
|
|
|
|
The cast is used here:
pair<uint32_t, syminfo>(s1.symesdid, s1)
The compiler: "Map's key must be a uint32_t , hence s1.symesdid , being an ESDID , does NOT fit.
Let's see if there is a suitable cast..."
"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<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>
> class map; As it should be, because the std::map is a sorted container.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
|
cppreference.com:
template<
class Key,
class T,
class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>
> class map;
Microsoft:
template <class Key,
class Type,
class Traits = less<Key>,
class Allocator=allocator<pair <const Key, Type>>>
class map;
Do you see significant differences?
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
I see the third parameter to the template in microsoft docs is class traits in the cpp reference its class compare thank you
|
|
|
|
|
That's, you know, just a matter of naming...
BTW, you are welcome.
"In testa che avete, Signor di Ceprano?"
-- Rigoletto
|
|
|
|
|
this is just a general comment I thought MainFrame Assembler was Hard but being a C\C++ proficient coder is a very difficult skill to master as an aside just looked at the retrieval for the map class "AT" method it looks like if not found it generates an exception would of been a lot simpler if they gave back a bad return code
Thank
|
|
|
|
|
It is just as easy to catch the exception. Exceptions are another useful feature of OOP languages, and provide more flexibility than simple return codes.
|
|
|
|
|