Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5141 in orxonox.OLD for trunk/src/lib/util


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/lib/util
Files:
2 copied

Legend:

Unmodified
Added
Removed
  • 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 */
Note: See TracChangeset for help on using the changeset viewer.