Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core2/src/util/MultiTypeString.h @ 947

Last change on this file since 947 was 947, checked in by landauf, 16 years ago
  • added CommandExecutor
  • added ConsoleCommand macros
  • added getTypename to all MultiTypes
  • added 2 static maps to Identifier that contain all existing Identifiers with their names and lowercase names respectively.
  • added 2 maps to each Identifier that contain all console commands of the Identifier with their names and lowercase names respectively
  • using tolower(.) and toupper(.) instead of selfmade hacks in String.h
  • added AccessLevel enum
  • added some test-console-commands to OutputHandler, Ambient and SpaceShip
File size: 6.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 *   Inspiration: MultiType by Benjamin Grauer
27 */
28
29#ifndef _MultiTypeString_H__
30#define _MultiTypeString_H__
31
32#include <string>
33#include <iostream>
34#include "UtilPrereqs.h"
35#include "XMLIncludes.h"
36#include "tinyxml/ticpp.h"
37
38#include "MultiTypePrimitive.h"
39
40class _UtilExport MultiTypeString : public MultiTypePrimitive
41{
42    public:
43        MultiTypeString(MultiType type = MT_null);
44        inline MultiTypeString(void*          value) : MultiTypePrimitive(value) {}
45        inline MultiTypeString(int            value) : MultiTypePrimitive(value) {}
46        inline MultiTypeString(unsigned int   value) : MultiTypePrimitive(value) {}
47        inline MultiTypeString(char           value) : MultiTypePrimitive(value) {}
48        inline MultiTypeString(unsigned char  value) : MultiTypePrimitive(value) {}
49        inline MultiTypeString(short          value) : MultiTypePrimitive(value) {}
50        inline MultiTypeString(unsigned short value) : MultiTypePrimitive(value) {}
51        inline MultiTypeString(long           value) : MultiTypePrimitive(value) {}
52        inline MultiTypeString(unsigned long  value) : MultiTypePrimitive(value) {}
53        inline MultiTypeString(float          value) : MultiTypePrimitive(value) {}
54        inline MultiTypeString(double         value) : MultiTypePrimitive(value) {}
55        inline MultiTypeString(long double    value) : MultiTypePrimitive(value) {}
56        inline MultiTypeString(bool           value) : MultiTypePrimitive(value) {}
57        inline MultiTypeString(const char*           value)   { this->setValue(value); }
58        inline MultiTypeString(const std::string&    value)   { this->setValue(value); }
59        inline MultiTypeString(const orxonox::Element& value) { this->setValue(value); }
60        inline MultiTypeString(const MultiTypeString& mts)    { this->setValue(mts);   }
61        virtual inline ~MultiTypeString() {}
62
63        using MultiTypePrimitive::operator=;
64        inline MultiTypeString& operator=(const char*             value)   { this->setValue(value); return *this; }
65        inline MultiTypeString& operator=(const std::string&      value)   { this->setValue(value); return *this; }
66        inline MultiTypeString& operator=(const orxonox::Element& value)   { this->setValue(value); return *this; }
67        inline MultiTypeString& operator=(const MultiTypeString& mts)      { this->setValue(mts);   return *this; }
68
69        using MultiTypePrimitive::operator==;
70        inline bool operator==(const char*             value) const { return (this->string_      == std::string(value)); }
71        inline bool operator==(const std::string&      value) const { return (this->string_      == value);              }
72        inline bool operator==(const orxonox::Element& value) const { return (&this->xmlelement_ == &value);             }
73        bool operator==(const MultiTypeString& mts) const;
74
75        using MultiTypePrimitive::operator!=;
76        inline bool operator!=(const char*             value) const { return (this->string_      != std::string(value)); }
77        inline bool operator!=(const std::string&      value) const { return (this->string_      != value);              }
78        inline bool operator!=(const orxonox::Element& value) const { return (&this->xmlelement_ != &value);             }
79        bool operator!=(const MultiTypeString& mts) const;
80
81        virtual operator void*()                const;
82        virtual operator int()                  const;
83        virtual operator unsigned int()         const;
84        virtual operator char()                 const;
85        virtual operator unsigned char()        const;
86        virtual operator short()                const;
87        virtual operator unsigned short()       const;
88        virtual operator long()                 const;
89        virtual operator unsigned long()        const;
90        virtual operator float ()               const;
91        virtual operator double ()              const;
92        virtual operator long double()          const;
93        virtual operator bool()                 const;
94        virtual operator std::string()          const;
95        virtual operator const char*()          const;
96        virtual operator orxonox::Element()     const;
97
98        using MultiTypePrimitive::setValue;
99        inline void setValue(const char*             value) { this->type_ = MT_string;     this->string_     = std::string(value); }
100        inline void setValue(const std::string&      value) { this->type_ = MT_string;     this->string_     = value;              }
101        inline void setValue(const orxonox::Element& value) { this->type_ = MT_xmlelement; this->xmlelement_ = value;              }
102        void setValue(const MultiTypeString& mts);
103
104        inline std::string getString()          const { return this->string_;         }
105        inline const char*  getConstChar()      const { return this->string_.c_str(); }
106        inline orxonox::Element getXMLElement() const { return this->xmlelement_;     }
107
108        inline std::string& getString()          { return this->string_;         }
109        inline const char*  getConstChar()       { return this->string_.c_str(); }
110        inline orxonox::Element& getXMLElement() { return this->xmlelement_;     }
111
112        using MultiTypePrimitive::getValue;
113        inline void getValue(std::string*      variable) const { (*variable) = this->string_;         }
114        inline void getValue(const char**      variable) const { (*variable) = this->string_.c_str(); }
115        inline void getValue(orxonox::Element* variable) const { (*variable) = this->xmlelement_;     }
116
117        virtual std::string getTypename() const;
118
119        virtual std::string toString() const;
120        virtual bool fromString(const std::string value);
121
122    protected:
123        std::string      string_;
124        orxonox::Element xmlelement_;
125};
126
127std::ostream& operator<<(std::ostream& out, MultiTypeString& mts);
128
129#endif /* _MultiTypeString_H__ */
Note: See TracBrowser for help on using the repository browser.