Generic x-dimensional name values

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christopher

    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 multidimensiona l 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.Get2 D("wheel");

    int size;
    wheel.GetMyObje ct1D(size);

    I don't like having a seperate class for every dimension though. Any
    Ideas on how to do something like this another way?










  • Thomas J. Gritzan

    #2
    Re: Generic x-dimensional name values

    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 multidimensiona l 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 multidimensiona l 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

    Comment

    • Victor Bazarov

      #3
      Re: Generic x-dimensional name values

      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::s tring, 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

      Comment

      • Christopher

        #4
        Re: Generic x-dimensional name values

        On Jul 24, 1:43 pm, Victor Bazarov <v.Abaza...@com Acast.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::s tring, 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
        "Discrimina ted 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.

        Comment

        Working...