473,729 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Mapping of constants to data members of a class?

Hi y'all,

I have an existing GUI application where various windows has columns
which are mapped to data members of various classes. Now, I have to
implement a new functionality to all the classes and I was wondering
if I can somehow map the data member fields to the column ids.

Following code illustrates the question.

// Existing code

// Constants for window columns
const int COL_A 1;
const int COL_B 2;
const int COL_C 3;
....
<const for other columns>

// classes whose member fields holds the data of the columns
class foo
{
public:
string a;
string b;
int c;
...
<other data member corresponding to columns>
};
now at run_time I need to do something like the following:

// New functionality

void bar(int col_id, int val)
{
int field_val = mapping_to_get_ value_based_on_ col_id();
if (field_val == val)
new_functionali ty();
}

I am having a hard time to find a generic wasy to do the mapping. I
know, I can have a switch statement for all the classes where based on
col number I get the field value but it will be nice to have a simple,
generic way.

Thanks for your replies.
Vikas
Jul 22 '05 #1
1 1212
vs*****@gmail.c om (Vikas) wrote in message news:<7a******* *************** ****@posting.go ogle.com>...
Hi y'all,

I have an existing GUI application where various windows has columns
which are mapped to data members of various classes. Now, I have to
implement a new functionality to all the classes and I was wondering
if I can somehow map the data member fields to the column ids.
What is the use behind the column ideas?
Something like "virtual QString text ( int column ) const", see
http://doc.trolltech.com/3.3/qlistviewitem.html.

Following code illustrates the question.

// Existing code

// Constants for window columns
const int COL_A 1;
const int COL_B 2;
const int COL_C 3;
...
<const for other columns>

// classes whose member fields holds the data of the columns
class foo
{
public:
string a;
string b;
int c;
...
<other data member corresponding to columns>
};
now at run_time I need to do something like the following:

// New functionality

void bar(int col_id, int val)
{
int field_val = mapping_to_get_ value_based_on_ col_id();
if (field_val == val)
new_functionali ty();
}
How to you make use of the argument `col_id'?
What about:

class Base {
public:
// returns true if `col' can be mapped to an integer value,
// `val' is then set to this value, else left unchanged.
virtual bool intval(int col, int& val) const = 0;
};

void bar(const Base& base, int col, int val)
{
int retval;
if (base.intval(co l, retval)) {
if (retval == val) new_functionali ty();
}
}

In this design bar(...) dominates the concrete classes derived from Base.
Eventually you want to give the leaf classes more flexibility, this
however depends on when bar(...) is called.
I am having a hard time to find a generic wasy to do the mapping. I
know, I can have a switch statement for all the classes where based on
col number I get the field value but it will be nice to have a simple,
generic way.

Thanks for your replies.
Vikas


Stephan Brönnimann
br****@osb-systems.com
Open source rating and billing engine for communication networks.
Jul 22 '05 #2

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

Similar topics

0
3574
by: William Ryan | last post by:
WebConfig is made for storing such constants but there are other methods as well. You can create a Module in VB.NET or a class with Static Members in C# and query your DB at the onset and populate these fields there. In one case you change Web.Config when you want to make changes, in the other you change you DB fields. Since ADO.NET is probably how you'll access the data, they are both essentially as dynamic as the other one. ...
29
4635
by: Joe | last post by:
This is a very basic question, but why can't I do the following ? class schedule { private: static const string mScheduleFile = "schedule.txt"; .... }
5
2635
by: Generic Usenet Account | last post by:
I am trying to compile the following sample code: class WhatISHappeningHere { static const int x = 32; static const char* yy = "Howdy"; // ... // blah blah blah // ... };
2
1522
by: mars | last post by:
Alexandrescu(2000) advance a method about mapping intergral constants to types like this: template<int v> struct Int2Type { enum { value = v }; }; Why cann't use like this: template<int v> struct Int2Type {
8
2175
by: Mark Rae | last post by:
Hi, Another stupid newbie question from me, I'm sorry to say... but can anyone tell me how to simulate the concept of a global constant in a C# Windows app? The app in question contains several forms, each of which need to interrogate the value of a "global" constant. Do I have to create a class with a public constant declaration and instantiate that class from each form?
4
51178
by: Amadelle | last post by:
Hi all and thanks again in advance, What is the best way of defining global constants in a C# application? (A windows application with no windows forms - basically a set of classes). Would it be a wise idea to create a clsCommonApp and let all other classes to be derived from that class? and define all constants in that base class? Any other suggestions are more than welcome. (BTW this is not for one constant, I have multiple...
8
2887
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger class that I want its instance to be accessible from any other classe in the project. There is also a bunch of constants that I want to be public for the
10
1549
by: Paul | last post by:
Hi all, All of the classes in my DAL are static, with constants defining the stored procedures and parameters. I've been having some problems with my site which makes me wonder if there's a thread safety issue. Are consts thread safe? Would the following example create any thread safety issues? Would you recommend using static readonly members instead of constants?
3
5856
by: Steve Folly | last post by:
Hi, I had a problem in my code recently which turned out to be the 'the "static initialization order fiasco"' problem (<http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12>) The FAQ section describes a solution using methods returning references to static objects. But consider:
0
9428
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9289
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9156
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8159
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4798
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3242
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 we have to send another system
2
2694
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.