473,386 Members | 1,741 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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_functionality();
}

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 1194
vs*****@gmail.com (Vikas) wrote in message news:<7a**************************@posting.google. 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_functionality();
}
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(col, retval)) {
if (retval == val) new_functionality();
}
}

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
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...
29
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
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
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>...
8
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...
4
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...
8
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...
10
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...
3
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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,...
0
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...

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.