#DEFINE "magic"...

Started by
14 comments, last by Erzengeldeslichtes 19 years, 11 months ago
quote:Original post by fredizzimo
I don''t understand why you need to use the preprocessor, when this does the same thing...

void BLAH(char* name){    cout << name;}


that would cout the contents of name, not name itself.


Sharp Basic - Coming summer 2004!
Sign Up For Sharp Basic Beta Testing!!!
Advertisement
I did say that was a simplified preproccessor call. The actual one I''m using is actually a pluggable factory creator. Since Pluggable factories are almost always the same and require only modification in name, return object, and the method of creating that object, I decided that making a macro that makes it easy to generate the class declaration was the best way to go, and then within the CPP I can do the modifications on how to create the object from a string.
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
Hey, why not make a templated version of the factory?

like:

class IFactory {virtual void* create(ID id);};//Creation policyclass ICreationMethod {virtual void* create();};class SingletonCreation : public ICreationMethod {void* create() {//create as a singleton and manage as a singleton...}}template <class TYPE, class CREATION_METHOD>class FactoryItemCreation : public CREATION_METHOD<TYPEA>, public ICreationMethod {};template <class T>class Factory : public IFactory {void* create(ID id) {return (getCreationMethod.create());}ICreationMethod* getCreationMethod(ID id) {//find the creation method of id...}bool addType(ID id, ICreationMethod* pCreator){//insert new entry...}};


Something like that, think its better than messing around with macros.
Yes, I thought of making a template, but:

quote:Original post by Erzengeldeslichtes
... and then within the CPP I can do the modifications on how to create the object from a string.


I'm not necessarilly able to modify the code to the objects I'm creating, so I can't add a string constructor, therefore I need to be able to take a string and convert it into what the constructor actually wants. As such I need derived classes that take the parameters, parse them into what the object it's designed to create needs, and then create the object with the needed parameters. That's what the macro is for, the derived classes.

[edited by - Erzengeldeslichtes on May 20, 2004 8:44:51 PM]
----Erzengel des Lichtes光の大天使Archangel of LightEverything has a use. You must know that use, and when to properly use the effects.♀≈♂?
quote:Original post by FxMazter
Hey, why not make a templated version of the factory?

like:
[snip]

Something like that, think its better than messing around with macros.
Yes, but compare the volume code you wrote for that to the 1 line macro you need...
template<typename T> inline std::string nameOfClass() {    return typeid(T).name();}


_should_ work the way you need for a factory..

class Factory {    template<typename T> register() {        register(nameOfClass<T>(),&T::create);    }}


like that..

but some compilers (vc6 i know), don''t return "T" with typeid(T).name(), but "struct T" or "class T" or whatever else..

wich, in case you want to support vc6, you have to handle (or you have to

Obj* obj = Factory::create("class T");
instead of
Obj* obj = Factory::create("T");


hope that gives an idea.. else, yes.. the #name results in "name"..



If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

This topic is closed to new replies.

Advertisement