Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: one Parameter safe now

File size: 1.6 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(!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
40int 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
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;
60}
61
62
63const char* isString(const char* STRING, const char* defaultValue)
64{
65  if (STRING != NULL)
66    return STRING;
67  else
68    return defaultValue;
69}
Note: See TracBrowser for help on using the repository browser.