| 145 | === General === |
| 146 | To connect objects, you have to put one object into another object in the XML file: |
| 147 | {{{ |
| 148 | <SomeClass param=...> |
| 149 | <connected-objects> |
| 150 | <OtherClass param=... /> |
| 151 | <OtherClass param=... /> |
| 152 | <OtherClass param=... /> |
| 153 | </connected-objects> |
| 154 | <more-objects> |
| 155 | <DifferentClass param=... /> |
| 156 | <DifferentClass param=... /> |
| 157 | </more-objects> |
| 158 | </SomeClass> |
| 159 | }}} |
| 160 | In this example, we create one instance of ''SomeClass'' and connect three instances of ''OtherClass'' and two instances of ''DifferentClass'' to it. |
| 161 | |
| 162 | To let the instance of ''SomeClass'' know there are some connected objects, we have to pass them to a function of ''SomeClass''. This can be achieved by using XMLPortObject: |
| 163 | {{{ |
| 164 | void SomeClass::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
| 165 | { |
| 166 | SUPER(SomeClass, XMLPort, xmlelement, mode); |
| 167 | |
| 168 | XMLPortObject(SomeClass, OtherClass, "connected-objects", connectObject, getConnectedObject, \ |
| 169 | xmlelement, mode); |
| 170 | XMLPortObject(SomeClass, DifferentClass, "more-objects", addDifferentObject, getDifferentObject, \ |
| 171 | xmlelement, mode); |
| 172 | } |
| 173 | }}} |
| 174 | Note: We used XMLPortObject two times because we have two subsections with different types of connected objects. |
| 175 | |
| 176 | XMLPortObject has the following form: |
| 177 | * '''XMLPortObject('''''classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode''''')''' |
| 178 | |
| 179 | ''objectclass'' is the class of the conneted objects in the specified subsection.[[br]] |
| 180 | ''sectionname'' is the name of the subsection. |
| 181 | |
| 182 | '''Important''': If sectionname is an empty string (""), '''no''' subsection is used, so you can put sub-objects directly into the base object. |
| 183 | |
| 184 | The set- and the get-function must have the following form: |
| 185 | * void set-function(objectclass* object); |
| 186 | * const objectclass* get-function(unsigned int index) const; |
| 187 | |
| 188 | The set-function just passes the pointer of the connected object.[[br]] |
| 189 | The get-function returns a different pointer for each index, starting with zero. If all pointers were returned, the get-function returns a NULL pointer and the process stops. |
| 190 | |
| 191 | Note: There is also a related macro called XMLPortObjectTemplate used to avoid ambiguity (see [wiki:XMLPort#Ambiguity the chapter above]). |
| 192 | |
| 193 | === Extended === |
| 194 | There is an extended version of the XMLPortParam macro, taking two additional arguments: |
| 195 | * '''XMLPortObjectExtended('''''classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore''''')''' |
| 196 | |
| 197 | If ''bApplyLoaderMask'' is true, a subobject gets only created and connected if it's class is included in the mask of the [wiki:Loader]. This argument is usually ''false'' because not connecting a subobject might damage the base-object, although the base-object IS included in the Loaders mask and should therefore not be touched. |
| 198 | |
| 199 | If ''bLoadBefore'' is true, the subobject will get connected after all parameters (and subobjects of the subobject) are completely loaded. This argument is usually ''true'' because we might use the connected object already in the set-function. If the subobject is not already loaded at this point, this could cause trouble. |
| 200 | |
| 201 | Note: There is also a related macro called XMLPortObjectExtendedTemplate used to avoid ambiguity (see [wiki:XMLPort#Ambiguity the chapter above]). |