| 1 | /* | 
|---|
| 2 |    orxonox - the future of 3D-vertical-scrollers | 
|---|
| 3 |  | 
|---|
| 4 |    Copyright (C) 2004 orx | 
|---|
| 5 |  | 
|---|
| 6 |    This program is free software; you can redistribute it and/or modify | 
|---|
| 7 |    it under the terms of the GNU General Public License as published by | 
|---|
| 8 |    the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 9 |    any later version. | 
|---|
| 10 |  | 
|---|
| 11 |    ### File Specific: | 
|---|
| 12 |    main-programmer: Benjamin Grauer | 
|---|
| 13 |    co-programmer: ... | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ | 
|---|
| 17 |  | 
|---|
| 18 | #include "helper_functions.h" | 
|---|
| 19 | #include "stdlibincl.h" | 
|---|
| 20 |  | 
|---|
| 21 | using namespace std; | 
|---|
| 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; | 
|---|
| 37 |  | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | int isInt(const char* INT, int defaultValue) | 
|---|
| 41 | { | 
|---|
| 42 |   char* endPtr = NULL; | 
|---|
| 43 |   int result = strtol(INT, &endPtr, 10); | 
|---|
| 44 |  | 
|---|
| 45 |   if ( endPtr >= INT && endPtr < INT + strnlen(INT, 10)) | 
|---|
| 46 |     return defaultValue; | 
|---|
| 47 |   else | 
|---|
| 48 |     return result; | 
|---|
| 49 | } | 
|---|
| 50 |  | 
|---|
| 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; | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 |  | 
|---|
| 63 | const char* isString(const char* STRING, const char* defaultValue) | 
|---|
| 64 | { | 
|---|
| 65 |   if (STRING != NULL) | 
|---|
| 66 |     return STRING; | 
|---|
| 67 |   else | 
|---|
| 68 |     return defaultValue; | 
|---|
| 69 | } | 
|---|