Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 1 (modified by landauf, 17 years ago) (diff)

LoadParam

A functor that enables us to (very) easy load many different Types of data onto all objects in orxonox. LoadParam can be found source:trunk/src/lib/util/loading/load_param.h#HEAD

Usage

this loads from class className the parameter from the XML file parameterName, and sends the output to paramFunction.

  • using the Lumberjack-Method:
    LoadParam(XMLROOT, PARAMNAME, OBJECT, CLASS, FUNCTIONNAME)
    
    • XMLROOT: normaly the root, where a given parameter is located under
    • PARAMNAME: the Parameter in the XML file
    • OBJECT: The Object to which we would load the Information (normally this)
    • CLASS: the class we want to load it to
    • FUNCTIONNAME: The name of the function we want to load

Actually the two Function up there do exactly the same Thing. (only with the second one, you can do more elaborate things.)

At the end you could also specify some default Values, by just adding them, as you would as parameters of the selected Function.

Document what you do

There is also the possibility to document what you are doing.

Just use a trailing

.describe("what this does").

and we can easily write a full featured documentation.

what is cool about it

Because 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.

Example

/**
  \brief loads the Parameters of a Campaign
  \param root: The XML-element to load from
 */
void Campaign::loadParams(const TiXmlElement* root)
{
  static_cast<BaseObject*>(this)->loadParams(root);

  LoadParam(root, "identifier", this, Campaign, setStoryID, false)
      .describe("A Unique Identifier for this Campaign")
      ->defaultValues(1, 0);

  LoadParam(root, "WorldList", this, Campaign, loadWorldListParams)
      .describe("A List of Worlds to be loaded in this Campaign");
}

Loads the following:

<Campaign>
 <name>string</name> -- the name of the Object at hand (Default: "")
 <identifier>int</identifier> -- A Unique Identifier for this Campaign (Default: 0)
 <WorldList>XML-Element</WorldList> -- A List of Worlds to be loaded in this Campaign
</Campaign>

as 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.

also you may have noticed the Default arguments of <identifier>, because you specified 0 as default

(output may differ, from the above)