Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: one Parameter safe now

File size: 1.6 KB
RevLine 
[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]21using 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 */
29bool 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]40int 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]51float 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
63const 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}
Note: See TracBrowser for help on using the repository browser.