Codesynthesis - Compare string value with sequence in C++











up vote
0
down vote

favorite












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;
}

}









share|improve this question




























    up vote
    0
    down vote

    favorite












    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;
    }

    }









    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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;
      }

      }









      share|improve this question















      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;
      }

      }






      c++ compare sequence codesynthesis






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 16:09

























      asked Nov 22 at 15:36









      T.Low

      13




      13
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          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.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434249%2fcodesynthesis-compare-string-value-with-sequence-in-c%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            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.






            share|improve this answer

























              up vote
              0
              down vote



              accepted










              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.






              share|improve this answer























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                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.






                share|improve this answer












                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 4 at 13:35









                T.Low

                13




                13






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53434249%2fcodesynthesis-compare-string-value-with-sequence-in-c%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks