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

M

Matt

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
 
B

Buster Copley

Matt said:
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.

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top