Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/helper_functions.cc @ 5329

Last change on this file since 5329 was 5329, checked in by bensch, 19 years ago

orxonox/trunk: executing static commands work

File size: 1.8 KB
Line 
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
21using 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 */
29bool isBool(const char* BOOL, bool defaultValue)
30{
31  if (BOOL == NULL)
32    return defaultValue;
33  if(!strcmp(BOOL, "1") || !strcmp( BOOL,"true") || !strcmp(BOOL,"TRUE"))
34    return true;
35  else if (!strcmp(BOOL, "0") || !strcmp( BOOL,"false") || !strcmp(BOOL,"FALSE"))
36    return false;
37  else
38    return defaultValue;
39
40}
41
42int isInt(const char* INT, int defaultValue)
43{
44  if (INT == NULL)
45    return defaultValue;
46  char* endPtr = NULL;
47
48  int result = strtol(INT, &endPtr, 10);
49
50  if ( endPtr >= INT && endPtr < INT + strlen(INT))
51    return defaultValue;
52  else
53    return result;
54}
55
56float isFloat(const char* FLOAT, float defaultValue)
57{
58  if (FLOAT == NULL)
59    return defaultValue;
60  char* endPtr = NULL;
61  double result = strtod(FLOAT, &endPtr);
62
63  if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))
64    return defaultValue;
65  else
66    return result;
67}
68
69
70const char* isString(const char* STRING, const char* defaultValue)
71{
72  if (STRING != NULL && strlen(STRING) > 0)
73    return STRING;
74  else
75    return defaultValue;
76}
Note: See TracBrowser for help on using the repository browser.