Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9730 in orxonox.OLD for branches/new_class_id/src


Ignore:
Timestamp:
Sep 15, 2006, 12:09:12 PM (18 years ago)
Author:
bensch
Message:

cleaner executor with evaluate function, that will be made an Object Soon.

Location:
branches/new_class_id/src/lib
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/new_class_id/src/lib/lang/Makefile.am

    r9717 r9730  
    11MAINSRCDIR=../..
    22include $(MAINSRCDIR)/defs/include_paths.am
    3 
    4 LIB_PREFIX=$(MAINSRCDIR)/lib
    5 include $(MAINSRCDIR)/lib/BuildLibs.am
    63
    74noinst_LIBRARIES = libORXlang.a
  • branches/new_class_id/src/lib/lang/base_object.cc

    r9727 r9730  
    1 
    2 
    31/*
    42   orxonox - the future of 3D-vertical-scrollers
  • branches/new_class_id/src/lib/util/executor/executor.cc

    r9728 r9730  
    6161      break;
    6262    }
     63    else
     64      this->defaultValue[i].storeString();
    6365  }
    6466}
     
    106108    {
    107109      this->defaultValue[i].setValueOf(*value[i]);
     110      this->defaultValue[i].storeString();
    108111    }
    109112  }
  • branches/new_class_id/src/lib/util/executor/executor.h

    r9728 r9730  
    1515//! an enumerator for the definition of the Type.
    1616typedef enum {
    17   Executor_Objective         = 1,
    18   Executor_Static            = 2,
     17  Executor_Objective,
     18  Executor_Static,
    1919} Executor_Type;
    2020
     
    5151  inline MultiType& getDefaultValue(unsigned int i) { return defaultValue[i]; };
    5252
    53   // EXECUTE
    54   /** executes a Command. @param objec the Object, @param count how many values, @param values the Values */
    55   //     virtual void operator()(BaseObject* object, int& count, void* values) const = 0;
    56   /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */
    57   //     virtual void operator()(BaseObject* object, const SubString& sub = SubString()) const = 0;
    58 
    5953  // RETRIEVE INFORMATION
    6054  /** @returns the Type of this Function (either static or objective) */
    61   inline long getType() const { return this->functorType; };
     55  inline Executor_Type getType() const { return this->functorType; };
     56
    6257  /** @returns the Count of Parameters this Executor takes */
    6358  inline unsigned int getParamCount() const { return this->paramCount; };
     
    8479
    8580protected:
    86   short                       functorType;      //!< The type of Function we've got (either static or objective).
     81  Executor_Type               functorType;      //!< The type of Function we've got (either static or objective).
    8782  unsigned int                paramCount;       //!< the count of parameters.
    8883  MultiType                   defaultValue[7];  //!< Default Values.
    8984
    90   bool                        bRetVal;          //!< True if the Executor has a return Value.
     85  const bool                  bRetVal;          //!< True if the Executor has a return Value.
    9186};
    9287
  • branches/new_class_id/src/lib/util/executor/executor_functional.cc

    r9728 r9730  
    1515
    1616#include "executor_functional.h"
    17 std::string ExecutorFunctional_returningString_from[7];
    18 
    1917
    2018template<> bool fromString<bool>(const std::string& input, bool defaultValue) { return isBool(input, defaultValue); };
     
    3937template<> float getDefault<float>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getFloat(); };
    4038template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getChar(); };
    41 template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return ExecutorFunctional_returningString_from[i] = defaultValues[i].getString(); };
     39template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i) { return defaultValues[i].getStoredString(); };
    4240
    4341
  • branches/new_class_id/src/lib/util/executor/executor_functional.h

    r9728 r9730  
    5151template<> char getDefault<char>(const MultiType* const defaultValues, unsigned int i);
    5252template<> const std::string& getDefault<const std::string&>(const MultiType* const defaultValues, unsigned int i);
     53
     54
     55/**
     56 * @brief to remove writing errors, this function is Used.
     57 * @param sub The SubString to use
     58 * @param default The default Values.
     59 */
     60template<typename type, int index> type Evaluate(const SubString& sub, const MultiType* const defaults)
     61{
     62  return (sub.size() > index) ?
     63      fromString<type>(sub[index], getDefault<type>(defaults, index)) :
     64      fromMulti<type>(defaults[index]);
     65};
     66
    5367
    5468#endif /* __EXECUTOR_FUNCTIONAL_H_ */
     
    8094 #endif
    8195
    82   #ifdef __EXECUTOR_FUNCTIONAL_STATIC_INCLUDED
     96#ifdef __EXECUTOR_FUNCTIONAL_STATIC_INCLUDED
    8397   #define __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS
    8498  #else
     
    103117
    104118#ifndef __EXECUTOR_FUNCTIONAL_NOT_INCLUDE_THIS
     119
    105120///////////
    106121//// 0 ////
     
    177192  {
    178193    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    179       (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])));
     194      Evaluate<type0, 0>(sub, this->defaultValue));
    180195  };
    181196
     
    220235  {
    221236    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    222       (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),
    223       (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])));
     237      Evaluate<type0, 0>(sub, this->defaultValue),
     238      Evaluate<type1, 1>(sub, this->defaultValue));
    224239  };
    225240
     
    265280  {
    266281    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    267       (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),
    268       (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])),
    269       (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])));
     282      Evaluate<type0, 0>(sub, this->defaultValue),
     283      Evaluate<type1, 1>(sub, this->defaultValue),
     284      Evaluate<type2, 2>(sub, this->defaultValue));
    270285  };
    271286
     
    312327  {
    313328    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    314       (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),
    315       (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])),
    316       (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])),
    317       (sub.size() > 3) ? fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)) : (fromMulti<type3>(this->defaultValue[3])));
     329      Evaluate<type0, 0>(sub, this->defaultValue),
     330      Evaluate<type1, 1>(sub, this->defaultValue),
     331      Evaluate<type2, 2>(sub, this->defaultValue),
     332      Evaluate<type3, 3>(sub, this->defaultValue));
    318333  };
    319334
     
    360375  {
    361376    (__EXECUTOR_FUNCTIONAL_FUNCTION_EXEC)(
    362       (sub.size() > 0) ? fromString<type0>(sub[0], getDefault<type0>(this->defaultValue, 0)) : (fromMulti<type0>(this->defaultValue[0])),
    363       (sub.size() > 1) ? fromString<type1>(sub[1], getDefault<type1>(this->defaultValue, 1)) : (fromMulti<type1>(this->defaultValue[1])),
    364       (sub.size() > 2) ? fromString<type2>(sub[2], getDefault<type2>(this->defaultValue, 2)) : (fromMulti<type2>(this->defaultValue[2])),
    365       (sub.size() > 3) ? fromString<type3>(sub[3], getDefault<type3>(this->defaultValue, 3)) : (fromMulti<type3>(this->defaultValue[3])),
    366       (sub.size() > 4) ? fromString<type4>(sub[4], getDefault<type4>(this->defaultValue, 4)) : (fromMulti<type4>(this->defaultValue[4])));
     377      Evaluate<type0, 0>(sub, this->defaultValue),
     378      Evaluate<type1, 1>(sub, this->defaultValue),
     379      Evaluate<type2, 2>(sub, this->defaultValue),
     380      Evaluate<type3, 3>(sub, this->defaultValue),
     381      Evaluate<type4, 4>(sub, this->defaultValue));
    367382  };
    368383
  • branches/new_class_id/src/lib/util/multi_type.cc

    r9406 r9730  
    3333  {
    3434    default:
    35       this->value.Float = 0.0f;
    36       break;
     35    this->value.Float = 0.0f;
     36    break;
    3737    case MT_BOOL:
    38       this->value.Bool = false;
    39       break;
     38    this->value.Bool = false;
     39    break;
    4040    case MT_INT:
    41       this->value.Int = 0;
    42       break;
     41    this->value.Int = 0;
     42    break;
    4343    case MT_FLOAT:
    44       this->value.Float = 0.0f;
    45       break;
     44    this->value.Float = 0.0f;
     45    break;
    4646    case MT_CHAR:
    47       this->value.Char = '\0';
    48       break;
     47    this->value.Char = '\0';
     48    break;
    4949    case MT_STRING:
    50       this->storedString = "";
    51       break;
     50    this->storedString = "";
     51    break;
    5252  }
    5353}
     
    142142  {
    143143    case MT_NULL:
    144       return true;
     144    return true;
    145145    case MT_BOOL:
    146       return (this->value.Bool == mt.value.Bool);
     146    return (this->value.Bool == mt.value.Bool);
    147147    case MT_INT:
    148       return (this->value.Int == mt.value.Int);
     148    return (this->value.Int == mt.value.Int);
    149149    case MT_CHAR:
    150       return (this->value.Char == mt.value.Char);
     150    return (this->value.Char == mt.value.Char);
    151151    case MT_FLOAT:
    152       return (this->value.Float == mt.value.Float);
     152    return (this->value.Float == mt.value.Float);
    153153    case MT_STRING:
    154       return (this->storedString == mt.storedString);
     154    return (this->storedString == mt.storedString);
    155155    default:
    156       return false;
     156    return false;
    157157  }
    158158}
     
    171171  {
    172172    case MT_BOOL:
    173       this->setBool(this->getBool());
    174       break;
     173    this->setBool(this->getBool());
     174    break;
    175175    case MT_INT:
    176       this->setInt(this->getInt());
    177       break;
     176    this->setInt(this->getInt());
     177    break;
    178178    case MT_FLOAT:
    179       this->setFloat(this->getFloat());
    180       break;
     179    this->setFloat(this->getFloat());
     180    break;
    181181    case MT_CHAR:
    182       this->setChar(this->getChar());
    183       break;
     182    this->setChar(this->getChar());
     183    break;
    184184    case MT_STRING:
    185       this->setString(this->getString());
    186       break;
     185    this->setString(this->getString());
     186    break;
    187187    default:
    188       this->type = type;
     188    this->type = type;
    189189  }
    190190}
     
    257257}
    258258
     259/**
     260 * @brief stores any value to the string.
     261 * @note this Value can be grabbed by using the getStoredString function.
     262 */
     263void MultiType::storeString()
     264{
     265  if (!(this->type & MT_STRING))
     266    this->storedString = this->getString();
     267}
    259268
    260269/**************************
     
    381390 * @brief returns a Constant string (actually this is slower than getString()
    382391 * @returns a constant string of the stored version's one.
    383  * @note this  could lead to a inconsistency of data
     392 * @note this  could lead to a inconsistency of data AND IS HIGHLY NON_THREAD_SAFE!
     393 * PLEASE THINK ABOUT USING THE getStoredString function in conjunction with storeString().
    384394 */
    385395const std::string& MultiType::getConstString() const
    386396{
    387 
    388397  MultiType::constString = this->getString();
    389398  return MultiType::constString;
    390399}
    391400
     401/**
     402 * @brief returns the currently stored string.
     403 * @returns the Stored string.
     404 * @note Storing a string works as follows: \\
     405 * MultiType a(3);  // Creates a MultiType of Type int with value 3 \\
     406 * a.storeString(); // Stores the String in the internal structure. \\
     407 * std::string name = a.getStoredString();
     408 *
     409 * This would be the same as
     410 * name = a.getString();
     411 * but with much more const'ness.
     412 */
     413const std::string& MultiType::getStoredString() const
     414{
     415  MultiType::constString = this->getString();
     416  return MultiType::constString;
     417}
    392418
    393419/**
     
    433459  {
    434460    case MT_BOOL:
    435       this->setBool(false);
    436       break;
     461    this->setBool(false);
     462    break;
    437463    case MT_INT:
    438       this->setInt(0);
    439       break;
     464    this->setInt(0);
     465    break;
    440466    case MT_FLOAT:
    441       this->setFloat(0.0f);
    442       break;
     467    this->setFloat(0.0f);
     468    break;
    443469    case MT_CHAR:
    444       this->setChar('\0');
    445       break;
     470    this->setChar('\0');
     471    break;
    446472    case MT_STRING:
    447       this->setString("");
    448       break;
     473    this->setString("");
     474    break;
    449475    default:
    450476#ifdef DEBUG
    451       PRINTF(2)("Unknown Type not reseting\n");
     477    PRINTF(2)("Unknown Type not reseting\n");
    452478#endif
    453       break;
     479    break;
    454480  }
    455481}
     
    465491  {
    466492    case MT_BOOL:
    467       return MultiType::typeNames[1];
     493    return MultiType::typeNames[1];
    468494    case MT_INT:
    469       return MultiType::typeNames[2];
     495    return MultiType::typeNames[2];
    470496    case MT_FLOAT:
    471       return MultiType::typeNames[3];
     497    return MultiType::typeNames[3];
    472498    case MT_CHAR:
    473       return MultiType::typeNames[4];
     499    return MultiType::typeNames[4];
    474500    case MT_STRING:
    475       return MultiType::typeNames[5];
     501    return MultiType::typeNames[5];
    476502    default:
    477       return MultiType::typeNames[0];
     503    return MultiType::typeNames[0];
    478504  }
    479505}
  • branches/new_class_id/src/lib/util/multi_type.h

    r8035 r9730  
    7979    inline MT_Type getType() const { return this->type; };
    8080
     81    void storeString();
    8182
    8283    /* RETRIEVING FUNCTIONS */
     
    8889    std::string getString() const;
    8990    const std::string& getConstString() const;
     91    const std::string& getStoredString() const;
    9092
    9193    void reset();
Note: See TracChangeset for help on using the changeset viewer.