Run-time type define 
Author Message
 Run-time type define

//------------------------------------
struct Color15bit{....};
struct Color16bit{....};

//------------------------------------
if( ColorMode == 15 )
    typedef Color15bit Color16;
else if( ColorMode == 16 )
    typedef Color16bit Color16;

//----------------------------------
Color16 aPixel(255, 255, 255 );
//***********************************************//

I know this is impossible

How can I have same effect like that?



Mon, 13 Oct 2003 22:45:00 GMT  
 Run-time type define
Use polymorphism :)
For example:
Abstract class Color with Color specific methods.
Concrete classes Color15 and Color16 deriving from Color and implementing
the interface Color specifies.

Then when you create a specific Color object you can use a ColorFactory, for
example, that creates the right concrete Color
object depending on the ColorMode like:

class Color {...};
class Color15 : public Color {...};
class Color16 : public Color {...};

Color* ColorFactory::MakeColor()
{
    if(ColorMode == 15)
        return new Color15;
    else if(ColorMode == 16)
        return new Color16;

Quote:
}

...
Color* aPixel = ColorFactory::MakeColor();
...

This is a very simplistic implementation, but the essence of the concept is
there I think. :)

Regards,
Dadi.


Quote:
> file://------------------------------------
> struct Color15bit{....};
> struct Color16bit{....};

> file://------------------------------------
> if( ColorMode == 15 )
>     typedef Color15bit Color16;
> else if( ColorMode == 16 )
>     typedef Color16bit Color16;

> file://----------------------------------
> Color16 aPixel(255, 255, 255 );
> file://***********************************************//

> I know this is impossible

> How can I have same effect like that?



Tue, 14 Oct 2003 00:46:07 GMT  
 Run-time type define
You could use a class hierarchy, such as:

class ColorPixel
{
public:
    ColorPixel(int red, int green, int blue);
    // whatever colors can do

Quote:
};

class ColorPixel15 : public ColorPixel
{
public:
    ColorPixel15(int red, int green, int blue) : ColorPixel(red, green,
blue) { }
    // whatever additional things ColorPixel15s can do

Quote:
};

class ColorPixel16 : public ColorPixel
{
public:
    ColorPixel16(int red, int green, int blue) : ColorPixel(red, green,
blue) { }
    // whatever additional things ColorPixel16s can do

Quote:
};

// somewhere off in code:
ColorPixel* pPixel = NULL;
if (ColorMode == 15)
    pPixel  = new ColorPixel 15;
else if (ColorMode == 16)
    pPixel = new ColorPixel 16;

// etc.


Quote:
> //------------------------------------
> struct Color15bit{....};
> struct Color16bit{....};

> //------------------------------------
> if( ColorMode == 15 )
>     typedef Color15bit Color16;
> else if( ColorMode == 16 )
>     typedef Color16bit Color16;

> //----------------------------------
> Color16 aPixel(255, 255, 255 );
> //***********************************************//

> I know this is impossible

> How can I have same effect like that?



Tue, 14 Oct 2003 01:05:17 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Determining type at run-time or compile-time

2. How to define enum type in runtime?

3. Run time error (#define) challeng !!

4. Mathematical Function - defining at run-time??

5. run time type checking

6. Choose type of the object in run-time

7. Bug in C# run-time type information?

8. Q: malloc and type info - fatal run-time eror

9. Data types at run time

10. Determine Column Data Type at run time

11. fast run-time type idenitification

12. Run-time type information

 

 
Powered by phpBB® Forum Software