Changes between Version 3 and Version 4 of code/doc/MultiType
- Timestamp:
- Sep 22, 2008, 8:33:10 PM (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
code/doc/MultiType
v3 v4 65 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. 66 66 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. 67 73 68 74 == Types == … … 106 112 // Note: The string was converted to an int 107 113 108 value.setValue<float>(12.3); // internal type: float, value: 12.3 109 // Note: Now we changed the type to float and 12.3 can110 // be assigned without loss of precision114 value.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 111 117 112 118 value.convert<int>(); // internal type: int, value: 12 113 119 // Note: We converted the value back to int, so it's 12 again 120 121 value.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 114 125 }}} 115 126 116 127 {{{ 117 MultiType value1 = 10; // internal type: int, value: 10118 MultiType value2 = 12.3; // internal type: float, value: 12.3128 MultiType value1 = "10"; // value1: internal type: string, value: "10" 129 MultiType value2; // value2: currently empty 119 130 120 value2.convert(value1); // internal type: int, value: 12 131 value2.setType<float>(); // value2: internal type: float, value: 0.0f 132 133 value2 = value1; // value2: internal type: float, value: 10.0f 134 }}} 135 136 {{{ 137 MultiType value1 = 10; // value1: internal type: int, value: 10 138 MultiType value2 = 12.3; // value2: internal type: float, value: 12.3 139 140 value2.convert(value1); // value2: internal type: int, value: 12 121 141 122 142 // Note: The internal type of value2 was converted to the internal type of value1 (int)