Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1056 was 1056, checked in by landauf, 16 years ago

don't panic, no codechanges!
added a link to www.orxonox.net

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 <string>
34#include <iostream>
35#include "UtilPrereqs.h"
36
37#include "MultiTypePrimitive.h"
38
39class _UtilExport MultiTypeString : public MultiTypePrimitive
40{
41    public:
42        MultiTypeString(MultiType type = MT_null);
43        inline MultiTypeString(void*          value) : MultiTypePrimitive(value) {}
44        inline MultiTypeString(int            value) : MultiTypePrimitive(value) {}
45        inline MultiTypeString(unsigned int   value) : MultiTypePrimitive(value) {}
46        inline MultiTypeString(char           value) : MultiTypePrimitive(value) {}
47        inline MultiTypeString(unsigned char  value) : MultiTypePrimitive(value) {}
48        inline MultiTypeString(short          value) : MultiTypePrimitive(value) {}
49        inline MultiTypeString(unsigned short value) : MultiTypePrimitive(value) {}
50        inline MultiTypeString(long           value) : MultiTypePrimitive(value) {}
51        inline MultiTypeString(unsigned long  value) : MultiTypePrimitive(value) {}
52        inline MultiTypeString(float          value) : MultiTypePrimitive(value) {}
53        inline MultiTypeString(double         value) : MultiTypePrimitive(value) {}
54        inline MultiTypeString(long double    value) : MultiTypePrimitive(value) {}
55        inline MultiTypeString(bool           value) : MultiTypePrimitive(value) {}
56        inline MultiTypeString(const char*           value)   { this->setValue(value); }
57        inline MultiTypeString(const std::string&    value)   { this->setValue(value); }
58        inline MultiTypeString(const MultiTypeString& mts)    { this->setValue(mts);   }
59        virtual inline ~MultiTypeString() {}
60
61        using MultiTypePrimitive::operator=;
62        inline MultiTypeString& operator=(const char*             value)   { this->setValue(value); return *this; }
63        inline MultiTypeString& operator=(const std::string&      value)   { this->setValue(value); return *this; }
64        inline MultiTypeString& operator=(const MultiTypeString& mts)      { this->setValue(mts);   return *this; }
65
66        using MultiTypePrimitive::operator==;
67        inline bool operator==(const char*             value) const { return (this->string_      == std::string(value)); }
68        inline bool operator==(const std::string&      value) const { return (this->string_      == value);              }
69        bool operator==(const MultiTypeString& mts) const;
70
71        using MultiTypePrimitive::operator!=;
72        inline bool operator!=(const char*             value) const { return (this->string_      != std::string(value)); }
73        inline bool operator!=(const std::string&      value) const { return (this->string_      != value);              }
74        bool operator!=(const MultiTypeString& mts) const;
75
76        virtual operator void*()                const;
77        virtual operator int()                  const;
78        virtual operator unsigned int()         const;
79        virtual operator char()                 const;
80        virtual operator unsigned char()        const;
81        virtual operator short()                const;
82        virtual operator unsigned short()       const;
83        virtual operator long()                 const;
84        virtual operator unsigned long()        const;
85        virtual operator float ()               const;
86        virtual operator double ()              const;
87        virtual operator long double()          const;
88        virtual operator bool()                 const;
89        virtual operator std::string()          const;
90        virtual operator const char*()          const;
91
92        using MultiTypePrimitive::setValue;
93        inline void setValue(const char*             value) { this->type_ = MT_string;     this->string_     = std::string(value); }
94        inline void setValue(const std::string&      value) { this->type_ = MT_string;     this->string_     = value;              }
95        void setValue(const MultiTypeString& mts);
96
97        inline std::string getString()          const { return this->string_;         }
98        inline const char*  getConstChar()      const { return this->string_.c_str(); }
99
100        inline std::string& getString()          { return this->string_;         }
101        inline const char*  getConstChar()       { return this->string_.c_str(); }
102
103        using MultiTypePrimitive::getValue;
104        inline void getValue(std::string*      variable) const { (*variable) = this->string_;         }
105        inline void getValue(const char**      variable) const { (*variable) = this->string_.c_str(); }
106
107        virtual std::string getTypename() const;
108
109        virtual std::string toString() const;
110        virtual bool fromString(const std::string value);
111
112    protected:
113        std::string      string_;
114};
115
116_UtilExport std::ostream& operator<<(std::ostream& out, MultiTypeString& mts);
117
118#endif /* _MultiTypeString_H__ */
Note: See TracBrowser for help on using the repository browser.