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 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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;
|
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.
...
|
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...
|
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 ()...
|
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,
|
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;...
|
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 ;
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |