[4744] | 1 | /* |
---|
[1853] | 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. |
---|
[1855] | 10 | |
---|
| 11 | ### File Specific: |
---|
[5141] | 12 | main-programmer: Benjamin Grauer |
---|
[1855] | 13 | co-programmer: ... |
---|
[1853] | 14 | */ |
---|
| 15 | |
---|
[3955] | 16 | //#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_ |
---|
[1853] | 17 | |
---|
[5141] | 18 | #include "helper_functions.h" |
---|
| 19 | #include "stdlibincl.h" |
---|
[1853] | 20 | |
---|
[1856] | 21 | using namespace std; |
---|
[1853] | 22 | |
---|
[3245] | 23 | /** |
---|
[5141] | 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) |
---|
[3365] | 30 | { |
---|
[5141] | 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; |
---|
[4320] | 37 | |
---|
[5141] | 38 | } |
---|
[4320] | 39 | |
---|
[5141] | 40 | int isInt(const char* INT, int defaultValue) |
---|
| 41 | { |
---|
| 42 | char* endPtr = NULL; |
---|
| 43 | int result = strtol(INT, &endPtr, 10); |
---|
| 44 | |
---|
[5148] | 45 | if ( endPtr >= INT && endPtr < INT + strnlen(INT, 10)) |
---|
[5141] | 46 | return defaultValue; |
---|
| 47 | else |
---|
| 48 | return result; |
---|
[3365] | 49 | } |
---|
[1853] | 50 | |
---|
[5141] | 51 | float isFloat(const char* FLOAT, float defaultValue) |
---|
| 52 | { |
---|
| 53 | char* endPtr = NULL; |
---|
| 54 | double result = strtod(FLOAT, &endPtr); |
---|
[1853] | 55 | |
---|
[5141] | 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) |
---|
[3543] | 64 | { |
---|
[5141] | 65 | if (STRING != NULL) |
---|
| 66 | return STRING; |
---|
| 67 | else |
---|
| 68 | return defaultValue; |
---|
[3543] | 69 | } |
---|