473,609 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
+ 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_conve rtible< 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_T YPE 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_T YPE( 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++5w1G 4ZUM7KZoRArioAJ 9ypL+ABKdb4zMeE gfjbb0VpftgEQCf QKXD
gCi//HEnMUDEkqjC0XWL Ys0=
=NEZj
-----END PGP SIGNATURE-----
Jul 23 '05 #1
3 1119

Tom Howard wrote:
Create a macro called ORG_CREATE_ID_T YPE 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_T YPE( MyID )


What does this macro do?

Jul 23 '05 #2

Shezan Baig wrote:
Tom Howard wrote:
Create a macro called ORG_CREATE_ID_T YPE 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_T YPE( MyID )


What does this macro do?


Probably something along the lines of

#define ORG_CREATE_ID_T YPE(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_T YPE 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_T YPE( 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

iD8DBQFCCvodw1G 4ZUM7KZoRAoMxAK CSH7+XJea/uK80er2tMFpaISE GsQCfchPl
fsTtXefotRpBzAA 9Ogvh7IU=
=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
1632
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 applications need to serialise the classes to/from the same files but only the GUI app needs the full range of class methods. Now, the rendering app needs to be ported to multiple OS's but the GUI doesn't. In order to reduce the time/cost of porting I'd...
7
1577
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 I am confused with java where you say Test c = new Test; whre you can move this Test object around by saying "Test b" and then b = c;(so c and b points to the same object). while in c++ I think it has different meaning(like b would have different...
20
2205
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, cast to void *. Specifically, template <typename T> void f(T * t) { void * p = dynamic_cast<void *>(t) ; } will not compile if T isn't of a class that has somewhere at least
24
2318
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 compilers like GCC though. Many thanks! - Kevin
1
1383
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 sites - If no link found in DB, I want to display a message instead. I worked out I need a function to do this
11
1524
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 system identification to determine the parameters. After I determine these unknown parameters, I would like to substitute them back into the model and save the model as a new python class. To do this, I think each element needs to be able to read...
6
3524
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 Hidden_functionality { protected: // These helper classes provide some functionality that is // only used by the client classes class Helper1 {};
26
5350
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 because I am not always able to control/create all the different constructors the base class has. My problem can be described in code as follows ... /* This is the base class with a whole heap of constructors/functionality*/ public class Animal
4
1591
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 without mutual interference. The naive, yet wrong, solution is: typedef int A; typedef int B; void f(A a); void f(B b); // Error
0
8573
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
8541
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
8406
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
7002
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
6057
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
5510
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4021
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2531
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
0
1389
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.