Returning a non-pod object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jan-Henrik Grobe

    Returning a non-pod object

    Hallo,

    I am searching for helpü with non-pod objects. I have a class X which
    contains an object y of class Y as a member. This object is non-pod. Now I
    have an object x from class X and want to isolate the object y out of it. I
    tried it with adding a get-fucntion.

    Y X::getObjectY(v oid)
    {
    return y;
    }

    In my main program I create an Y object where I want to store the result of
    that function.

    Y myy;
    ....
    myy = x->getObjectY() ;

    Now gcc (I use Fedora Core 2.0) plays wild boar and comes with an error
    message like this: "object y is non-pod. assignment will be aborted during
    runtime". In result I dont have y copied in myy. But that is what I want
    because I want to send myy over a network.

    Does anyone had this problem before and know how to solve it.

    Many thanks
    Jan


  • Victor Bazarov

    #2
    Re: Returning a non-pod object

    Jan-Henrik Grobe wrote:[color=blue]
    > I am searching for helpü with non-pod objects. I have a class X which
    > contains an object y of class Y as a member. This object is non-pod. Now I
    > have an object x from class X and want to isolate the object y out of it. I
    > tried it with adding a get-fucntion.
    >
    > Y X::getObjectY(v oid)
    > {
    > return y;
    > }
    >
    > In my main program I create an Y object where I want to store the result of
    > that function.
    >
    > Y myy;
    > ...
    > myy = x->getObjectY() ;[/color]

    Have you tried doing initialisation instead of assignment? Like

    Y myy(x->getObjectY() );

    ?
    [color=blue]
    > Now gcc (I use Fedora Core 2.0) plays wild boar and comes with an error
    > message like this: "object y is non-pod. assignment will be aborted during
    > runtime". In result I dont have y copied in myy. But that is what I want
    > because I want to send myy over a network.
    >
    > Does anyone had this problem before and know how to solve it.[/color]

    You would have to post the definition of Y to begin with.

    V

    Comment

    • Jan-Henrik Grobe

      #3
      Re: Returning a non-pod object


      "Victor Bazarov" <v.Abazarov@com Acast.net> schrieb im Newsbeitrag
      news:exd3e.5898 0$NC6.56389@new sread1.mlpsca01 .us.to.verio.ne t...[color=blue]
      > Jan-Henrik Grobe wrote:[color=green]
      >> I am searching for helpü with non-pod objects. I have a class X which
      >> contains an object y of class Y as a member. This object is non-pod. Now
      >> I have an object x from class X and want to isolate the object y out of
      >> it. I tried it with adding a get-fucntion.
      >>
      >> Y X::getObjectY(v oid)
      >> {
      >> return y;
      >> }
      >>
      >> In my main program I create an Y object where I want to store the result
      >> of that function.
      >>
      >> Y myy;
      >> ...
      >> myy = x->getObjectY() ;[/color]
      >
      > Have you tried doing initialisation instead of assignment? Like
      >
      > Y myy(x->getObjectY() );
      >
      > ?[/color]


      Hallo,

      may thanks....the only problem is, that the assignment has to be done
      continously in a callback function.

      Jan


      Comment

      • Victor Bazarov

        #4
        Re: Returning a non-pod object

        Jan-Henrik Grobe wrote:[color=blue]
        > [..] the only problem is, that the assignment has to be done
        > continously in a callback function.[/color]

        Well, fine. What about my suggestion on posting the definition of 'Y'?

        V

        Comment

        • Jan-Henrik Grobe

          #5
          Re: Returning a non-pod object


          "Victor Bazarov" <v.Abazarov@com Acast.net> schrieb im Newsbeitrag
          news:kre3e.5898 3$NC6.50949@new sread1.mlpsca01 .us.to.verio.ne t...[color=blue]
          > Jan-Henrik Grobe wrote:[color=green]
          >> [..] the only problem is, that the assignment has to be done continously
          >> in a callback function.[/color]
          >
          > Well, fine. What about my suggestion on posting the definition of 'Y'?
          >
          > V[/color]


          Hallo,

          Y looks like this

          class Y

          {

          public:

          void clear();

          bool MouseEvent () const { return v_event==1; }

          bool MouseMove () const { return (v_event==1 && v_v0.i0()==0); }

          bool MousePush () const { return (v_event==1 && v_v0.i0()==1); }

          bool MouseDrag () const { return (v_event==1 && v_v0.i0()==2); }

          bool MouseRelease () const { return (v_event==1 && v_v0.i0()==3); }

          bool MouseDblClick() const { return (v_event==1 && v_v0.i0()==4); }

          bool MouseLButton () const { return (v_event==1 && v_v1.i0()==1); }

          bool MouseRButton () const { return (v_event==1 && v_v1.i0()==2); }

          bool MouseMButton () const { return (v_event==1 && v_v1.i0()==3); }

          bool KeyEvent () const { return v_event==2; }

          bool KeyShift () const { return ((v_v2.i1()&1)= =1); }

          bool KeyCtrl () const { return ((v_v2.i1()&2)= =2); }

          bool KeyAlt () const { return ((v_v2.i1()&4)= =4); }

          bool Spacemouse () const { return v_event==3; }

          bool SelectHit () const { return v_selectHit; }

          // *** Event custom data

          int v_event;

          Token v_v0, v_v1, v_v2, v_v3;

          // *** possibly additionally a select

          bool v_selectHit;

          Token v_pNear; // Mouse on near plane

          Token v_pFar; // Mouse on far plane

          Token v_hitpoint; // hit point,

          Token v_screenXY; // Mouse event, pixel coords

          Token v_hittoken; // registered object

          Token v_ticket; // HandleIO ticket for the hit

          };



          it contains geometrical events....the object has to be send through a
          network, because these events (the resulting rendering) have to be performed
          on the client computers

          Hope that helps

          Jan


          Comment

          • Victor Bazarov

            #6
            Re: Returning a non-pod object

            Jan-Henrik Grobe wrote:[color=blue]
            > "Victor Bazarov" <v.Abazarov@com Acast.net> schrieb im Newsbeitrag
            > news:kre3e.5898 3$NC6.50949@new sread1.mlpsca01 .us.to.verio.ne t...
            >[color=green]
            >>Jan-Henrik Grobe wrote:
            >>[color=darkred]
            >>>[..] the only problem is, that the assignment has to be done continously
            >>>in a callback function.[/color]
            >>
            >>Well, fine. What about my suggestion on posting the definition of 'Y'?
            >>
            >>V[/color]
            >
            >
            >
            > Hallo,
            >
            > Y looks like this
            >
            > class Y
            >
            > {
            >
            > public:
            >
            > [.. member functions ..]
            > // *** Event custom data
            >
            > int v_event;[/color]

            OK, no problem assigning 'int'.
            [color=blue]
            >
            > Token v_v0, v_v1, v_v2, v_v3;[/color]

            What's "Token"? Is 'Token' assignable?
            [color=blue]
            >
            > // *** possibly additionally a select
            >
            > bool v_selectHit;[/color]

            No problem here either.
            [color=blue]
            >
            > Token v_pNear; // Mouse on near plane
            > [.. more Token objects ..][/color]

            Again, is 'Token' assignable?
            [color=blue]
            >
            > };
            >
            >
            >
            > it contains geometrical events....the object has to be send through a
            > network, because these events (the resulting rendering) have to be performed
            > on the client computers[/color]

            That's irrelevant AFA C++ is concerned.

            You see, if the compiler complains about being unable to perform the
            operation "assignment ", you need to start looking at the involved types
            trying to understand how assignment is going to be attempted and why it
            might fail. Could it be that the operator= is a virtual function and is
            declared pure? Although that would make objects non-instantiable...

            Anyway, impossible to conclude at this point (yet). Extract your classes
            into a separate project, reduce to the bare minimum that still exhibits
            the problem, perhaps in the process you'll find the cause, if not, post
            the bare minimum code here, we'll take a look at it again.

            V

            Comment

            • Jan-Henrik Grobe

              #7
              Re: Returning a non-pod object


              "Victor Bazarov" <v.Abazarov@com Acast.net> schrieb im Newsbeitrag
              news:LWe3e.5898 9$NC6.30696@new sread1.mlpsca01 .us.to.verio.ne t...[color=blue]
              > Jan-Henrik Grobe wrote:[color=green]
              >> "Victor Bazarov" <v.Abazarov@com Acast.net> schrieb im Newsbeitrag
              >> news:kre3e.5898 3$NC6.50949@new sread1.mlpsca01 .us.to.verio.ne t...
              >>[color=darkred]
              >>>Jan-Henrik Grobe wrote:
              >>>
              >>>>[..] the only problem is, that the assignment has to be done continously
              >>>>in a callback function.
              >>>
              >>>Well, fine. What about my suggestion on posting the definition of 'Y'?
              >>>
              >>>V[/color]
              >>
              >>
              >>
              >> Hallo,
              >>
              >> Y looks like this
              >>
              >> class Y
              >>
              >> {
              >>
              >> public:
              >>
              >> [.. member functions ..]
              >> // *** Event custom data
              >>
              >> int v_event;[/color]
              >
              > OK, no problem assigning 'int'.
              >[color=green]
              >>
              >> Token v_v0, v_v1, v_v2, v_v3;[/color]
              >
              > What's "Token"? Is 'Token' assignable?
              >[color=green]
              >>
              >> // *** possibly additionally a select
              >>
              >> bool v_selectHit;[/color]
              >
              > No problem here either.
              >[color=green]
              >>
              >> Token v_pNear; // Mouse on near plane
              >> [.. more Token objects ..][/color]
              >
              > Again, is 'Token' assignable?
              >[color=green]
              >>
              >> };
              >>
              >>
              >>
              >> it contains geometrical events....the object has to be send through a
              >> network, because these events (the resulting rendering) have to be
              >> performed on the client computers[/color]
              >
              > That's irrelevant AFA C++ is concerned.
              >
              > You see, if the compiler complains about being unable to perform the
              > operation "assignment ", you need to start looking at the involved types
              > trying to understand how assignment is going to be attempted and why it
              > might fail. Could it be that the operator= is a virtual function and is
              > declared pure? Although that would make objects non-instantiable...
              >
              > Anyway, impossible to conclude at this point (yet). Extract your classes
              > into a separate project, reduce to the bare minimum that still exhibits
              > the problem, perhaps in the process you'll find the cause, if not, post
              > the bare minimum code here, we'll take a look at it again.
              >
              > V[/color]


              Hey,

              Token is another with assignable and unassignable objects. I must say, that
              I havent written the Token-class and the Y-class by myself and they cannot
              be changed. My job is only to "copy out" the Y-object out of the X-object
              and send it over the net to "paste it in" the X-object that is running on
              the client PC. I dont know...maybe it is possible to get the pointer from
              the y-object and create a new y-object in the main application and assign
              the value behind the pointer to that new object

              Greetings
              Jan


              Comment

              • Howard

                #8
                Re: Returning a non-pod object


                "Victor Bazarov" <v.Abazarov@com Acast.net> wrote in message
                news:LWe3e.5898 9$NC6.30696@new sread1.mlpsca01 .us.to.verio.ne t...[color=blue][color=green]
                >>
                >> it contains geometrical events....the object has to be send through a
                >> network, because these events (the resulting rendering) have to be
                >> performed on the client computers[/color]
                >
                > That's irrelevant AFA C++ is concerned.
                >[/color]

                I'm wondering if that actually *is* relevant in this case. He's mentioned
                several things that suggest he's dealing with an issue that isn't standard
                C++. For one, the error message says that the assignment will be aborted
                "at run time". That's not any normal C++ error I've ever heard of. And he
                says he can't do initialization, because he's required to "continuous ly
                assign" it in a callback function.

                I'm suspecting that he's using a compiler that is somehow aware of the
                networked nature of this software, and is telling him that non-POD objects
                cannot be copied, **at run time**, in this manner. That's probably because
                there's no way to allocate the shared memory (or whatever) that is used to
                get the data from the server object to the client object.

                If that's the case, then what he needs is to either make proper use of the
                network facilities for a non-POD object (a subject only addressable by the
                reading the docs for that software or that networking system, or by asking
                on a more appropriate newsgroup), or else the object needs to return some
                kind of POD representation of the actual data (such as by streaming it into
                an array of char), which *can* be passed using this system.

                I'm only guessing here, but that sounds like what he's trying to do, to me
                anyway. (And I think it's off-topic here, and should be taken to a
                newsgroup that knows what he's talking about.)

                -Howard




                Comment

                • Victor Bazarov

                  #9
                  Re: Returning a non-pod object

                  Jan-Henrik Grobe wrote:[color=blue]
                  > [..]
                  > Token is another with assignable and unassignable objects.[/color]

                  If that's so, then Token may not be assignable, and that's your problem.
                  [color=blue]
                  > I must say, that
                  > I havent written the Token-class and the Y-class by myself and they cannot
                  > be changed.[/color]

                  That's too bad.
                  [color=blue]
                  > My job is only to "copy out" the Y-object out of the X-object
                  > and send it over the net to "paste it in" the X-object that is running on
                  > the client PC.[/color]

                  I am not blaming you or trying to make you do what you don't want to.
                  [color=blue]
                  > I dont know...maybe it is possible to get the pointer from
                  > the y-object and create a new y-object in the main application and assign
                  > the value behind the pointer to that new object[/color]

                  It seems that what you're solving here is a *serialization* problem. You
                  need to send information over the wires, which should represent the 'Y'
                  object in such way that it can be recreated. Without knowing the problem
                  domain in detail (not that I'm asking you to fill me in) it is difficult
                  to give you more specific advice than the following. Try to imagine what
                  information you need to be able to recreate a 'Y' on the other end of your
                  transmission and stick it into your other 'X'. Perhaps you need to make
                  up another type, like 'Y_proto', which will be created by your 'X', then
                  transmitted somehow and then used by the other 'X' to generate the proper
                  'Y' object inside it. You do have control over 'X', don't you?

                  In some cases you can get away with some binary content, especially if you
                  do not cross platform borders, in other instances you need to convert your
                  internal representations into some kind of text stream, formed on one end
                  and interpreted at the other end. I don't know which you'll pick, nor do
                  I claim the ability to recommend one here and now, since I don't know the
                  details. Do find a book or look on the Web for "serializat ion" of C++
                  objects. They can probably explain it better than I can.

                  V

                  Comment

                  • Jan-Henrik Grobe

                    #10
                    Re: Returning a non-pod object


                    "Victor Bazarov" <v.Abazarov@com Acast.net> schrieb im Newsbeitrag
                    news:Iuf3e.5903 6$NC6.25509@new sread1.mlpsca01 .us.to.verio.ne t...[color=blue]
                    > Jan-Henrik Grobe wrote:[color=green]
                    >> [..]
                    >> Token is another with assignable and unassignable objects.[/color]
                    >
                    > If that's so, then Token may not be assignable, and that's your problem.
                    >[color=green]
                    > > I must say, that
                    >> I havent written the Token-class and the Y-class by myself and they
                    >> cannot be changed.[/color]
                    >
                    > That's too bad.
                    >[color=green]
                    > > My job is only to "copy out" the Y-object out of the X-object
                    >> and send it over the net to "paste it in" the X-object that is running on
                    >> the client PC.[/color]
                    >
                    > I am not blaming you or trying to make you do what you don't want to.
                    >[color=green]
                    > > I dont know...maybe it is possible to get the pointer from
                    >> the y-object and create a new y-object in the main application and assign
                    >> the value behind the pointer to that new object[/color]
                    >
                    >
                    > In some cases you can get away with some binary content, especially if you
                    > do not cross platform borders, in other instances you need to convert your
                    > internal representations into some kind of text stream, formed on one end
                    > and interpreted at the other end. I don't know which you'll pick, nor do
                    > I claim the ability to recommend one here and now, since I don't know the
                    > details. Do find a book or look on the Web for "serializat ion" of C++
                    > objects. They can probably explain it better than I can.
                    >
                    > V[/color]

                    Now I realize somehow in what trash I am :-) Yesterday evening I thought
                    that programming this all would take me about 15 minutes and everything will
                    run fine.

                    I am working on a kind of interaction manager for a CAVE virtual
                    environment.... interaction is performed on the server PC which is pushing
                    the information through a network to the clients that render my Cavewalls. I
                    have a class X object running on all computers...the Y class objects
                    contains the information, how the geometry is "modified" (complexer
                    geometric function). On the server (where the interaction is performed), the
                    y-object will be continuiously modifizied depending on the actions the user
                    does...but to render all this, I have to send it to the clients.

                    So much to my work

                    I have never really coped a lot with networks and object referencing,
                    copying, etc....but somehow it cannot be so hard to instance a new object
                    with the data from an existing object, irrelevant if it is pod or not.
                    [color=blue]
                    > It seems that what you're solving here is a *serialization* problem. You
                    > need to send information over the wires, which should represent the 'Y'
                    > object in such way that it can be recreated. Without knowing the problem
                    > domain in detail (not that I'm asking you to fill me in) it is difficult
                    > to give you more specific advice than the following. Try to imagine what
                    > information you need to be able to recreate a 'Y' on the other end of your
                    > transmission and stick it into your other 'X'. Perhaps you need to make
                    > up another type, like 'Y_proto', which will be created by your 'X', then
                    > transmitted somehow and then used by the other 'X' to generate the proper
                    > 'Y' object inside it. You do have control over 'X', don't you?[/color]

                    yes, I can add functions to X if I want....I already added the getObjectY
                    function. But changes in the geometric parts I cannot do.

                    Probably I should leave it away for the weekend :-)

                    Greetings
                    Jan


                    Comment

                    Working...