Changeset 1854 for code/trunk/src/core
- Timestamp:
- Sep 28, 2008, 5:30:14 PM (16 years ago)
- Location:
- code/trunk/src/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/core/Iterator.h
r1747 r1854 35 35 36 36 Usage: 37 for (Iterator<myClass> it = anyidentifier->getObjects() .begin(); it != anyidentifier->getObjects().end(); ++it)37 for (Iterator<myClass> it = anyidentifier->getObjects()->begin(); it != anyidentifier->getObjects()->end(); ++it) 38 38 { 39 39 it->someFunction(...); -
code/trunk/src/core/Namespace.cc
r1747 r1854 101 101 } 102 102 103 XMLPortObject (Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, mode, true, false);103 XMLPortObjectExtended(Namespace, BaseObject, "", loadObjects, saveObjects, xmlelement, mode, true, false); 104 104 } 105 105 -
code/trunk/src/core/ObjectListBase.h
r1747 r1854 71 71 { 72 72 public: 73 ObjectListElement(T* object) : ObjectListBaseElement( object), object_(object) {}73 ObjectListElement(T* object) : ObjectListBaseElement((OrxonoxClass*)object), object_(object) {} 74 74 T* object_; //!< The object 75 75 }; -
code/trunk/src/core/XMLPort.h
r1841 r1854 26 26 * 27 27 */ 28 29 /** 30 @file XMLPort.h 31 @brief Declaration of the XMLPort helper classes and macros. 32 33 XMLPort is a virtual function of every BaseObject. Every object can change this function. 34 The XMLPort function gets called with an XMLElement, containing all attributes and 35 subclasses the object gets from the levelfile. 36 37 This file declares classes and macros to simplify XML-parsing. 38 */ 28 39 29 40 #ifndef _XMLPort_H__ … … 40 51 #include "BaseObject.h" 41 52 42 53 // ------------ 54 // XMLPortParam 55 56 /** 57 @brief Declares an XML attribute with a name, which will be set through load- and savefunctions. 58 @param classname The name of the class owning this param 59 @param paramname The name of the attribute 60 @param loadfunction A function to set the param in the object with a given value (~a set-function) 61 @param savefunction A function to get the value of the param from the object (~a get-function) 62 @param xmlelement The XMLElement, you get this from the XMLPort function 63 @param mode The mode (load or save), you get this from the XMLPort function 64 65 In the XML file, a param or attribute will be set like this: 66 <classname paramname="value" /> 67 68 The macro will then call loadfunction(value) to set the given value (or call savefunction() to 69 write an existing value to an XML file). 70 */ 43 71 #define XMLPortParam(classname, paramname, loadfunction, savefunction, xmlelement, mode) \ 44 72 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode) 73 /** 74 @brief This is the same as XMLPortParam, but you can set the template arguments needed to store the loadfunction. 75 76 Sometimes the name of the loadfunction is ambiguous (example: setPosition(Vector3) or 77 setPosition(float, float, float)). In this case, you can choose the right function by 78 telling the types of the functionparams. In our example, this would be either 79 > XMLPortParamTemplate(classname, paramname, loadfunction, savefunction, xmlelement, mode, Vector3); 80 or 81 > XMLPortParamTemplate(classname, paramname, loadfunction, savefunction, xmlelement, mode, float, float, float); 82 You don't have to use this, if there exist only one function with the given name. 83 */ 45 84 #define XMLPortParamTemplate(classname, paramname, loadfunction, savefunction, xmlelement, mode, ...) \ 46 85 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor< __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode) 47 86 87 // -------------------- 88 // XMLPortParamLoadOnly 89 90 /** 91 @brief Declares an XML attribute with a name, which can be set through a loadfunction. 92 93 This is the same as XMLPortParam, but you don't need a savefunction (get-function). Therefore, 94 this param won't be saved in an XML file, but you can add the attribute manually an it will be 95 loaded. 96 97 This might be helpful in cases, when you have several options to set a value, for example the 98 rotation. You can set the rotation with a quaternion, but you could also use three angles. 99 When saving the object, only one of both options has to be saved; this is, where this macro helps. 100 */ 48 101 #define XMLPortParamLoadOnly(classname, paramname, loadfunction, xmlelement, mode) \ 49 102 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), 0, xmlelement, mode) 103 /** 104 @brief This is the same as XMLPortParamTemplate, but for load-only attributes (see XMLPortParamLoadOnly). 105 */ 50 106 #define XMLPortParamLoadOnlyTemplate(classname, paramname, loadfunction, xmlelement, mode, ...) \ 51 107 XMLPortParamGeneric(xmlcontainer##loadfunction##0, classname, classname, this, paramname, orxonox::createExecutor(orxonox::createFunctor< __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), 0, xmlelement, mode) 52 108 109 // ------------------ 110 // XMLPortParamExtern 111 112 /** 113 @brief This is the same as XMLPortParam, but for attributes in an extern class. 114 @param classname The name of the class owning the object owning the attribute 115 @param externclass The name of the extern class (the objects class) 116 @param object The name of the object of the extern class (a member of the main class) 117 @param paramname The name of the attribute 118 @param loadfunction The function to set the attribute inside of the member object. 119 @param loadfunction The function to get the attribute from the member object 120 121 Sometimes you'll have a member object in your class, which has it's own load- and savefunctions. 122 With this macro, you can simply use them instead of writing your own functions. 123 124 @example 125 Your class is called SpaceShip and this class has an object (myPilot_) of class Pilot. Pilot has a name 126 and two functions, setName(name) and getName(). Now you want an attribute "pilotname" in your 127 SpaceShip class. Instead of writing wrapper functions, you can simply use the XMLPortParamExtern 128 macro: 129 > XMLPortParamExtern(SpaceShip, Pilot, myPilot_, "pilotname", setName, getName, xmlelement, mode); 130 */ 53 131 #define XMLPortParamExtern(classname, externclass, object, paramname, loadfunction, savefunction, xmlelement, mode) \ 54 132 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, externclass, object, paramname, orxonox::createExecutor(orxonox::createFunctor(&externclass::loadfunction), std::string( #externclass ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&externclass::savefunction), std::string( #externclass ) + "::" + #savefunction), xmlelement, mode); 133 /** 134 @brief This is the same as XMLPortParamTemplate, but for extern attributes (see XMLPortParamExtern). 135 */ 55 136 #define XMLPortParamExternTemplate(classname, externclass, object, paramname, loadfunction, savefunction, xmlelement, mode, ...) \ 56 137 XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, externclass, object, paramname, orxonox::createExecutor(orxonox::createFunctor< __VA_ARGS__ >(&externclass::loadfunction), std::string( #externclass ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&externclass::savefunction), std::string( #externclass ) + "::" + #savefunction), xmlelement, mode); 57 138 139 // ------------------- 140 // XMLPortParamGeneric 141 142 /** 143 @brief This is the generic XMLPort param macro, which is used by all six specialized macros above. 144 */ 58 145 #define XMLPortParamGeneric(containername, classname, objectclass, object, paramname, loadexecutor, saveexecutor, xmlelement, mode) \ 59 146 orxonox::XMLPortClassParamContainer<objectclass>* containername = (orxonox::XMLPortClassParamContainer<objectclass>*)(ClassIdentifier<classname>::getIdentifier()->getXMLPortParamContainer(paramname)); \ … … 65 152 containername->port((BaseObject*)this, object, xmlelement, mode) 66 153 67 68 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 154 // -------------------- 155 // XMLPortObjectExtended 156 157 /** 158 @brief Declares a possible sub-object that can be added in the XML file. 159 @param classname The name of the class that uses this macro 160 @param objectclass The baseclass of objects that can be added 161 @param sectionname The name of the subsection in the XML file that encloses the sub-objects ("" means no subsection) 162 @param loadfunction The function to add a new object to the class 163 @param loadfunction The function to get all added objects from the class 164 @param xmlelement The XMLElement (recieved through the XMLPort function) 165 @param mode The mode (load/save) (received through the XMLPort function) 166 @param bApplyLoaderMask If this is true, an added sub-object only gets loaded if it's class is included in the Loaders ClassTreeMask (this is usually false) 167 @param bLoadBefore If this is true, the sub-cobject gets loaded (through XMLPort) BEFORE it gets added to the main class (this is usually true) 168 169 bApplyLoaderMask is usually false for the following reason: 170 If the loaders mask says, for example, "load only SpaceShips" and you added weapons to the 171 SpaceShips, then the Weapons will still be loaded (which is most probably what you want). 172 Of course, if there are "standalone" weapons in the level, they wont be loaded. 173 174 If bLoadBefore, an added object already has all attributes set (like it's name). This is most 175 likely the best option, so this is usually true. 176 177 @note 178 The load- and savefunctions have to follow an exactly defined protocol. 179 Loadfunction: 180 The loadfunction gets a pointer to the object. 181 > void loadfunction(objectclass* pointer); 182 183 Savefunction: 184 The savefunction gets an index, starting with 0. For every returnvalue != 0, the savefunction 185 gets called again, but with index + 1. It's the functions responsibility to do something smart 186 with the index and to return 0 if all objects were returned. 187 > objectclass* savefunction(unsigned int index) const; 188 189 Possible implementation: 190 objectclass* savefunction(unsigned int index) const 191 { 192 if (index < number_of_added_objects_) 193 return my_added_objects[index]; 194 else 195 return 0; 196 } 197 198 @example 199 Possible usage of the macro: 200 > XMLPortObject(SpaceShip, Weapon, "weapons", addWeapon, getWeapon, xmlelement, mode, false, true); 201 202 Now you can add weapons through the XML file: 203 <SpaceShip someattribute="..." ...> 204 <weapons> 205 <Weapon someattribute="..." ... /> 206 <Weapon someattribute="..." ... /> 207 <Weapon someattribute="..." ... /> 208 </weapons> 209 </SpaceShip> 210 211 Note that "weapons" is the subsection. This allows you to add more types of sub-objects. In our example, 212 you could add pilots, blinking lights or other stuff. If you don't want a subsection, just use "" (an 213 empty string). The you can add sub-objects directly into the mainclass. 214 */ 215 #define XMLPortObjectExtended(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 69 216 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 70 #define XMLPortObjectTemplate(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore, ...) \ 217 /** 218 @brief This is the same as XMLPortObjectExtended, but you can specify the loadfunction by adding the param types. See XMLPortParamTemplate for more details about the types. 219 */ 220 #define XMLPortObjectExtendedTemplate(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore, ...) \ 71 221 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor< __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, bApplyLoaderMask, bLoadBefore) 72 222 223 // ------------- 224 // XMLPortObject 225 226 /** 227 @brief This is the same as XMLPortObjectExtended, but bApplyLoaderMask is false and bLoadBefore is true by default. 228 */ 229 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode) \ 230 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, false, true) 231 /** 232 @brief This is the same as XMLPortObject, but you can specify the loadfunction by adding the param types. See XMLPortParamTemplate for more details about the types. 233 */ 234 #define XMLPortObjectTemplate(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, ...) \ 235 XMLPortObjectGeneric(xmlcontainer##loadfunction##savefunction, classname, objectclass, sectionname, orxonox::createExecutor(orxonox::createFunctor< __VA_ARGS__ >(&classname::loadfunction), std::string( #classname ) + "::" + #loadfunction), orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction), xmlelement, mode, false, true) 236 237 // -------------------- 238 // XMLPortObjectGeneric 239 240 /** 241 @brief Generic XMLPortObject macro, that gets called by all other XMLPortObject macros above. 242 */ 73 243 #define XMLPortObjectGeneric(containername, classname, objectclass, sectionname, loadexecutor, saveexecutor, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \ 74 244 orxonox::XMLPortClassObjectContainer<classname, objectclass>* containername = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(ClassIdentifier<classname>::getIdentifier()->getXMLPortObjectContainer(sectionname)); \
Note: See TracChangeset
for help on using the changeset viewer.