Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5536 in orxonox.OLD for trunk/src/lib/util


Ignore:
Timestamp:
Nov 10, 2005, 10:52:34 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: added class MultiType, for multi-typed Atrribute handling… working

Location:
trunk/src/lib/util
Files:
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/util/multi_type.cc

    r5529 r5536  
    1616//#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_
    1717
    18 #include "proto_class.h"
     18#include "multi_type.h"
     19#include "stdincl.h"
    1920
    2021using namespace std;
    2122
    22 
    23 /**
    24  * standard constructor
    25  * @todo this constructor is not jet implemented - do it
    26 */
    27 ProtoClass::ProtoClass ()
     23MultiType::MultiType(int value)
    2824{
    29    this->setClassID(CL_PROTO_ID, "ProtoClass");
    30 
    31    /* If you make a new class, what is most probably the case when you write this file
    32       don't forget to:
    33        1. Add the new file new_class.cc to the ./src/Makefile.am
    34        2. Add the class identifier to ./src/class_id.h eg. CL_NEW_CLASS
    35 
    36       Advanced Topics:
    37       - if you want to let your object be managed via the ObjectManager make sure to read
    38         the object_manager.h header comments. You will use this most certanly only if you
    39         make many objects of your class, like a weapon bullet.
    40    */
     25  this->type = M_Int;
     26  this->value.typeInt = value;
    4127}
    4228
     29
     30MultiType::MultiType(float value)
     31{
     32  this->type = M_Float;
     33  this->value.typeFloat = value;
     34}
     35
     36
     37MultiType::MultiType(char value)
     38{
     39  this->type = M_Char;
     40  this->value.typeChar = value;
     41}
     42
     43
     44MultiType::MultiType(const char* value)
     45{
     46  this->type = M_String;
     47  this->value.typeString = new char[strlen(value)+1];
     48  strcpy(this->value.typeString, value);
     49}
    4350
    4451/**
    4552 * standard deconstructor
    4653*/
    47 ProtoClass::~ProtoClass ()
     54MultiType::~MultiType ()
    4855{
    4956  // delete what has to be deleted here
  • trunk/src/lib/util/multi_type.h

    r5529 r5536  
    11/*!
    2  * @file proto_class.h
     2 * @file multi_type.h
    33 * @brief Definition of ...
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
    8 
    9 #include "base_object.h"
     6#ifndef _MULTI_TYPE_H
     7#define _MULTI_TYPE_H
    108
    119// FORWARD DECLARATION
    1210
    1311
     12typedef enum
     13{
     14  M_Int,
     15  M_Float,
     16  M_Char,
     17  M_String,
     18
     19} M_Type;
     20
     21
    1422
    1523//! A class for ...
    16 class ProtoClass : public BaseObject {
     24class MultiType {
    1725
    1826 public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
     27   MultiType(int value);
     28   MultiType(float value);
     29   MultiType(char value);
     30   MultiType(const char* value);
     31
     32  virtual ~MultiType();
    2133
    2234
    2335 private:
    2436
     37   M_Type             type;
     38   union Type
     39   {
     40     int              typeInt;
     41     float            typeFloat;
     42     char             typeChar;
     43     char*            typeString;
     44   } value;
     45
     46
     47
    2548};
    2649
    27 #endif /* _PROTO_CLASS_H */
     50#endif /* _MULTI_TYPE_H */
Note: See TracChangeset for help on using the changeset viewer.