Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of ~archive/LoadParam


Ignore:
Timestamp:
Nov 27, 2007, 10:44:33 PM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • ~archive/LoadParam

    v1 v1  
     1= LoadParam =
     2A functor that enables us to (very) easy load many different Types of data onto all objects in orxonox.
     3LoadParam can be found source:trunk/src/lib/util/loading/load_param.h#HEAD
     4
     5== Usage ==
     6this loads from class className the parameter from the XML file parameterName, and sends the output to paramFunction.
     7  * using the __Lumberjack-Method__:
     8{{{
     9#!cpp
     10LoadParam(XMLROOT, PARAMNAME, OBJECT, CLASS, FUNCTIONNAME)
     11}}}
     12   * XMLROOT: normaly the root, where a given parameter is located under
     13   * PARAMNAME: the Parameter in the XML file
     14   * OBJECT: The Object to which we would load the Information (normally this)
     15   * CLASS: the class we want to load it to
     16   * FUNCTIONNAME: The name of the function we want to load
     17
     18Actually the two Function up there do exactly the same Thing. (only with the second one, you can do more elaborate things.)
     19
     20At the end you could also specify some default Values, by just adding them, as you would as parameters of the selected Function.
     21
     22== Document what you do ==
     23 There is also the possibility to document what you are doing.
     24Just use a trailing
     25{{{
     26#!cpp
     27.describe("what this does").
     28}}}
     29and we can easily write a full featured documentation.
     30
     31== what is cool about it ==
     32Because LoadParam is a Functor with multiple input methoids it is comprehends (normally) what arguments must be given to the Function, and will split your input (in the XML-file) into what it needs.
     33
     34== Example ==
     35{{{
     36#!cpp
     37/**
     38  \brief loads the Parameters of a Campaign
     39  \param root: The XML-element to load from
     40 */
     41void Campaign::loadParams(const TiXmlElement* root)
     42{
     43  static_cast<BaseObject*>(this)->loadParams(root);
     44
     45  LoadParam(root, "identifier", this, Campaign, setStoryID, false)
     46      .describe("A Unique Identifier for this Campaign")
     47      ->defaultValues(1, 0);
     48
     49  LoadParam(root, "WorldList", this, Campaign, loadWorldListParams)
     50      .describe("A List of Worlds to be loaded in this Campaign");
     51}
     52}}}
     53
     54Loads the following:
     55{{{
     56#!xml
     57<Campaign>
     58 <name>string</name> -- the name of the Object at hand (Default: "")
     59 <identifier>int</identifier> -- A Unique Identifier for this Campaign (Default: 0)
     60 <WorldList>XML-Element</WorldList> -- A List of Worlds to be loaded in this Campaign
     61</Campaign>
     62}}}
     63as you can see also <name> gets loaded, this is because Campaign is derived from BaseObject, and as you can see in the loadParams function, its loadParams also gets called.
     64
     65also you may have noticed the Default arguments of <identifier>, because you specified 0 as default
     66
     67(output may differ, from the above)