473,486 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Classes with the same functionality but not convertible

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

On a project I'm working on we need a few of ID classes for various sub
systems. Each ID class (e.g. EntityID, ClassID, PhysicsID, AnimationID)
does exactly the same thing, but we would like to prevent conversion
from different types of IDs (e.g. boost::is_convertible< EntityID,
ClassID >::value is false), to avoid stupid errors.

So far we have come up with to methods for achieving this.

Method 1:

Create a macro called ORG_CREATE_ID_TYPE which takes a class name as an
argument, then when you need a new ID class, you just include the header
where the macro is defined and add

ORG_CREATE_ID_TYPE( MyID )

where you need MyID defined

Method 2:

enum IDTag { EntityIDTag, ClassIDTag, ..., MyIDTag };

template< IDTag T >
class BaseID
{
....
};

typedef BaseID< EntityIDTag > EntityID;
typedef BaseID< ClassIDTag > ClassID;
....
typedef BaseID< MyIDTag > MyID;

The template method is preferred but it is 17% slower to compile, which
given the size of the project and the number of developers is going to
add up to too much time over the next couple of years.

Is there another option I'm overlooking or some techniques you can think
of to make the template method faster?

Thanks in advance.

Cheers,

Tom Howard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCB++5w1G4ZUM7KZoRArioAJ9ypL+ABKdb4zMeEgfjbb 0VpftgEQCfQKXD
gCi//HEnMUDEkqjC0XWLYs0=
=NEZj
-----END PGP SIGNATURE-----
Jul 23 '05 #1
3 1113

Tom Howard wrote:
Create a macro called ORG_CREATE_ID_TYPE which takes a class name as an argument, then when you need a new ID class, you just include the header where the macro is defined and add

ORG_CREATE_ID_TYPE( MyID )


What does this macro do?

Jul 23 '05 #2

Shezan Baig wrote:
Tom Howard wrote:
Create a macro called ORG_CREATE_ID_TYPE which takes a class name
as an
argument, then when you need a new ID class, you just include the

header
where the macro is defined and add

ORG_CREATE_ID_TYPE( MyID )


What does this macro do?


Probably something along the lines of

#define ORG_CREATE_ID_TYPE(MyID) \
struct #MyID { \
//... \
}

Another option you should consider is a script (e.g., Perl) that
generates new ID-type components. This should reduce the burden on your
compiler. /david

Jul 23 '05 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Shezan Baig wrote:
Tom Howard wrote:
Create a macro called ORG_CREATE_ID_TYPE which takes a class name as


an
argument, then when you need a new ID class, you just include the


header
where the macro is defined and add

ORG_CREATE_ID_TYPE( MyID )

What does this macro do?


#define ORG_CREATE_ID_TYPE( id_name ) \
class id_name \
{ \
....
};

It does the trick, but we would like to avoid the macro usage if
possible. One of the reasons being that Intellisense in VC++ doesn't
play with the macro generated classes.

Templates are logically the way to go, because with templates each id
class is an instance of the id template which is conceptually exactly
what we want, however we can't find a way to overcome the speed hiccup.

Cheers,

Tom Howard
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCCvodw1G4ZUM7KZoRAoMxAKCSH7+XJea/uK80er2tMFpaISEGsQCfchPl
fsTtXefotRpBzAA9Ogvh7IU=
=5Qhg
-----END PGP SIGNATURE-----
Jul 23 '05 #4

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

Similar topics

9
1623
by: Jack | last post by:
Hello I have a library of calculationally intensive classes that is used both by a GUI based authoring application and by a simpler non-interactive rendering application. Both of these...
7
1568
by: Snake | last post by:
Hi guys, I have question about classes. when u create class called Test. and you define variable Test c; so does this act like( a variable c of type Test pointing to an abject )? The thing that...
20
2183
by: verec | last post by:
One problem I've come accross in designing a specific version of auto_ptr is that I have to disntiguish between "polymorphic" arguments and "plain" ones, because the template has to, internally,...
24
2290
by: kevin.hall | last post by:
Is char** (or char*) implicitly convertible to 'const char * const *'? I couldn't find anything about it in the standard. MSVS 8.0 allows this. I'm curious if I'll run into trouble with other...
1
1367
by: Simon Harris | last post by:
Hi All, I'm new to asp.net (Migrating from 'Classic' ASP) I'm having troubles working out classes, functions etc... Current situation is this: index.aspx displays datalist with links to...
11
1513
by: Ryan Krauss | last post by:
I have a set of Python classes that represent elements in a structural model for vibration modeling (sort of like FEA). Some of the parameters of the model are initially unknown and I do some...
6
3515
by: mailforpr | last post by:
Suppose you have a couple of helper classes that are used by 2 client classes only. How can I hide these helper classes from other programmers? Do you think this solution is a good idea?: class...
26
5333
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
4
1574
by: redqil | last post by:
The problem I am facing is that an integer is the ideal representation for many different classes I am using. I want to write overloaded functions that are able to differentiate between the classes...
0
6964
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
7126
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
5434
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
4865
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
3070
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
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
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 ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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...

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.