Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Version 3 and Version 4 of code/doc/MultiType


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

Legend:

Unmodified
Added
Removed
Modified
  • code/doc/MultiType

    v3 v4  
    6565 * '''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.
    6666
     67=== Interaction with other !MultiTypes ===
     68 * You can assign a !MultiType to another !MultiType. The value of the other !MultiType will then be converted to the internal type of the first !MultiType: myMT '''=''' otherMT; or myMT.'''setValue('''''otherMT''''')''';
     69 * If you don't want to convert the value of the other !MultiType but assigning value AND type, use myMT.'''copy('''''otherMT''''')'''.
     70 * You can convert the value of a !MultiType to the type of another !MultiType by calling myMT.'''convert('''''otherMT''''')'''.
     71 * You can do the same with myMT.'''setType('''''otherMT''''')'''.
     72 * Of course myMT.'''setValue<'''''type'''''>('''''otherMT''''')''' works too.
    6773
    6874== Types ==
     
    106112                             // Note: The string was converted to an int
    107113
    108 value.setValue<float>(12.3); // internal type: float, value: 12.3
    109                              // Note: Now we changed the type to float and 12.3 can
    110                              //       be assigned without loss of precision
     114value.setValue<float>(12.3); // internal type: float, value: 12.3f
     115                             // Note: Now we changed the type to float and the value
     116                             //       12.3 can now be assigned without loss of precision
    111117
    112118value.convert<int>();        // internal type: int,   value: 12
    113119                             // Note: We converted the value back to int, so it's 12 again
     120
     121value.setValue<float>("50"); // internal type: float, value: 50.0f
     122                             // Note: We changed the type to float
     123                                      We assigned the string "50"
     124                                      The string was converted to the float 50.0f
    114125}}}
    115126
    116127{{{
    117 MultiType value1 = 10;   // internal type: int,   value: 10
    118 MultiType value2 = 12.3; // internal type: float, value: 12.3
     128MultiType value1 = "10";   // value1: internal type: string, value: "10"
     129MultiType value2;          // value2: currently empty
    119130
    120 value2.convert(value1);  // internal type: int,   value: 12
     131value2.setType<float>();   // value2: internal type: float,  value: 0.0f
     132
     133value2 = value1;           // value2: internal type: float,  value: 10.0f
     134}}}
     135
     136{{{
     137MultiType value1 = 10;   // value1: internal type: int,   value: 10
     138MultiType value2 = 12.3; // value2: internal type: float, value: 12.3
     139
     140value2.convert(value1);  // value2: internal type: int,   value: 12
    121141
    122142// Note: The internal type of value2 was converted to the internal type of value1 (int)