473,395 Members | 1,870 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,395 software developers and data experts.

transformation -

Hi,

I'm trying to come up with a way to improve upon the following.

enum Label_Type
{
Label1,
Label2,
// ...
};

enum Key_Transform_Type
{
key1_key3,
key2_key4,
// ...
};

// key to scheme mapping
Key1 => { Label1, Label2, Label3, Label5, Label7 };
Key2 => { Label4, Label6, Label7 };

// map for converting from schemeA to schemeB
{ Key1, Key2, key1_key2 }
{ Key3, Key4, key3_key4 }

class test
{
// array of values referenced by labels
};

const test& test::operator = ( const test& src )
{
// ...

Key_Transform_Type TransformType = GetTransformType(
src.GetKeyType(), GetKeyType() );

switch ( TransformType )
{
case key1_key2:
Value(Label4) = src.Value(Label1) + src.Value(Label3);
Value(Label6) = src.Value(Label2) + src.Value(Label5);
Value(Label7) = src.Value(Label7);
break;

// handle other cases
}

return (*this);
}

The basic problem is to convert values in one scheme to another and it
has to be 'fast' as well. The code is littered with switch/case
statements and there're quite a few conversion scenarios.

Since the conversion is known at compile time, could templates be used
to express the relationship between the various schemes?

Any ideas?

Thanks
AK
Jul 19 '05 #1
1 1365
On 10 Oct 2003 14:22:39 -0700, ak****@yahoo.com (Anil) wrote:
I'm trying to come up with a way to improve upon the following.

enum Label_Type
{
Label1,
Label2,
// ...
};

enum Key_Transform_Type
{
key1_key3,
key2_key4,
// ...
};

// key to scheme mapping
Key1 => { Label1, Label2, Label3, Label5, Label7 };
Key2 => { Label4, Label6, Label7 };

// map for converting from schemeA to schemeB
{ Key1, Key2, key1_key2 }
{ Key3, Key4, key3_key4 }

class test
{
// array of values referenced by labels
};

const test& test::operator = ( const test& src )
{
// ...

Key_Transform_Type TransformType = GetTransformType(
src.GetKeyType(), GetKeyType() );

switch ( TransformType )
{
case key1_key2:
Value(Label4) = src.Value(Label1) + src.Value(Label3);
Value(Label6) = src.Value(Label2) + src.Value(Label5);
Value(Label7) = src.Value(Label7);
break;

// handle other cases
}

return (*this);
}

The basic problem is to convert values in one scheme to another and it
has to be 'fast' as well. The code is littered with switch/case
statements and there're quite a few conversion scenarios.

Since the conversion is known at compile time, could templates be used
to express the relationship between the various schemes?

Any ideas?


This won't solve _all_ of your problem, only the enum value -> associated
value.

Look at <url: http://home.no.net/dubjai/03/code/RangeMap.h> (note: 4 spaces
per tab) and usage in file [choice4/choice4.cpp] in the same directory. I
forgot to put my name, copyright etc. in that code, it's just part of a small
Norwegian tutorial in development, but I say here it's lesser GNU license.

This does away with switches and provides Pascal-like once-only checking at
initialization time (not compile time, but initialization time, e.g. first
call of a function that contains a static constant), like
enum LineWidthSpec{ width0, width1, width2, width4, width8 };
SimpleRange<LineWidthSpec> const LineWidthSpec_range( width0, width8 );
static unsigned lineWidthFrom( LineWidthSpec aWidthSpec )
{
typedef RangeMap<LineWidthSpec, unsigned> ToWidthMap;
static ToWidthMap::IndexAndValue const indexValuePairs[] =
{
{ width0, 0 },
{ width1, 1 },
{ width2, 2 },
{ width4, 4 },
{ width8, 8 }
}; // indexValuePairs
static ToWidthMap const values( LineWidthSpec_range, indexValuePairs );

return values[aWidthSpec];
} // lineWidthFrom
where at first call of lineWidthFrom it's checked that (1) all enum values
are present, and (2) no enum value is present more than once. Each index
operation also checks that the argument is in range. A non-checking index
operation should perhaps also be provided, I didn't bother... ;-)

Hth.

Jul 19 '05 #2

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

Similar topics

0
by: Sergio del Amo | last post by:
Hi, I use the xslt functions provided by php. I am running in my computer the package xampp(www.apachefriends.org) which includes php/apache/mysql .. In this package the php includes the sablotron...
3
by: pradeep gummi | last post by:
I have an XML FILE that is to be converted to Plain Text using an XSL file. Since I just want plain text, I do not want to set any root element during transformation.And if I do not any root...
4
by: Kevin Dean | last post by:
I'm trying to create an XSL transformation that will strip out development-specific attributes from deployment descriptors and other XML files. I have already successfully done so with web.xml but...
7
by: CK | last post by:
Hello, I have the 60 MB XML string and I am coding a program in Visual Basic to run a XSL transformation on it. Currently, I'm using the Microsoft standard MSXML 2.0 to create a DOM document, load...
8
by: Will | last post by:
I was thrust into XML about 2 weeks ago and don't know much yet. From another department in the corp I am receiving an XML file which concatenates nodes all on one line i.e....
4
by: Mike Conmackie | last post by:
Hi Folks, I've probably omitted something very basic but I have no idea what it might be. The results of my transformation _should_ be an xml file but all I get is the xml declaration...
6
by: Jain, Pranay Kumar | last post by:
Hi All, We have created a simple application that takes a dataset and generates the data in Excel schema format. It uses an xslt file to do the transformation for excel 2002 and so on. We are...
2
by: TomekR | last post by:
Hello ! I was developing xslt sheet lately and - experimenting - I made mistake resulting in that, the effect of the transformation is not well-formed xml document. I made these tests using...
2
by: HendrikLeder | last post by:
Hello everybody :-) Next year I`ll write my diploma in computer science for business (It`s a degree in Germany) and I`ve some questions about the topic. The diploma will handle about refactoring...
1
by: newbie | last post by:
This is probably a too general question, thanks for any feedback in advance. I am trying to write a class to do transformation on a data set. I want to make it easy to maintain in the long-run...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...

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.