| | 1 | = MultiType = |
| | 2 | [[TracNav(TracNav/TOC_Development)]] |
| | 3 | [[TOC]] |
| | 4 | |
| | 5 | == Introduction == |
| | 6 | |
| | 7 | 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. |
| | 8 | |
| | 9 | But what is this good for? Well, just think of an XML level. You write all values as strings, the [wiki: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. |
| | 10 | |
| | 11 | == Example == |
| | 12 | This is what you got: |
| | 13 | {{{ |
| | 14 | SomeType value = XXXX; // a value |
| | 15 | |
| | 16 | void function(OtherType value); // a function |
| | 17 | }}} |
| | 18 | |
| | 19 | This is what you want: |
| | 20 | {{{ |
| | 21 | function(value); // call the function with the value |
| | 22 | }}} |
| | 23 | |
| | 24 | This is what you know about SomeType and OtherType: |
| | 25 | {{{ |
| | 26 | // nothing |
| | 27 | }}} |
| | 28 | |
| | 29 | This is how you're doing it: |
| | 30 | {{{ |
| | 31 | function(MultiType(value)); |
| | 32 | }}} |
| | 33 | Isn't it cool? Sure it is! |
| | 34 | |
| | 35 | == Usage == |
| | 36 | It's important to know the MultiType has some sort of an internal type. |
| | 37 | |
| | 38 | |
| | 39 | == Types == |
| | 40 | Of course SomeType and OtherType from the example above can't be anything, otherwise the class would be called AnyType and probably being useless. |
| | 41 | |
| | 42 | These are the types supported by MultiType: |
| | 43 | |
| | 44 | * All primitives: |
| | 45 | * char |
| | 46 | * unsigned char |
| | 47 | * short |
| | 48 | * unsigned short |
| | 49 | * int |
| | 50 | * unsigned int |
| | 51 | * long |
| | 52 | * unsigned long |
| | 53 | * long long |
| | 54 | * unsigned long long |
| | 55 | * float |
| | 56 | * double |
| | 57 | * long double |
| | 58 | * bool |
| | 59 | * All pointers (but be careful with inheritance, in fact it's just handled as a void pointer) |
| | 60 | * std::string |
| | 61 | * Math objects: |
| | 62 | * Vector2 |
| | 63 | * Vector3 |
| | 64 | * Vector4 |
| | 65 | * Quaternion |
| | 66 | * ColourValue |
| | 67 | * Radian |
| | 68 | * Degree |