1 /******************************************************************************
2 * Arachnoid Graphics Plugin for Mupen64Plus
3 * http://bitbucket.org/wahrhaft/mupen64plus-video-arachnoid/
5 * Copyright (C) 2007 Kristofer Karlsson, Rickard Niklasson
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.
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.
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 *****************************************************************************/
22 #ifndef STRING_VALUE_H_
23 #define STRING_VALUE_H_
28 //! Represents numeric value(s) with a string using conversion operators
31 StringValue() {data = "";}
32 StringValue(const StringValue& v) { data=v.data; }
33 StringValue(const std::string& s) { data=s; }
34 StringValue(const char *s) { data = s; }
49 StringValue(float f) {
55 StringValue(double f) {
61 // assignment operators
62 StringValue& operator=(const char* s) { data=s; return *this; }
63 StringValue& operator=(const std::string& s) { data=s; return *this; }
64 StringValue& operator=(const StringValue& v) { data=v.data; return *this; }
65 template<class T> StringValue& operator=(T x)
74 // comparison operators
75 bool operator==(const char* s) const { return data==s; }
76 bool operator==(const std::string& s) const { return data==s; }
77 bool operator==(const StringValue& x) const { return data==x.data; }
78 template<class T> bool operator==(T x) const { return (x == T(*this)); }
79 // conversion operators
80 operator bool() const {
81 if (data=="false" || data=="0") return false;
84 operator float() const {
85 return (float) atof(data.c_str());
87 operator double() const {
88 return atof(data.c_str());
90 operator char() const {
92 std::stringstream ss; ss << data; ss >> x;
95 operator unsigned char() const {
97 std::stringstream ss; ss << data; ss >> x;
100 operator int() const {
101 return atoi(data.c_str());
103 operator short() const {
104 return (short) atoi(data.c_str());
106 operator long() const {
107 return atol(data.c_str());
109 operator unsigned short() const {
111 std::stringstream ss; ss << data; ss >> x;
114 operator unsigned int() const {
116 std::stringstream ss; ss << data; ss >> x;
119 operator unsigned long() const {
121 std::stringstream ss; ss << data; ss >> x;
124 operator const char *() const {
128 std::string str() const { return data; }