Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5141 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Aug 26, 2005, 4:04:53 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: moved helper-functions to helper-functions.cc

Location:
trunk/src
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r5133 r5141  
    8282                  lib/util/substring.cc \
    8383                  lib/util/color.cc \
     84                  lib/util/helper_functions.cc \
    8485                  lib/math/vector.cc \
    8586                  lib/math/curve.cc \
     
    157158                 lib/util/list.h \
    158159                 lib/util/color.h \
     160                 lib/util/helper_functions.h \
    159161                 lib/math/vector.h \
    160162                 lib/math/curve.h \
  • trunk/src/Makefile.in

    r5133 r5141  
    8181        orxonox-class_list.$(OBJEXT) orxonox-ini_parser.$(OBJEXT) \
    8282        orxonox-substring.$(OBJEXT) orxonox-color.$(OBJEXT) \
    83         orxonox-vector.$(OBJEXT) orxonox-curve.$(OBJEXT) \
    84         orxonox-glmenu_imagescreen.$(OBJEXT) \
     83        orxonox-helper_functions.$(OBJEXT) orxonox-vector.$(OBJEXT) \
     84        orxonox-curve.$(OBJEXT) orxonox-glmenu_imagescreen.$(OBJEXT) \
    8585        orxonox-benchmark.$(OBJEXT)
    8686orxonox_OBJECTS = $(am_orxonox_OBJECTS)
     
    109109@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-glmenu_imagescreen.Po \
    110110@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-graphics_engine.Po \
     111@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-helper_functions.Po \
    111112@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-ini_parser.Po \
    112113@AMDEP_TRUE@    ./$(DEPDIR)/orxonox-light.Po \
     
    342343                  lib/util/substring.cc \
    343344                  lib/util/color.cc \
     345                  lib/util/helper_functions.cc \
    344346                  lib/math/vector.cc \
    345347                  lib/math/curve.cc \
     
    417419                 lib/util/list.h \
    418420                 lib/util/color.h \
     421                 lib/util/helper_functions.h \
    419422                 lib/math/vector.h \
    420423                 lib/math/curve.h \
     
    519522@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-glmenu_imagescreen.Po@am__quote@
    520523@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-graphics_engine.Po@am__quote@
     524@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-helper_functions.Po@am__quote@
    521525@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-ini_parser.Po@am__quote@
    522526@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/orxonox-light.Po@am__quote@
     
    13691373@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
    13701374@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-color.obj `if test -f 'lib/util/color.cc'; then $(CYGPATH_W) 'lib/util/color.cc'; else $(CYGPATH_W) '$(srcdir)/lib/util/color.cc'; fi`
     1375
     1376orxonox-helper_functions.o: lib/util/helper_functions.cc
     1377@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT orxonox-helper_functions.o -MD -MP -MF "$(DEPDIR)/orxonox-helper_functions.Tpo" -c -o orxonox-helper_functions.o `test -f 'lib/util/helper_functions.cc' || echo '$(srcdir)/'`lib/util/helper_functions.cc; \
     1378@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/orxonox-helper_functions.Tpo" "$(DEPDIR)/orxonox-helper_functions.Po"; else rm -f "$(DEPDIR)/orxonox-helper_functions.Tpo"; exit 1; fi
     1379@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='lib/util/helper_functions.cc' object='orxonox-helper_functions.o' libtool=no @AMDEPBACKSLASH@
     1380@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/orxonox-helper_functions.Po' tmpdepfile='$(DEPDIR)/orxonox-helper_functions.TPo' @AMDEPBACKSLASH@
     1381@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1382@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-helper_functions.o `test -f 'lib/util/helper_functions.cc' || echo '$(srcdir)/'`lib/util/helper_functions.cc
     1383
     1384orxonox-helper_functions.obj: lib/util/helper_functions.cc
     1385@am__fastdepCXX_TRUE@   if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT orxonox-helper_functions.obj -MD -MP -MF "$(DEPDIR)/orxonox-helper_functions.Tpo" -c -o orxonox-helper_functions.obj `if test -f 'lib/util/helper_functions.cc'; then $(CYGPATH_W) 'lib/util/helper_functions.cc'; else $(CYGPATH_W) '$(srcdir)/lib/util/helper_functions.cc'; fi`; \
     1386@am__fastdepCXX_TRUE@   then mv -f "$(DEPDIR)/orxonox-helper_functions.Tpo" "$(DEPDIR)/orxonox-helper_functions.Po"; else rm -f "$(DEPDIR)/orxonox-helper_functions.Tpo"; exit 1; fi
     1387@AMDEP_TRUE@@am__fastdepCXX_FALSE@      source='lib/util/helper_functions.cc' object='orxonox-helper_functions.obj' libtool=no @AMDEPBACKSLASH@
     1388@AMDEP_TRUE@@am__fastdepCXX_FALSE@      depfile='$(DEPDIR)/orxonox-helper_functions.Po' tmpdepfile='$(DEPDIR)/orxonox-helper_functions.TPo' @AMDEPBACKSLASH@
     1389@AMDEP_TRUE@@am__fastdepCXX_FALSE@      $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
     1390@am__fastdepCXX_FALSE@  $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(orxonox_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o orxonox-helper_functions.obj `if test -f 'lib/util/helper_functions.cc'; then $(CYGPATH_W) 'lib/util/helper_functions.cc'; else $(CYGPATH_W) '$(srcdir)/lib/util/helper_functions.cc'; fi`
    13711391
    13721392orxonox-vector.o: lib/math/vector.cc
  • trunk/src/defs/class_id.h

    r5137 r5141  
    194194  CL_NUMBER                     =    0x00000b0c,
    195195  CL_FAST_FACTORY               =    0x00000c01,
     196  CL_SHELL_COMMAND              =    0x00000c02,
    196197
    197198
  • trunk/src/lib/util/helper_functions.cc

    r5114 r5141  
    1010
    1111   ### File Specific:
    12    main-programmer: ...
     12   main-programmer: Benjamin Grauer
    1313   co-programmer: ...
    1414*/
     
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "proto_class.h"
     18#include "helper_functions.h"
     19#include "stdlibincl.h"
    1920
    2021using namespace std;
    2122
     23/**
     24 * checks if the input was a Bool
     25 * @param BOOL a String that holds a bool: must be one of those: 1,0,true,false,TRUE,FALSE
     26 * @param defaultValue a default value that is set, if BOOL is corrupt
     27 * @return returns the bool, if BOOL was correct otherwise defaultValue
     28 */
     29bool isBool(const char* BOOL, bool defaultValue)
     30{
     31  if(!strcmp(BOOL, "1") || !strcmp( BOOL,"true") || !strcmp(BOOL,"TRUE"))
     32    return true;
     33  else if (!strcmp(BOOL, "0") || !strcmp( BOOL,"false") || !strcmp(BOOL,"FALSE"))
     34    return false;
     35  else
     36    return defaultValue;
    2237
    23 /**
    24  * standard constructor
    25  * @todo this constructor is not jet implemented - do it
    26 */
    27 ProtoClass::ProtoClass ()
     38}
     39
     40int isInt(const char* INT, int defaultValue)
    2841{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
     42  char* endPtr = NULL;
     43  int result = strtol(INT, &endPtr, 10);
    3044
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
     45  if ( endPtr >= INT && endPtr < INT + strlen(INT))
     46    return defaultValue;
     47  else
     48    return result;
     49}
    3550
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
     51float isFloat(const char* FLOAT, float defaultValue)
     52{
     53  char* endPtr = NULL;
     54  double result = strtod(FLOAT, &endPtr);
     55
     56  if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))
     57    return defaultValue;
     58  else
     59    return result;
    4160}
    4261
    4362
    44 /**
    45  * standard deconstructor
    46 */
    47 ProtoClass::~ProtoClass ()
     63const char* isString(const char* STRING, const char* defaultValue)
    4864{
    49   // delete what has to be deleted here
     65  if (STRING != NULL)
     66    return STRING;
     67  else
     68    return defaultValue;
    5069}
  • trunk/src/lib/util/helper_functions.h

    r5114 r5141  
    11/*!
    2  * @file proto_class.h
    3  * @brief Definition of ...
     2 * @file helper_functions.h
     3 * @brief Definition of some minor helper-functions
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
    8 
    9 #include "base_object.h"
     6#ifndef _HELPER_FUNCTIONS_H
     7#define _HELPER_FUNCTIONS_H
    108
    119// FORWARD DECLARATION
    1210
     11/***********************
     12*** HELPER FUNCTIONS ***
     13***********************/
     14bool          isBool(const char* BOOL, bool defaultValue);
     15int           isInt(const char* INT, int defaultValue);
     16float         isFloat(const char* FLOAT, float defaultValue);
     17const char*   isString(const char* STRING, const char* defaultValue);
    1318
    14 
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
    17 
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
    21 
    22 
    23  private:
    24 
    25 };
    26 
    27 #endif /* _PROTO_CLASS_H */
     19#endif /* _HELPER_FUNCTIONS_H */
  • trunk/src/util/loading/load_param.cc

    r5115 r5141  
    112112  }
    113113}
    114 
    115 /**
    116  * checks if the input was a Bool
    117  * @param BOOL a String that holds a bool: must be one of those: 1,0,true,false,TRUE,FALSE
    118  * @param defaultValue a default value that is set, if BOOL is corrupt
    119  * @return returns the bool, if BOOL was correct otherwise defaultValue
    120  */
    121 bool isBool(const char* BOOL, bool defaultValue)
    122 {
    123   if(!strcmp(BOOL, "1") || !strcmp( BOOL,"true") || !strcmp(BOOL,"TRUE"))
    124     return true;
    125   else if (!strcmp(BOOL, "0") || !strcmp( BOOL,"false") || !strcmp(BOOL,"FALSE"))
    126     return false;
    127   else
    128     return defaultValue;
    129 
    130 }
    131 
    132 int isInt(const char* INT, int defaultValue)
    133 {
    134   char* endPtr = NULL;
    135   int result = strtol(INT, &endPtr, 10);
    136 
    137   if ( endPtr >= INT && endPtr < INT + strlen(INT))
    138     return defaultValue;
    139   else
    140     return result;
    141 }
    142 
    143 float isFloat(const char* FLOAT, float defaultValue)
    144 {
    145   char* endPtr = NULL;
    146   double result = strtod(FLOAT, &endPtr);
    147 
    148   if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))
    149     return defaultValue;
    150   else
    151     return result;
    152 }
    153 
    154 const Vector& isVector(const char* VECTOR, const Vector& defaultValue)
    155 {
    156 
    157 
    158 }
    159 
    160 const char* isString(const char* STRING, const char* defaultValue)
    161 {
    162   if (STRING != NULL)
    163     return STRING;
    164   else
    165     return defaultValue;
    166 }
    167 
    168114
    169115/**
  • trunk/src/util/loading/load_param.h

    r5137 r5141  
    2828#include "substring.h"
    2929#include "tinyxml.h"
     30#include "helper_functions.h"
    3031
    3132// Forward Declaration //
     
    216217        PRINTF(4)("Not loaded parameter %s of %s\n", paramName, pt2Object->getClassName()); \
    217218}
    218 
    219 
    220 /***********************
    221 *** HELPER FUNCTIONS ***
    222 ***********************/
    223 bool          isBool(const char* BOOL, bool defaultValue);
    224 int           isInt(const char* INT, int defaultValue);
    225 float         isFloat(const char* FLOAT, float defaultValue);
    226 //const Vector& isVector(const char* VECTOR, const Vector& defaultValue);
    227 const char*   isString(const char* STRING, const char* defaultValue);
    228 
    229 //TiXmlEmlemnt* isXmlElem(const)
    230 
    231219
    232220/************************
  • trunk/src/util/shell.cc

    r5137 r5141  
    494494  if (event.bPressed)
    495495  {
    496     PRINTF(4)("Shell received command %s\n", SDLKToKeyname(event.type));
     496    PRINTF(5)("Shell received command %s\n", SDLKToKeyname(event.type));
    497497    if (event.type == SDLK_BACKQUOTE)
    498498    {
  • trunk/src/util/shell.h

    r5130 r5141  
    1616// FORWARD DECLARATION
    1717class Text;
     18class ShellCommandBase;
    1819template<class T> class tList;
    1920template<class T> class tIterator;
     
    8586    const tList<const char>* createCompleteList(const tList<const char>* inputList, const char* classNameBegin);
    8687    const tList<const char>* createCompleteList(const tList<BaseObject>* inputList, const char* classNameBegin);
     88    const tList<const char>* createCompleteList(const tList<ShellCommandBase>* inputList, const char* classNameBegin);
    8789
    8890    // helpers //
  • trunk/src/util/shell_command.cc

    r5140 r5141  
    3030ShellCommandBase::ShellCommandBase(const char* commandName, ClassID classID, unsigned int paramCount, ...)
    3131{
     32  this->setClassID(CL_SHELL_COMMAND, "ShellCommand");
     33  this->setName(commandName);
     34
    3235  va_list parameters;
    3336  va_start(parameters, paramCount);
    3437
    3538  this->classID = classID;
     39  this->className = ClassList::IDToString(classID);
     40
    3641  if (classID & CL_MASK_SINGLETON == CL_MASK_SINGLETON)
    3742    this->isSingleton = true;
    3843  else
    3944    this->isSingleton = false;
    40 
    41   this->commandName = new char[strlen(commandName)+1];
    42   strcpy(this->commandName, commandName);
    4345
    4446  // handling parameters, and storing them:
     
    5557ShellCommandBase::~ShellCommandBase()
    5658{
    57   delete[] this->commandName;
    5859  delete[] this->parameters;
    5960}
     
    7879  while(elem != NULL)
    7980  {
    80     if (classID == elem->classID && !strcmp(commandName, elem->commandName))
     81    if (classID == elem->classID && !strcmp(commandName, elem->getName()))
    8182    {
    8283      PRINTF(2)("Command already registered\n");
     
    104105  while(elem != NULL)
    105106  {
    106     printf("%s\n", elem->commandName);
    107     if (!strncmp(executionString, elem->commandName, strlen(elem->commandName)))
     107    printf("%s\n", elem->getName());
     108    if (!strncmp(executionString, elem->getName(), strlen(elem->getName())))
    108109    {
    109110      elem->executeCommand(commandEnd);
     
    116117  return true;
    117118}
    118 
  • trunk/src/util/shell_command.h

    r5140 r5141  
    88
    99#include "base_object.h"
     10
     11#include "helper_functions.h"
    1012
    1113#include <stdarg.h>
     
    4446
    4547
     48
    4649////////////////
    4750// BASE CLASS //
     
    5356    static bool execute (const char* executionString);
    5457
    55     virtual void executeCommand (const char* parameters) = NULL;
     58    static const tList<ShellCommandBase>* getCommandList() { return ShellCommandBase::commandList; };
     59
    5660
    5761  protected:
     
    6064
    6165    static bool isRegistered(const char* commandName, ClassID classID, unsigned int paramCount, ...);
     66
     67  private:
     68    virtual void executeCommand (const char* parameters) = NULL;
    6269
    6370  protected:
     
    6875
    6976  private:
    70     char*                            commandName;         //!< The name of the Command when executed
    71     long                             classID;             //!< The ID of the Class asociated to this Command
     77    long                             classID;             //!< The ID of the Class associated to this Command
     78    const char*                      className;           //!< The Name of the Class associated to this Command
    7279
    7380    // STATIC MEMBERS
     
    133140#define FUNCTOR_LIST(x) ShellCommand ## x
    134141//#include "functor_list.h"
    135 //ShellCommand2(l_INT, l_INT);
     142//FUNCTOR_LIST(2)(l_INT, l_INT);
    136143#undef FUNCTOR_LIST
    137144
    138   private:
    139 //    T*                   objectPointer;       //!< The pointer to the object to apply this function to (NULL if classID == CL_NULL )
    140145};
    141146
Note: See TracChangeset for help on using the changeset viewer.