Changeset 5141 in orxonox.OLD for trunk/src/lib/util
- Timestamp:
- Aug 26, 2005, 4:04:53 PM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/helper_functions.cc
r5114 r5141 10 10 11 11 ### File Specific: 12 main-programmer: ...12 main-programmer: Benjamin Grauer 13 13 co-programmer: ... 14 14 */ … … 16 16 //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ 17 17 18 #include "proto_class.h" 18 #include "helper_functions.h" 19 #include "stdlibincl.h" 19 20 20 21 using namespace std; 21 22 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 */ 29 bool 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; 22 37 23 /** 24 * standard constructor 25 * @todo this constructor is not jet implemented - do it 26 */ 27 ProtoClass::ProtoClass () 38 } 39 40 int isInt(const char* INT, int defaultValue) 28 41 { 29 this->setClassID(CL_PROTO_ID, "ProtoClass"); 42 char* endPtr = NULL; 43 int result = strtol(INT, &endPtr, 10); 30 44 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 } 35 50 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 */ 51 float 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; 41 60 } 42 61 43 62 44 /** 45 * standard deconstructor 46 */ 47 ProtoClass::~ProtoClass () 63 const char* isString(const char* STRING, const char* defaultValue) 48 64 { 49 // delete what has to be deleted here 65 if (STRING != NULL) 66 return STRING; 67 else 68 return defaultValue; 50 69 } -
trunk/src/lib/util/helper_functions.h
r5114 r5141 1 1 /*! 2 * @file proto_class.h3 * @brief Definition of ...2 * @file helper_functions.h 3 * @brief Definition of some minor helper-functions 4 4 */ 5 5 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 10 8 11 9 // FORWARD DECLARATION 12 10 11 /*********************** 12 *** HELPER FUNCTIONS *** 13 ***********************/ 14 bool isBool(const char* BOOL, bool defaultValue); 15 int isInt(const char* INT, int defaultValue); 16 float isFloat(const char* FLOAT, float defaultValue); 17 const char* isString(const char* STRING, const char* defaultValue); 13 18 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.