Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 1162 was 1064, checked in by rgrieder, 17 years ago
  • replaced all String2Number with ConvertValue
  • replaced all tokenize with SubString
  • dealt with warnings under msvc
  • removed some warnings by placing casts
  • bugfix in audio: local variable pushed into member variable std::vector
  • updated StableHeaders.h
File size: 5.4 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#include "MultiTypeString.h"
31#include "Convert.h"
32
33MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type)
34{
35    // Nothing to do for string and xml-element
36}
37
38bool MultiTypeString::operator==(const MultiTypeString& mts) const
39{
40    if (!MultiTypePrimitive::operator==(mts) && this->type_ == mts.type_)
41    {
42        if (this->type_ == MT_constchar)
43            return (this->string_ == mts.string_);
44        else if (this->type_ == MT_string)
45            return (this->string_ == mts.string_);
46    }
47
48    return false;
49}
50
51bool MultiTypeString::operator!=(const MultiTypeString& mts) const
52{
53    if (MultiTypePrimitive::operator==(mts) && this->type_ == mts.type_)
54    {
55        if (this->type_ == MT_constchar)
56            return (this->string_ != mts.string_);
57        else if (this->type_ == MT_string)
58            return (this->string_ != mts.string_);
59    }
60
61    return true;
62}
63
64MultiTypeString::operator void*() const
65{ return (this->type_ == MT_void) ? this->value_.void_ : getConvertedValue<MultiTypeString, void*>(*this, 0); }
66MultiTypeString::operator int() const
67{ return (this->type_ == MT_int) ? this->value_.int_ : getConvertedValue<MultiTypeString, int>(*this, 0); }
68MultiTypeString::operator unsigned int() const
69{ return (this->type_ == MT_uint) ? this->value_.uint_ : getConvertedValue<MultiTypeString, unsigned int>(*this, 0); }
70MultiTypeString::operator char() const
71{ return (this->type_ == MT_char) ? this->value_.char_ : getConvertedValue<MultiTypeString, char>(*this, 0); }
72MultiTypeString::operator unsigned char() const
73{ return (this->type_ == MT_uchar) ? this->value_.uchar_ : getConvertedValue<MultiTypeString, unsigned char>(*this, 0); }
74MultiTypeString::operator short() const
75{ return (this->type_ == MT_short) ? this->value_.short_ : getConvertedValue<MultiTypeString, short>(*this, 0); }
76MultiTypeString::operator unsigned short() const
77{ return (this->type_ == MT_ushort) ? this->value_.ushort_ : getConvertedValue<MultiTypeString, unsigned short>(*this, 0); }
78MultiTypeString::operator long() const
79{ return (this->type_ == MT_long) ? this->value_.long_ : getConvertedValue<MultiTypeString, long>(*this, 0); }
80MultiTypeString::operator unsigned long() const
81{ return (this->type_ == MT_ulong) ? this->value_.ulong_ : getConvertedValue<MultiTypeString, unsigned long>(*this, 0); }
82MultiTypeString::operator float() const
83{ return (this->type_ == MT_float) ? this->value_.float_ : getConvertedValue<MultiTypeString, float>(*this, 0); }
84MultiTypeString::operator double() const
85{ return (this->type_ == MT_double) ? this->value_.double_ : getConvertedValue<MultiTypeString, double>(*this, 0); }
86MultiTypeString::operator long double() const
87{ return (this->type_ == MT_longdouble) ? this->value_.longdouble_ : getConvertedValue<MultiTypeString, long double>(*this, 0); }
88MultiTypeString::operator bool() const
89{ return (this->type_ == MT_bool) ? this->value_.bool_ : getConvertedValue<MultiTypeString, bool>(*this, 0); }
90MultiTypeString::operator std::string() const
91{ return (this->type_ == MT_string) ? this->string_ : getConvertedValue<MultiTypeString, std::string>(*this); }
92MultiTypeString::operator const char*() const
93{ return ((this->type_ == MT_constchar) ? this->string_ : getConvertedValue<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::getTypename() const
102{
103    if (this->type_ == MT_constchar)
104        return "string";
105    else if (this->type_ == MT_string)
106        return "string";
107    else
108        return MultiTypePrimitive::getTypename();
109}
110
111std::string MultiTypeString::toString() const
112{
113    std::string output;
114
115    if (this->type_ == MT_constchar)
116        return this->string_;
117    else if (this->type_ == MT_string)
118        return this->string_;
119    else
120        return MultiTypePrimitive::toString();
121
122    // FIXME: unreachable code
123    // return output;
124}
125
126bool MultiTypeString::fromString(const std::string value)
127{
128    if (this->type_ == MT_constchar)
129        this->string_ = value;
130    else if (this->type_ == MT_string)
131        this->string_ = value;
132    else
133        return MultiTypePrimitive::fromString(value);
134
135    return true;
136}
137
138std::ostream& operator<<(std::ostream& out, MultiTypeString& mts)
139{
140    out << mts.toString();
141    return out;
142}
Note: See TracBrowser for help on using the repository browser.