C
Christopher
Let's see if I can explain my goal....
I need to devise a data structure that can contain a name and a data
object of any type (at least built in types)
For example:
name - "Car1" value - "WGNZYH"
name - "Latitude" value - 80.1
I created an class that represents both members as a std::string and
use boost's lexiconal cast along with template params for this class
and it works great for 1 dimension. My co-worker seems to think using
strings is inefficient memory wise, but I don't see an alternative, at
least not without tracking types and using unions, which I do not want
to do. We'll worry about efficiency later...
My problem is on how to represent multidimensional constructs of this
object where the dimension could be any number. At first, we assumed
we would only have 3 at most, but it doesn't seem very robust to me.
I went and made another class that wraps a map of the first. We'll
call that MyObject2D.
I went and made another class that wraps a map of the second. We'll
call that MyObject3D.
You see the problem..
For explanation, here is some sample data:
"car", "WGNYTH"
"wheel", "0901929AB"
"size", 18
"tread", 2
"psi", 35.001
"color", "black"
etc.
I want the user to be able to look up and retrieve values, groups of
values, or groups of groups, etc, by name.
The user should already know what types to expect.
usage like:
MyObject2D wheel = MyObject3D.Get2D("wheel");
int size;
wheel.GetMyObject1D(size);
I don't like having a seperate class for every dimension though. Any
Ideas on how to do something like this another way?
I need to devise a data structure that can contain a name and a data
object of any type (at least built in types)
For example:
name - "Car1" value - "WGNZYH"
name - "Latitude" value - 80.1
I created an class that represents both members as a std::string and
use boost's lexiconal cast along with template params for this class
and it works great for 1 dimension. My co-worker seems to think using
strings is inefficient memory wise, but I don't see an alternative, at
least not without tracking types and using unions, which I do not want
to do. We'll worry about efficiency later...
My problem is on how to represent multidimensional constructs of this
object where the dimension could be any number. At first, we assumed
we would only have 3 at most, but it doesn't seem very robust to me.
I went and made another class that wraps a map of the first. We'll
call that MyObject2D.
I went and made another class that wraps a map of the second. We'll
call that MyObject3D.
You see the problem..
For explanation, here is some sample data:
"car", "WGNYTH"
"wheel", "0901929AB"
"size", 18
"tread", 2
"psi", 35.001
"color", "black"
etc.
I want the user to be able to look up and retrieve values, groups of
values, or groups of groups, etc, by name.
The user should already know what types to expect.
usage like:
MyObject2D wheel = MyObject3D.Get2D("wheel");
int size;
wheel.GetMyObject1D(size);
I don't like having a seperate class for every dimension though. Any
Ideas on how to do something like this another way?