Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 3, 2006, 12:19:30 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/loading/load_param_description.cc

    r8362 r9869  
    1717
    1818#include "multi_type.h"
    19 #include <stdarg.h>
    2019#include "debug.h"
    2120
    2221/**
     22 * @brief Creates a Description of a LoadParam
    2323 * @param paramName the name of the parameter to load
    2424 */
    2525LoadParamDescription::LoadParamDescription(const std::string& paramName)
    26 {
    27   this->types = NULL;
    28   this->defaultValues = NULL;
    29   this->paramName = paramName;
    30 }
    31 
    32 /**
    33  *  removes all the alocated memory
    34  */
    35 LoadParamDescription::~LoadParamDescription()
    36 {
    37   if (this->defaultValues != NULL)
    38   {
    39     for(int i = 0; i < this->paramCount; i++)
    40     {
    41       delete[] this->defaultValues[i];
    42     }
    43   }
    44 
    45   delete[] this->types;
    46   delete[] this->defaultValues;
    47 }
     26    : _name(paramName), _parameterCount(0)
     27{ }
    4828
    4929/**
     
    5232void LoadParamDescription::setDescription(const std::string& descriptionText)
    5333{
    54   this->description = descriptionText;
     34  this->_description = descriptionText;
    5535}
    5636
    5737/**
    58  *  prints out this parameter, its input method and the description (if availiable)
     38 * @brief sets the Values of the LoadParam in the Description.
     39 * @param paramCount the count of arguments the underlying paramDescription takes.
     40 * @param defaultValues the default Values the underlying parameter takes.
     41 * @param retVal if the underlying parameter has a return value
    5942 */
    60 void LoadParamDescription::print() const
     43void LoadParamDescription::setValues(unsigned int paramCount,
     44                                     const MultiType* const defaultValues,
     45                                     bool retVal)
    6146{
    62   PRINT(3)(" <%s>", this->paramName.c_str());
    63   for (int i = 0; i < this->paramCount; i++)
     47  this->_parameterCount = paramCount;
     48  for (unsigned int i = 0; i < paramCount; ++i)
    6449  {
    65     if (i > 0)
    66       PRINT(3)(",");
    67     // FIXME
    68     //     switch (this->types[i])
    69 //     {
    70 //       default:
    71 //         PRINTF(3)("none");
    72 //         break;
    73 //       case ParameterBool:
    74 //         PRINT(3)("bool");
    75 //         break;
    76 //       case ParameterChar:
    77 //         PRINT(3)("char");
    78 //         break;
    79 //       case ParameterString:
    80 //         PRINT(3)("string");
    81 //         break;
    82 //       case ParameterInt:
    83 //         PRINT(3)("int");
    84 //         break;
    85 //       case ParameterUInt:
    86 //         PRINT(3)("Uint");
    87 //         break;
    88 //       case ParameterFloat:
    89 //         PRINT(3)("float");
    90 //         break;
    91 //       case ParameterLong:
    92 //         PRINT(3)("long");
    93 //         break;
    94 //       case ParameterXML:
    95 //         PRINT(3)("XML");
    96 //         break;
    97 //     }
     50    this->_defaultValues.push_back(defaultValues[i].getString());
     51    this->_types.push_back(MultiType::MultiTypeToString(defaultValues[i].getType()));
    9852  }
    99   PRINT(3)("</%s>", this->paramName.c_str());
    100   if (!this->description.empty())
    101     PRINT(3)(" -- %s", this->description.c_str());
    102   // default values
    103   if (this->paramCount > 0)
    104   {
    105     PRINT(3)(" (Default: ");
    106     for (int i = 0; i < this->paramCount; i++)
    107     {
    108       if (i > 0)
    109         PRINT(3)(", ");
    110       if (this->types[i] & MT_STRING)
    111       { // leave brackets !!
    112         PRINT(3)("\"%s\"", this->defaultValues[i]);
    113       }
    114       else
    115       {
    116         PRINT(3)("%s", this->defaultValues[i]);
    117       }
    118     }
    119     PRINT(3)(")");
    120   }
    121   PRINT(3)("\n");
    122 }
    12353
    124 /**
    125  *  A list, that holds all the classes that are loadable (classes not objects!!)
    126  */
    127 std::list<LoadClassDescription*>* LoadClassDescription::classList = NULL;
    128 
    129 /**
    130  *  if the description of Parameters should be executed
    131  */
    132 bool LoadClassDescription::parametersDescription = false;
    133 
    134 /**
    135  * @param className the name of the class to be loadable
    136  */
    137 LoadClassDescription::LoadClassDescription(const std::string& className)
    138 {
    139   this->className = className;
    140 
    141   if (LoadClassDescription::classList == NULL)
    142     LoadClassDescription::classList = new std::list<LoadClassDescription*>;
    143 
    144   LoadClassDescription::classList->push_back(this);
    145 }
    146 
    147 /**
    148  *  deletes a classDescription (deletes all the parameterDescriptions as well
    149  */
    150 LoadClassDescription::~LoadClassDescription()
    151 {
    152   std::list<LoadParamDescription*>::iterator it = this->paramList.begin();
    153   while (!this->paramList.empty())
    154   {
    155     delete this->paramList.front();
    156     this->paramList.pop_front();
    157   }
    158 }
    159 
    160 void LoadClassDescription::deleteAllDescriptions()
    161 {
    162   if (LoadClassDescription::classList != NULL)
    163   {
    164     while (!LoadClassDescription::classList->empty())
    165     {
    166       delete LoadClassDescription::classList->front();
    167       LoadClassDescription::classList->pop_front();
    168     }
    169     delete LoadClassDescription::classList;
    170   }
    171   LoadClassDescription::classList = NULL;
    17254}
    17355
    17456
    17557/**
    176  *  adds a class to the list of loadable classes
    177  * @param className The name of the class to add
    178 
    179    this function searches for the className string, and if found just returns the appropriate Class.
    180    Otherwise it returns a new classDescription
     58 * @brief prints out this parameter, its input method and the description (if availiable)
     59 * @param stream the stream to print to.
     60 * @param withComments if the comments should be appended.
    18161 */
    182 LoadClassDescription* LoadClassDescription::addClass(const std::string& className)
     62void LoadParamDescription::print(FILE* stream, bool withComments) const
    18363{
    184   if (LoadClassDescription::classList != NULL)
     64  fprintf(stream, " <%s>", this->_name.c_str());
     65  for (unsigned int i = 0; i < this->_parameterCount; i++)
    18566  {
    186     std::list<LoadClassDescription*>::iterator it = LoadClassDescription::classList->begin();
    187     while (it != LoadClassDescription::classList->end())
     67    if (i > 0)
     68      fprintf(stream, ",");
     69    fprintf(stream, "%s", this->_types[i].c_str());
     70  }
     71  fprintf(stream, "</%s>", this->_name.c_str());
     72  // here the comments are printed out.
     73  if (withComments)
     74  {
     75    if (!this->_description.empty())
     76      fprintf(stream, " <!-- %s", this->_description.c_str());
     77    // default values
     78    if (this->_parameterCount > 0)
    18879    {
    189       if ((*it)->className == className)
     80      fprintf(stream, " (Default: ");
     81      for (unsigned int i = 0; i < this->_parameterCount; i++)
    19082      {
    191         return (*it);
     83        if (i > 0)
     84          fprintf(stream, ", ");
     85        if (this->_types[i] == "string")
     86        { // leave brackets !!
     87          fprintf(stream, "\"%s\"", this->_defaultValues[i].c_str());
     88        }
     89        else
     90        {
     91          fprintf(stream, "%s", this->_defaultValues[i].c_str());
     92        }
    19293      }
    193       it++;
     94      fprintf(stream, ")");
    19495    }
     96    if (!this->_description.empty() || this->_parameterCount > 0)
     97      fprintf(stream, " -->");
    19598  }
    196   return new LoadClassDescription(className);
     99  fprintf(stream, "\n");
    197100}
    198101
    199 /**
    200  *  does the same as addClass(const std::string& className), but with params
    201  * @param paramName the name of the parameter to add.
    202  */
    203 LoadParamDescription* LoadClassDescription::addParam(const std::string& paramName)
    204 {
    205   std::list<LoadParamDescription*>::iterator it = this->paramList.begin();
    206   while (it != this->paramList.end())
    207   {
    208     if ((*it)->paramName == paramName)
    209     {
    210       return NULL;
    211     }
    212     it++;
    213   }
    214102
    215   LoadParamDescription* newParam = new LoadParamDescription(paramName);
    216 
    217   this->paramList.push_back(newParam);
    218   return newParam;
    219 }
    220 
    221 /**
    222  *  prints out all loadable Classes, and their parameters
    223  * @param fileName prints the output to a File
    224  * @todo implement it
    225  */
    226 void LoadClassDescription::printAll(const std::string& fileName)
    227 {
    228   PRINT(3)("===============================================================\n");
    229   PRINT(3)(" Listing all the Loadable Options (loaded since Game started).\n\n");
    230   if (LoadClassDescription::classList != NULL)
    231   {
    232     std::list<LoadClassDescription*>::iterator classDesc = LoadClassDescription::classList->begin();
    233     while (classDesc != LoadClassDescription::classList->end())
    234     {
    235       PRINT(3)("<%s>\n", (*classDesc)->className.c_str());
    236       std::list<LoadParamDescription*>::iterator param = (*classDesc)->paramList.begin();
    237       while (param != (*classDesc)->paramList.end())
    238       {
    239         (*param)->print();
    240         param++;
    241       }
    242       PRINT(3)("</%s>\n\n", (*classDesc)->className.c_str());
    243       classDesc++;
    244     }
    245   }
    246   else
    247     PRINT(3)("no Classes defined so far\n");
    248   PRINT(3)("===============================================================\n");
    249 }
    250 
    251 /**
    252  * searches for classes, which beginn with classNameBegin
    253  * @param classNameBegin the beginning string of a Class
    254  * @return a NEW char-array with ClassNames. The LIST should be deleted afterwards,
    255  * !! The strings MUST NOT be deleted !!
    256  */
    257 std::list<std::string> LoadClassDescription::searchClassWithShort(const std::string& classNameBegin)
    258 {
    259   /// FIXME
    260   // NOT USED
    261 /*  unsigned int searchLength = strlen(classNameBegin);
    262   std::list<const std::string&> retVal;
    263 
    264   tIterator<LoadClassDescription>* iterator = LoadClassDescription::classList->getIterator();
    265   LoadClassDescription* enumClassDesc = iterator->firstElement();
    266   while (enumClassDesc)
    267   {
    268     if (strlen(enumClassDesc->className)>searchLength+1 &&
    269         !strncasecmp(enumClassDesc->className, classNameBegin, searchLength))
    270     {
    271       retVal->add(enumClassDesc->className);
    272     }
    273     enumClassDesc = iterator->nextElement();
    274   }
    275   delete iterator;
    276 
    277   return retVal;*/
    278   std::list<std::string> a;
    279   return a;
    280 }
Note: See TracChangeset for help on using the changeset viewer.