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

Home Posts Topics Members FAQ

class for "updatable enum"


Dear all,

I wonder whether anyone might have a better idea/solution to the
following. I need an associative container <int,string> for a limited
and defined number of values (enum-like) but ir must be able to be updated
with more pairs later. Here is the solution I have developed so long
All my enum-like int values are declared static const inside a namespace
as well as a struct with a static map<int,string> to keep the pairs.
The constructor is used to add new pairs later.

So here are the declarations enum.h

namespace myEnum
{
const static int boolean;
const static int character;
struct table
{
typedef map<int, const string> mymap;
typedef mymap::value_type mypair;
typedef mymap* iter;
table(const Iter & first, const Iter & last);
static ValuesDescList values;
};
}

And the definitions enum.cpp

#include <enum.h>

namespace myEnum {
const int boolean = 1;
const int character = 2;
namespace
{
table::mypair v_tableInit[] =
{
table::mypair(boolean , "bool"),
table::mypair(character, "char")
};
table::mypair *v_tableInitEnd(v_tableInit+
sizeof v_tableInit / sizeof v_tableInit[0]);
}
table::table(const Iter & first, const Iter & last)
{
values.insert(first, last);
}
// initialise static
table::mymap table::values(v_tableInit, v_tableInitEnd);
}

Now if I need to update the namespace with more pairs, here is what I
can do

#include <enum.h>

namespace myEnum
{
const static int boolVect = 100;
const static int realVect = 104;
namespace // seems to need namespace to avoid redef of v_tableInit and v_tableInitEnd
{
table::mypair v_tableInit[] =
table::mypair(boolVect, "bool[]"),
table::mypair(realVect, "real[]")
};
table::mypair *v_tableInitEnd(v_tableInit+
sizeof v_tableInit / sizeof v_tableInit[0]);
table registerMe(v_mapInit, v_mapInitEnd);
}

The trick is to use the constructor of table to insert new pairs in the
static table::values.
Then I can check

using namespace myEnym;
int main()
{
table::mymap::const_iterator i=table::value.begin()
do {
std::cout << i->first << " " << i->second << std::endl;
} while (i != valueMap::values.end());
}

Is this a reasonable solution? Anything that could improve it?

Sincerely,
Patrick

Jul 22 '05 #1
0 1955

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

Similar topics

3
by: Ajax Chelsea | last post by:
can not the "static const int" be replaced by "static enum" anywhere? is it necessary that define special initialization syntax for "static const int"?
6
by: Fao | last post by:
Hi, I am in my first year of C++ in college and my professor wants me to Write a Program with multiple functions,to input two sets of user-defined data types: One type named 'Sign' declared by...
7
by: Martin Lacoste | last post by:
I have a very basic query that Access 2000 will not allow to be updatable. I've gone through all the situations in the help file where data cannot be updated, and I don't see that this query...
0
by: zheng | last post by:
I create a OCX program with ATL project, and One parameter in the interface function is ENUM type, and I has defined the ENUM type in the interface, but compiled falid with MIDL2001, in the...
6
by: ZRexRider | last post by:
I've been reading the newsgroups and most of the solutions for this message are simple and obvious but unfortunately don't solve my problem. I have an MS-Access 2002 ADP application that...
9
by: Jacek Dziedzic | last post by:
Hi! I often find that my programs need to store information on "current mode of something" with two or at most several mutually exclusive "modes" to choose from, e.g. - datafile: is it in a)...
17
by: radio1 | last post by:
Configuration: Access 2002 and SQL Server 2000 using a .ADP Project. I would VERY MUCH appreciate anyone's input into this problem I'm having. I have a form in Access that does not permit...
2
by: JB | last post by:
Hi All, I'm pulling my hair over this and could really do with a bit of help. I'm using various different enums as bit fields and I'd like to create a set of generic Functions or Subs to...
4
by: msukumarbabu | last post by:
Hi all, What will be difference between "typedef enum" and "enum". or difference between “typedef structure" and "structure" I am going through some code. in that some place they are using...
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...
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.