473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
Jul 19 '05 #1
1 7113
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

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt | last post by:
Hi all, Suppose I have a bunch of similar structs/classes in a format like this: struct s1{ int arg1; char arg2; }; struct s2{ char arg1;
3
by: Gianni Mariani | last post by:
I was a little surprised by this: It seems like the code below should not compile but the Comeau 4.3.3 compiler accepts it and the gcc 3.4(prerel) compiler rejects it and MSVC++7.1 ICE's. ...
13
by: Dan Bass | last post by:
Say I've got an ArrayList, which contains a list of integers. Is it possible to get a reference to one of the integers contained within the collection so that changes to it are reflected in the...
3
by: The Petar | last post by:
I am really unhappy that C# accessors are not powerful enough to mimic as if you were accessing an class field. In particular, let S be: public struct S { public int v; public void change ()...
10
by: utab | last post by:
Dear all, Can somebody direct me to some resources on the subject or explain the details in brief? I checked the FAQ but could not find or maybe missed. Regards,
14
by: Glen Dayton | last post by:
While looking at some old code I ran across a snippet that increments a pointer to access different members of a structure: .... struct Badness { std::string m_begin; std::string m_param1;...
4
by: Santosh Nayak | last post by:
Hi, Is it possible to sort the array of struct based on the data members. e.g. struct { int a ; float b ; char c ; } TEMP ;
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.