Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/executor/executor_substring.h @ 10642

Last change on this file since 10642 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 4.0 KB
Line 
1/*!
2 * @file executor_substring.h
3 * Definition of a Generic Executor
4 */
5
6/*
7   orxonox - the future of 3D-vertical-scrollers
8
9   Copyright (C) 2004 orx
10
11   This program is free software; you can redistribute it and/or modify
12   it under the terms of the GNU General Public License as published by
13   the Free Software Foundation; either version 2, or (at your option)
14   any later version.
15
16### File Specific:
17   main-programmer: Benjamin Grauer
18   co-programmer: ...
19*/
20
21
22
23#ifndef __EXECUTOR_SUBSTRING_H_
24#define __EXECUTOR_SUBSTRING_H_
25
26
27#include "executor_generic.h"
28#include "substring.h"
29#ifdef FUNCTOR_CALL_TYPE
30 #undef FUNCTOR_CALL_TYPE
31#endif
32//! Use SubString as the FUNCTION_CALL_TYPE so that we can easily extend the Engine.
33#define FUNCTOR_CALL_TYPE const SubString
34
35/**
36 * @brief converts an input string into a value, if no value was converted, uses defaultValue.
37 * @param input the input as a String.
38 * @param defaultValue the Default Value set, if the input could not be converted into type.
39 * @returns either the converted value or defaultValue.
40 */
41template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; };
42template<> bool fromString<bool>(const std::string& input, bool defaultValue);
43template<> int fromString<int>(const std::string& input, int defaultValue);
44template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue);
45template<> float fromString<float>(const std::string& input, float defaultValue);
46template<> char fromString<char>(const std::string& input, char defaultValue);
47template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue);
48
49/**
50 * @brief converts to any type from a MultiType
51 * @param multi the MultiType to convert.
52 * @returns the converted Value.
53 */
54template<typename type> type fromMulti(const MultiType& multi) { /* return defaultValue; */ };
55template<> bool fromMulti<bool>(const MultiType& multi);
56template<> int fromMulti<int>(const MultiType& multi);
57template<> unsigned int fromMulti<unsigned int>(const MultiType& multi);
58template<> float fromMulti<float>(const MultiType& multi);
59template<> char fromMulti<char>(const MultiType& multi);
60template<> const std::string& fromMulti<const std::string&>(const MultiType& multi);
61
62/**
63 * @brief retrieves a default value from an array of default values, at possition i.
64 * @param defaultValues the Array of default values.
65 * @param i the index.
66 * @returns the Default Value at Position i
67 */
68template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; };
69template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i);
70template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i);
71template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i);
72template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i);
73template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i);
74template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i);
75
76
77/**
78 * @brief to remove writing errors, this function is Used.
79 * @param sub The SubString to use
80 * @param default The default Values.
81 */
82template<> class ExecutorEvaluater <const SubString>
83{
84public:
85  /** @brief Executes the Evaluater
86   * @param CallValue the Value that should be converted
87   * @param defaults the default Values.
88   */
89  template <typename ToType, int index>
90  static ToType getValue(const SubString& CallValue, const MultiType* const defaults)
91  {
92    return (CallValue.size() > index) ?
93           fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) :
94           fromMulti<ToType>(defaults[index]);
95  }
96  /** @returns the default Value of a SubString, namely NullSubString or SubString() */
97  static const SubString& defaultValue() { return SubString::NullSubString; };
98};
99
100#endif /* __EXECUTOR_SUBSTRING_H_ */
Note: See TracBrowser for help on using the repository browser.