Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/util/MultiTypeString.cc @ 890

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

merged core branch to trunk

File size: 5.0 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#include "MultiTypeString.h"
30#include "Convert.h"
31
32MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type)
33{
34    if (type == MT_constchar)
35        this->string_ = std::string("");
36    else if (type == MT_string)
37        this->string_ = std::string("");
38}
39
40bool MultiTypeString::operator==(const MultiTypeString& mts) const
41{
42    if (!MultiTypePrimitive::operator==(mts) && this->type_ == mts.type_)
43    {
44        if (this->type_ == MT_constchar)
45            return (this->string_ == mts.string_);
46        else if (this->type_ == MT_string)
47            return (this->string_ == mts.string_);
48    }
49
50    return false;
51}
52
53bool MultiTypeString::operator!=(const MultiTypeString& mts) const
54{
55    if (MultiTypePrimitive::operator==(mts) && this->type_ == mts.type_)
56    {
57        if (this->type_ == MT_constchar)
58            return (this->string_ != mts.string_);
59        else if (this->type_ == MT_string)
60            return (this->string_ != mts.string_);
61    }
62
63    return true;
64}
65
66MultiTypeString::operator int() const
67{ return (this->type_ == MT_int) ? this->value_.int_ : ConvertValueAndReturn<MultiTypeString, int>(*this); }
68MultiTypeString::operator unsigned int() const
69{ return (this->type_ == MT_uint) ? this->value_.uint_ : ConvertValueAndReturn<MultiTypeString, unsigned int>(*this); }
70MultiTypeString::operator char() const
71{ return (this->type_ == MT_char) ? this->value_.char_ : ConvertValueAndReturn<MultiTypeString, char>(*this); }
72MultiTypeString::operator unsigned char() const
73{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : ConvertValueAndReturn<MultiTypeString, unsigned char>(*this); }
74MultiTypeString::operator short() const
75{ return (this->type_ == MT_short) ? this->value_.short_ : ConvertValueAndReturn<MultiTypeString, short>(*this); }
76MultiTypeString::operator unsigned short() const
77{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : ConvertValueAndReturn<MultiTypeString, unsigned short>(*this); }
78MultiTypeString::operator long() const
79{ return (this->type_ == MT_long) ? this->value_.long_ : ConvertValueAndReturn<MultiTypeString, long>(*this); }
80MultiTypeString::operator unsigned long() const
81{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : ConvertValueAndReturn<MultiTypeString, unsigned long>(*this); }
82MultiTypeString::operator float() const
83{ return (this->type_ == MT_float) ? this->value_.float_ : ConvertValueAndReturn<MultiTypeString, float>(*this); }
84MultiTypeString::operator double() const
85{ return (this->type_ == MT_double) ? this->value_.double_ : ConvertValueAndReturn<MultiTypeString, double>(*this); }
86MultiTypeString::operator long double() const
87{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : ConvertValueAndReturn<MultiTypeString, long double>(*this); }
88MultiTypeString::operator bool() const
89{ return (this->type_ == MT_bool) ? this->value_.bool_ : ConvertValueAndReturn<MultiTypeString, bool>(*this); }
90MultiTypeString::operator std::string() const
91{ return (this->type_ == MT_string) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this); }
92MultiTypeString::operator const char*() const
93{ return ((this->type_ == MT_constchar) ? this->string_ : ConvertValueAndReturn<MultiTypeString, std::string>(*this)).c_str(); }
94
95void MultiTypeString::setValue(const MultiTypeString& mts)
96{
97    MultiTypePrimitive::setValue(mts);
98    this->string_ = mts.string_;
99}
100
101std::string MultiTypeString::toString() const
102{
103    if (this->type_ == MT_constchar)
104        return this->string_;
105    else if (this->type_ == MT_string)
106        return this->string_;
107    else
108        return MultiTypePrimitive::toString();
109}
110
111bool MultiTypeString::fromString(const std::string value)
112{
113    if (this->type_ == MT_constchar)
114        this->string_ = value;
115    else if (this->type_ == MT_string)
116        this->string_ = value;
117    else
118        return MultiTypePrimitive::fromString(value);
119
120    return true;
121}
122
123std::ostream& operator<<(std::ostream& out, MultiTypeString& mts)
124{
125    out << mts.toString();
126    return out;
127}
Note: See TracBrowser for help on using the repository browser.