Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/MultiTypeString.h @ 1062

Last change on this file since 1062 was 1062, checked in by rgrieder, 16 years ago
  • changed header file inclusion order
File size: 5.9 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 *   Inspiration: MultiType by Benjamin Grauer
28 */
29
30#ifndef _MultiTypeString_H__
31#define _MultiTypeString_H__
32
33#include "UtilPrereqs.h"
34
35#include <string>
36#include <iostream>
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 MultiTypeString& mts)    { this->setValue(mts);   }
60        virtual inline ~MultiTypeString() {}
61
62        using MultiTypePrimitive::operator=;
63        inline MultiTypeString& operator=(const char*             value)   { this->setValue(value); return *this; }
64        inline MultiTypeString& operator=(const std::string&      value)   { this->setValue(value); return *this; }
65        inline MultiTypeString& operator=(const MultiTypeString& mts)      { this->setValue(mts);   return *this; }
66
67        using MultiTypePrimitive::operator==;
68        inline bool operator==(const char*             value) const { return (this->string_      == std::string(value)); }
69        inline bool operator==(const std::string&      value) const { return (this->string_      == value);              }
70        bool operator==(const MultiTypeString& mts) const;
71
72        using MultiTypePrimitive::operator!=;
73        inline bool operator!=(const char*             value) const { return (this->string_      != std::string(value)); }
74        inline bool operator!=(const std::string&      value) const { return (this->string_      != value);              }
75        bool operator!=(const MultiTypeString& mts) const;
76
77        virtual operator void*()                const;
78        virtual operator int()                  const;
79        virtual operator unsigned int()         const;
80        virtual operator char()                 const;
81        virtual operator unsigned char()        const;
82        virtual operator short()                const;
83        virtual operator unsigned short()       const;
84        virtual operator long()                 const;
85        virtual operator unsigned long()        const;
86        virtual operator float ()               const;
87        virtual operator double ()              const;
88        virtual operator long double()          const;
89        virtual operator bool()                 const;
90        virtual operator std::string()          const;
91        virtual operator const char*()          const;
92
93        using MultiTypePrimitive::setValue;
94        inline void setValue(const char*             value) { this->type_ = MT_string;     this->string_     = std::string(value); }
95        inline void setValue(const std::string&      value) { this->type_ = MT_string;     this->string_     = value;              }
96        void setValue(const MultiTypeString& mts);
97
98        inline std::string getString()          const { return this->string_;         }
99        inline const char*  getConstChar()      const { return this->string_.c_str(); }
100
101        inline std::string& getString()          { return this->string_;         }
102        inline const char*  getConstChar()       { return this->string_.c_str(); }
103
104        using MultiTypePrimitive::getValue;
105        inline void getValue(std::string*      variable) const { (*variable) = this->string_;         }
106        inline void getValue(const char**      variable) const { (*variable) = this->string_.c_str(); }
107
108        virtual std::string getTypename() const;
109
110        virtual std::string toString() const;
111        virtual bool fromString(const std::string value);
112
113    protected:
114        std::string      string_;
115};
116
117_UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeString& mts);
118
119#endif /* _MultiTypeString_H__ */
Note: See TracBrowser for help on using the repository browser.