473,473 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Generic x-dimensional name values

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?




Jul 24 '08 #1
3 1095
Christopher schrieb:
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
[...]
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..
Do you want a multidimensional data structure, or a hierarchical /
recursive data structure?

For the latter, you could make a std::map, where the value type is a
boost::variant (google for it), which can be recursive.

--
Thomas
Jul 24 '08 #2
Christopher wrote:
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)
[..]
Like std::map<std::string, boost::any?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 24 '08 #3
On Jul 24, 1:43 pm, Victor Bazarov <v.Abaza...@comAcast.netwrote:
Christopher wrote:
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)
[..]

Like std::map<std::string, boost::any?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Almost, except
"Discriminated types that contain values of different types but do not
attempt conversion between them"

I want to be able to convert from any built in type to any other built
in type during sets and gets.
I have that part down though. Storing as strings and using lexical
casting seems to work pretty well.
Its the grouping part I can't wrap my head around.

I need name value pairs
I need named groups of name value pairs
I need named groups, of named groups, of name value pairs
and on and on.

Jul 24 '08 #4

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

Similar topics

17
by: Andreas Huber | last post by:
What follows is a discussion of my experience with .NET generics & the ..NET framework (as implemented in the Visual Studio 2005 Beta 1), which leads to questions as to why certain things are the...
1
by: Arthur Dent | last post by:
Hi all... Heres what im looking to do.... I have a Generic class i wrote. Now, on another class, i want to add a method which can take in an object of my generic class... but the catch is, i want...
3
by: Tigger | last post by:
I have an object which could be compared to a DataTable/List which I am trying to genericify. I've spent about a day so far in refactoring and in the process gone through some hoops and hit some...
4
by: Andrew Ducker | last post by:
I have a collection of classes descending from a single root class (let's call it RootClass). They all currently have a property of Logical, of type Logical. However they actually return a...
9
by: mps | last post by:
I want to define a class that has a generic parameter that is itself a generic class. For example, if I have a generic IQueue<Tinterface, and class A wants to make use of a generic class that...
3
by: Seth Gecko | last post by:
Hi I am working with generic lists of various objects and a control dealing with these lists. For instance: A parent form holds: dim Walls as List(Of wall) dim Segments as List(Of segment) ...
13
by: rkausch | last post by:
Hello everyone, I'm writing because I'm frustrated with the implementation of C#'s generics, and need a workaround. I come from a Java background, and am currently writing a portion of an...
3
by: Boris | last post by:
I have a class which should like this ideally: generic <typename T> public ref class ManagedClass { T ^managedMember; UnmanagedClass<U*unmanagedMember; }; I actually would like to specify...
7
by: Dave | last post by:
I've got these declarations: public delegate void FormDisplayResultsDelegate<Type>(Type displayResultsValue); public FormDisplayResultsDelegate<stringdisplayMsgDelegate; instantiation:...
15
by: Lloyd Dupont | last post by:
Don't mistake generic type for what you would like them to be!! IFoo<Ahas nothing in common with IFoo<B>! They are completely different type create dynamically at runtime. What you ask is a...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.