Thread: data set

  1. #1
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248

    data set

    Hi everybody,

    I want to improve my existing library of a Data Set in which I can store variables of any kind, accessible by hash function via a key (string). Goal is to access variables across translation different translation units without passing them as input (to allow compilation independency). Only the singleton object of this DataSet will be passed as argument.

    The variables stored in the hash table are of type "My_Variable", which is a class containing the various types I possibly want to store. It also has a variable "Type" to set the type, in order to select between the right overloaded Set and Get functions.

    To store classes, I derive all classes from my GenericContainer type, and store pointers to this class in the Data Set. By polymorphism I can then access the data members / functions of the derived classes. I know these should have been smart pointers, this is for future development.

    BUT: Somewhere there is this small voice telling me that a library like Boost should have this implemented.

    I was looking for boost::unordered_map , but this map (as well as the std::map / std::set) can only store one type of variables in a hash table. I want to store no matter what variable.

    Does there exist a nice solution for this in Boost / Loki / STL / ... ?

    Thanks in advance for your answer!!!

    Mark

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    I think boost has variant and any, and the unordered collections should be standard in C++0x.

    Goal is to access variables across translation different translation units without passing them as input (to allow compilation independency). Only the singleton object of this DataSet will be passed as argument.
    This I don't quite understand. How does that reduce dependencies?

    It seems that having functions take arguments most of the time don't create new dependencies (the implementation file has the same dependencies anyway):

    Code:
    #ifndef FOOBAR_H
    #define FOOBAR_H
    
    class X;
    class Y;
    
    void Foo(X* x);
    void Bar(const Y& y);
    #endif
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    May 2008
    Location
    Paris
    Posts
    248
    Hi, thanks for your answer.
    Goal is to access variables across translation different translation units without passing them as input (to allow compilation independency). Only the singleton object of this DataSet will be passed as argument.
    This I don't quite understand. How does that reduce dependencies?
    Well, I can now pass a pointer to the dynamically allocated object to functions in some utility plug-in. Every functions only takes this as argument.
    So it will always compile, only at runtime it will raise an exception that the variable does not exist (so instead of variables as arguments, they are stored in the data set and accessed in the function).

    Thanks, I will look into boost::any !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lame null append cause buffer to crash
    By cmoo in forum C Programming
    Replies: 8
    Last Post: 12-29-2008, 03:27 AM
  2. Generating the Mode of a Data Set
    By firetheGlazer in forum C Programming
    Replies: 3
    Last Post: 07-15-2008, 01:48 PM
  3. The new FAQ
    By Hammer in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 08-30-2006, 10:05 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM