I'm new to Codesynthesis and i'm wondering about how i can compare string values with a sequence.
For example i have a Message id "0x100" and i want to check if its in the Send sequences. If its there, i just want to get the Signal name of the Message with the id "0x100" (in this case: "one") and not the whole sequence.
With my code i can get all the Message ids in all Send sequences, but i dont know how to use them to compare it to a string variable respectively just get one element out of the sequence and save it to a string variable.
How can i accomplish this?
Thanks for your help!
This is the xml:
<record>
<signals>
<Send name="Port1">
<Message id="0x100">
<Signal name="one"/>
</Message>
<Message id="0x101">
<Signal name="two"/>
<Signal name="three"/>
<Signal name="four"/>
</Message>
<Message id="0x102">
<Signal name="five"/>
</Message>
<Message id="0x103">
<Signal name="six"/>
</Message>
<Message id="0x104">
<Signal name="seven"/>
<Signal name="eight"/>
<Signal name="nine"/>
<Signal name="ten"/>
</Message>
<Message id="0x105">
<Signal name="eleven"/>
</Message>
</Send>
<Send name="Port2">
<Message id="0x106">
<Signal name="twelve"/>
</Message>
<Message id="0x107">
<Signal name="thirteen"/>
</Message>
<Message id="0x108">
<Signal name="fourteen"/>
</Message>
<Message id="0x109">
<Signal name="fifteen"/>
</Message>
<Message id="0x110">
<Signal name="sixteen"/>
</Message>
</Send>
</signals>
</record>
This is how i read the sequences from the xml:
string filename = "test.xml";
unique_ptr<record> h(record(filename));
signals::Send_sequence& s(h->signals().Send());
for (signals::Send_iterator i(s.begin()); i != s.end(); ++i)
{
Send::Message_sequence& s2(i->Message());
for (Send::Message_iterator j(s2.begin()); j != s2.end(); ++j)
{
Message& u(*j);
cout << u.id() << endl;
}
}
FYI: I found the solution. It was quite easy.
string filename = "test.xml";
unique_ptr<record> h(record(filename));
signals::Send_sequence& s(h->signals().Send());
for (signals::Send_iterator i(s.begin()); i != s.end(); ++i)
{
Send::Message_sequence& s2(i->Message());
for (Send::Message_iterator j(s2.begin()); j != s2.end(); ++j)
{
Message& u(*j);
cout << u.id() << endl;
//Check if theres a message
if (u.id().present()) {
//Put the message in a struct array (same with signals)
info[NumberOfSends].messages[NumberOfMessages] = u.id().get(); //this is how you get it as a string
NumberOfMessages++;
}
}
}NumberOfSends++;
Now you can use this array to compare it to a string.