Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: inition is our motto, so now the debug function of the ClassList really looks greate and is easy to use.

File size: 2.5 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/**
[5331]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(case-insensitive)
[5141]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{
[5329]31  if (BOOL == NULL)
32    return defaultValue;
[5331]33  if(!strcmp(BOOL, "1") || !strcasecmp( BOOL, "true") )
[5141]34    return true;
[5331]35  else if (!strcmp(BOOL, "0") || !strcasecmp( BOOL, "false"))
[5141]36    return false;
37  else
38    return defaultValue;
[4320]39
[5141]40}
[4320]41
[5331]42
43/**
44 * checks if the input was a int
45 * @param INT a String that holds an int.
46 * @param defaultValue a default value that is set, if INT is corrupt
47 * @return returns the contained int, if INT was correct otherwise defaultValue
48 */
[5141]49int isInt(const char* INT, int defaultValue)
50{
[5329]51  if (INT == NULL)
52    return defaultValue;
[5141]53  char* endPtr = NULL;
[5329]54
[5141]55  int result = strtol(INT, &endPtr, 10);
56
[5270]57  if ( endPtr >= INT && endPtr < INT + strlen(INT))
[5141]58    return defaultValue;
59  else
60    return result;
[3365]61}
[1853]62
[5331]63
64/**
65 * checks if the input was a float
66 * @param FLOAT a String that holds an float.
67 * @param defaultValue a default value that is set, if FLOAT is corrupt
68 * @return returns the contained float, if FLOAT was correct otherwise defaultValue
69 */
[5141]70float isFloat(const char* FLOAT, float defaultValue)
71{
[5329]72  if (FLOAT == NULL)
73    return defaultValue;
[5141]74  char* endPtr = NULL;
75  double result = strtod(FLOAT, &endPtr);
[1853]76
[5141]77  if ( endPtr >= FLOAT && endPtr < FLOAT + strlen(FLOAT))
78    return defaultValue;
79  else
80    return result;
81}
82
83
[5331]84/**
85 * checks if the input was a string
86 * @param STING a String(char-array) that holds an string.
87 * @param defaultValue a default value that is set, if STRING is corrupt
88 * @return returns the contained string (char-array), if STRING was correct otherwise defaultValue
89 */
[5141]90const char* isString(const char* STRING, const char* defaultValue)
[3543]91{
[5207]92  if (STRING != NULL && strlen(STRING) > 0)
[5141]93    return STRING;
94  else
95    return defaultValue;
[3543]96}
Note: See TracBrowser for help on using the repository browser.