Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/util/executor/executor_substring.h @ 9747

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

orxonox/new_class_id: Indexing works again for all the Scripts.

File size: 3.2 KB
Line 
1/*!
2 * @file executor_generic.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#define FUNCTOR_CALL_TYPE const SubString
33
34template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; };
35template<> bool fromString<bool>(const std::string& input, bool defaultValue);
36template<> int fromString<int>(const std::string& input, int defaultValue);
37template<> unsigned int fromString<unsigned int>(const std::string& input, unsigned int defaultValue);
38template<> float fromString<float>(const std::string& input, float defaultValue);
39template<> char fromString<char>(const std::string& input, char defaultValue);
40template<> const std::string& fromString<const std::string&>(const std::string& input, const std::string& defaultValue);
41
42template<typename type> type fromMulti(const MultiType& multi) { /* return defaultValue; */ };
43template<> bool fromMulti<bool>(const MultiType& multi);
44template<> int fromMulti<int>(const MultiType& multi);
45template<> unsigned int fromMulti<unsigned int>(const MultiType& multi);
46template<> float fromMulti<float>(const MultiType& multi);
47template<> char fromMulti<char>(const MultiType& multi);
48template<> const std::string& fromMulti<const std::string&>(const MultiType& multi);
49
50
51template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; };
52template<> bool getDefault<bool>(const MultiType* const defaultValues, unsigned int i);
53template<> int getDefault<int>(const MultiType* const defaultValues, unsigned int i);
54template<> unsigned int getDefault<unsigned int>(const MultiType* const defaultValues, unsigned int i);
55template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i);
56template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i);
57template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i);
58
59
60/**
61 * @brief to remove writing errors, this function is Used.
62 * @param sub The SubString to use
63 * @param default The default Values.
64 */
65template<> class ExecutorEvaluater <const SubString>
66{
67public:
68  /** @brief Executes the Evaluater
69   * @param CallValue the Value that should be converted
70   * @param defaults the default Values.
71   */
72  template <typename ToType, int index>
73  static ToType getValue(const SubString& CallValue, const MultiType* const defaults)
74  {
75    return (CallValue.size() > index) ?
76           fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) :
77           fromMulti<ToType>(defaults[index]);
78  }
79  static const SubString& defaultValue() { return SubString::NullSubString; };
80};
81
82#endif /* __EXECUTOR_SUBSTRING_H_ */
Note: See TracBrowser for help on using the repository browser.