Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

completely documented Executors

File size: 4.0 KB
RevLine 
[4838]1/*!
[9748]2 * @file executor_substring.h
[9737]3 * Definition of a Generic Executor
[5391]4 */
[1853]5
[7716]6/*
7   orxonox - the future of 3D-vertical-scrollers
[1853]8
[7716]9   Copyright (C) 2004 orx
[1853]10
[7716]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.
[5141]15
[7716]16### File Specific:
17   main-programmer: Benjamin Grauer
18   co-programmer: ...
19*/
[5652]20
[5328]21
[9740]22
[9742]23#ifndef __EXECUTOR_SUBSTRING_H_
24#define __EXECUTOR_SUBSTRING_H_
[5641]25
[9740]26
[9742]27#include "executor_generic.h"
[9728]28#include "substring.h"
[9745]29#ifdef FUNCTOR_CALL_TYPE
30 #undef FUNCTOR_CALL_TYPE
31#endif
[9748]32//! Use SubString as the FUNCTION_CALL_TYPE so that we can easily extend the Engine.
[9745]33#define FUNCTOR_CALL_TYPE const SubString
[5641]34
[9748]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 */
[8035]41template<typename type> type fromString(const std::string& input, type defaultValue) { return defaultValue; };
[7721]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);
[5641]48
[9748]49/**
50 * @brief converts to any type from a MultiType
51 * @param multi the MultiType to convert.
52 * @returns the converted Value.
53 */
[8035]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
[9748]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 */
[7716]68template<typename type> type getDefault(const MultiType* const defaultValues, unsigned int i) { return (type)0; };
[7721]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);
[5161]75
[9730]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 */
[9736]82template<> class ExecutorEvaluater <const SubString>
[9730]83{
[9731]84public:
[9736]85  /** @brief Executes the Evaluater
[9735]86   * @param CallValue the Value that should be converted
87   * @param defaults the default Values.
88   */
[9736]89  template <typename ToType, int index>
[9747]90  static ToType getValue(const SubString& CallValue, const MultiType* const defaults)
[9731]91  {
[9732]92    return (CallValue.size() > index) ?
93           fromString<ToType>(CallValue[index], getDefault<ToType>(defaults, index)) :
[9731]94           fromMulti<ToType>(defaults[index]);
95  }
[9748]96  /** @returns the default Value of a SubString, namely NullSubString or SubString() */
[9736]97  static const SubString& defaultValue() { return SubString::NullSubString; };
[9730]98};
99
[9742]100#endif /* __EXECUTOR_SUBSTRING_H_ */
Note: See TracBrowser for help on using the repository browser.