Thread: enum question

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    519

    enum question

    Hi,

    I have a namespace and an enum in it:

    Code:
    nmamespace dem
    {
    
    enum User_types
    {
            ....
    	EntityManagerStatus = 1000,
    	MissionDescription = 1010,
    	GeneralEntityData = 1020,
    	ImCmdQueue = 1030
            ....
    }
    
    }
    Basically that are ID's describing classes. I need that while serializing object data to push it over network to indicate the types.
    That classes are loaded from dll's.
    Now that I want to do is to expand that enum dynamically while loading an new dll.
    I guess that's not possible, isn't it?
    How would you work around that, so you still got such global identifiers which could expanded dynamically?

    Thanks for your ideas!
    Last edited by pheres; 08-21-2007 at 06:55 AM.

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    Unfortunately not, since enums are determined at compile time. I would store the values in a map instead. something like this perhaps -

    Code:
        std::map< std::string, int > User_types;
    
        User_types.insert( std::make_pair< std::string, int >( "EntityManagerStatus", 1000 ) );
        User_types.insert( std::make_pair< std::string, int >( "MissionDescription", 1010 ) );
        User_types.insert( std::make_pair< std::string, int >( "GeneralEntityData", 1020 ) );

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    519
    Sounds reasonable so far.
    assuming I need both a) int->string as well as b) string->int.
    For the above map a) O(n) and b) has O(log n).

    other options that come to my mind are 2 separate maps, so a) and b) have O(log n) but the expense to attend 2 containers and hold them in a consistence state.
    Or a vector<string> that would get me O(1) for a) and O(n) for b)

    Are there other options?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 04:22 AM
  2. Question on Enum
    By markcls in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 08:19 AM
  3. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  4. Enum question
    By Bill 101 in forum C Programming
    Replies: 4
    Last Post: 10-31-2002, 12:33 AM
  5. enum question
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 12-30-2001, 12:04 AM