Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 1 and Version 2 of code/doc/MultiType


Ignore:
Timestamp:
Sep 22, 2008, 8:04:42 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/MultiType

    v1 v2  
    3434
    3535== Usage ==
    36 It's important to know the MultiType has some sort of an internal type.
     36
     37=== Assign a value ===
     38There are three ways to assign a value to a MultiType:
     39 * Constructor: MultiType myMT = 10;
     40 * Assignment '''operator=''': MultiType myMT myMT = 10;
     41 * '''setValue('''''value''''')''': MultiType myMT myMT.setValue(10);
     42
     43Important: If you assign a value of a specific type and then assign a new value of another type, the new value will be converted to the first type. Read the [wiki:MultiType#internaltype section below] for detailed information.
     44
     45=== Retrieve a value ===
     46There are four three to retrieve a value from a MultiType:
     47 * Implicit conversion: float value = myMT; (or float value = (float)myMT;)
     48 * Get by pointer: '''getValue('''''pointer''''')''': float value = 0; myMT.getValue(&value);
     49 * Explicit function call: float value = myMT.getFloat().
     50
     51If the current value of the MultiType has another type, it will be converted to the implicitly or explicitly requested type.
     52
     53=== Internal type ===
     54It's very important to know the MultiType has some sort of an internal type. It's the type of the first assigned value. If you assign another value of another type, it will be converted to the first type. If you don't know about this, you may get many unnecessary conversions. But if you know about it, you can save much CPU time.
     55
     56Example:
     57 * Think about a function, receiving a float, and a MultiType, containing a string. If you want to call the function 100'000 times, you will convert the string every f***ing time into a float. So you better create a MultiType with internal type ''float'' and assign the string afterward. This way the string gets already converted when assigned and you save 99'999 conversions.
     58
     59But of course you can change this type:
     60
     61=== Change type ===
     62There are three possible ways to change the internal type of a MultiType:
     63 * '''setType<'''''type'''''>()''': This changes the type and resets the value.
     64 * '''convert<'''''type'''''>()''': This changes the type and converts the current value to the new type.
     65 * '''setValue<'''''type'''''>('''''value''''')''': This changes the type and assigns a new value. The new value may be of another value than ''type'', it will be converted.
    3766
    3867