Get/set value to members of a struct/class on fly

Discussion in 'C++' started by Matt, Jul 25, 2003.

  1. Matt

    Matt Guest

    Hi all,

    Suppose I have a bunch of similar structs/classes in a format like this:
    struct s1{
    int arg1;
    char arg2[SIZE];
    };

    struct s2{
    char arg1[SIZE];
    int arg2;
    float arg3;
    };
    ....
    struct sN{
    int flag;
    s1 arr1;
    };


    Then I need a general method(of course, we can do it one by one :) to pull
    out/assign values from/to these structs with something like this(we don't
    care mem alloc, and we also have a migic buf which can accept/supply
    necessary values on demand btw :):
    void set_values_for_any_struct (struct *assignto, point *migbuf, int
    arrdepth, .., any other stuff)
    {
    /*
    suppose we know in advance the assignto is sN *
    and we even know sN has two members, and what their types are, but since
    this method should fit all structs we can't use assignto->flag =
    migbuf.value to assign the value, is there a way to do so?
    */
    ???
    }
    // same thing for get

    (I'm doing this for a soap client(not server) app, not sure param's name in
    soap1.2 is significant means server decides the name and I may not be able
    to change them. but I don't have ideas even I can decide the struct and its
    members names for soap1.1)
    Anyway, help!

    -m
    Matt, Jul 25, 2003
    #1
    1. Advertising

  2. Matt wrote:
    > Hi all,


    Hi.

    > Suppose I have a bunch of similar structs/classes in a format like this:
    > struct s1{
    > int arg1;
    > char arg2[SIZE];
    > };
    >
    > struct s2{
    > char arg1[SIZE];
    > int arg2;
    > float arg3;
    > };
    > ...
    > struct sN{
    > int flag;
    > s1 arr1;
    > };
    >


    > Then I need a general method(of course, we can do it one by one :) to pull
    > out/assign values from/to these structs with something like this(we don't
    > care mem alloc, and we also have a migic buf which can accept/supply
    > necessary values on demand btw :):


    What does "we don't care mem alloc" mean?
    What does "migic" mean?

    > void set_values_for_any_struct (struct *assignto, point *migbuf, int
    > arrdepth, .., any other stuff)
    > {
    > /*
    > suppose we know in advance the assignto is sN *
    > and we even know sN has two members, and what their types are, but since
    > this method should fit all structs we can't use assignto->flag =
    > migbuf.value to assign the value, is there a way to do so?
    > */
    > ???
    > }
    > // same thing for get


    ???

    >
    > (I'm doing this for a soap client(not server) app, not sure param's name in
    > soap1.2 is significant means server decides the name and I may not be able
    > to change them. but I don't have ideas even I can decide the struct and its
    > members names for soap1.1)
    > Anyway, help!


    Use full stops (periods) and capital letters. Try to make sure each
    sentence has (at least) a subject and a verb. After you write something,
    read through it and ask yourself, "Does this make sense?". Ask an adult
    to help you if you get stuck.

    > -m


    Perhaps you're thinking of a discriminated union, like boost::any.
    A good database system will have a sensible way to do this.

    Good luck,
    Buster
    Buster Copley, Jul 25, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    0
    Views:
    342
  2. Matt
    Replies:
    0
    Views:
    383
  3. Matt
    Replies:
    0
    Views:
    313
  4. CoolPint
    Replies:
    8
    Views:
    976
    Jeff Schwab
    Dec 14, 2003
  5. John Reye
    Replies:
    28
    Views:
    1,368
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page