Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 1 (modified by landauf, 16 years ago) (diff)

MultiType

TracNav(TracNav/TOC_Development)?

Introduction

The MultiType is a fancy class, designed to accept values of almost every type and to return exactly this value in almost every other type - depending on your needs. This allows you to assign a string, for example "105.3", to a MultiType and to let the MultiType return 105.3 as a float.

But what is this good for? Well, just think of an XML level. You write all values as strings, the Loader? loads the level, creates new objects and passes the values to the objects. But how should the Loader know, which type a value has? It just loads a string! Thats why the Loader puts the string into a MultiType and passes it to the new object. The object receives the MultiType and C++ does an implicit conversion to the requested type.

Example

This is what you got:

SomeType value = XXXX; // a value

void function(OtherType value); // a function

This is what you want:

function(value); // call the function with the value

This is what you know about SomeType and OtherType:

// nothing

This is how you're doing it:

function(MultiType(value));

Isn't it cool? Sure it is!

Usage

It's important to know the MultiType has some sort of an internal type.

Types

Of course SomeType and OtherType from the example above can't be anything, otherwise the class would be called AnyType and probably being useless.

These are the types supported by MultiType:

  • All primitives:
    • char
    • unsigned char
    • short
    • unsigned short
    • int
    • unsigned int
    • long
    • unsigned long
    • long long
    • unsigned long long
    • float
    • double
    • long double
    • bool
  • All pointers (but be careful with inheritance, in fact it's just handled as a void pointer)
  • std::string
  • Math objects:
    • Vector2
    • Vector3
    • Vector4
    • Quaternion
    • ColourValue
    • Radian
    • Degree