Hi,
I have been maintaining a structure (c-struct) in my application which constitutes of
{
DDS::Entity
ReaderCallback
ReaderStatusCallback
...
}
DDS:Entity, as you know can be either a DataWriter or DataReader etc.. I maintain a list of these structures within my base application - probably for some legacy purposes which I dont want to dig in now. During filling the list, I plan to check for an existing DataWriter using the following logic:
{
EntityList::iterator it = m_entityList.begin();
EntityList::iterator end = m_entityList.end();
for ( ; it != end ; it++)
{
if ((*it)->entity == entity)
return (*it);
}
return NULL;
}
Though it seems to work (I mean if I try to give same DataWriter, then it considers a duplicate), but I would like to know a bit more on this. How does a "compare" work in such scenarios? In other words, what gets compared during this '==' operator? I tried searching around, but didn't get any clue.
Thanks in advance.
Uday
Hi Uday,
Firstly, the condition == is just comparing pointers of DDS_Entity.
The proper way about how to compare two DDS_Entity objects is using DDS_BuiltinTopicKey_t:
"Each remote DDS_Entity to be discovered can be uniquely identified by DDS_BuiltinTopicKey_t"
As DDS_InstanceHandle_t is derived from DDS_BuiltinTopicKey_t, the API provides methods to compare DDS_Entity objects by DDS_InstanceHandle_t, steps:
1. Get DDS_InstanceHandle_t:
This operation returns the DDS_InstanceHandle_t that represents the DDS_Entity.
2. Compare two DDS_InstanceHandle_t objects:
If this operation returns DDS_BOOLEAN_TRUE if the two DDS_Entities have equal values, or DDS_BOOLEAN_FALSE otherwise.
Let me know if you have further questions about DDS_Entity comparisons.
Best,
Antonio