Project

General

Profile

SO3Engine
FlashValue.cpp
Go to the documentation of this file.
1/*
2 This file is part of Hikari, a library that allows developers
3 to use Flash in their Ogre3D applications.
4
5 Copyright (C) 2008 Adam J. Simmons
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 This library 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 GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21/*********************************************************************************************
22 ___ ___ .__ __ .__
23 / | \|__| | _______ _______|__|
24/ ~ \ | |/ /\__ \\_ __ \ |
25\ Y / | < / __ \| | \/ |
26 \___|_ /|__|__|_ \‍(____ /__| |__| v0.4
27 \/ \/ \/
28
29
30* Zed Games PC Development Team - Jaime Crespillo Vilchez (jcrespillo@zed.com)
31* Build: 0.1 - Date: 13/10/2008
32* Undocked version of Hikari Lib
33* Brief: Changes in constructors to support basic string
34**********************************************************************************************/
36
37using namespace Hikari;
38
39template<class NumberType>
40inline NumberType toNumber(std::string numberString)
41{
42 if(numberString.substr(0, 4).compare("true") == 0) return 1;
43 else if(numberString.substr(0, 4).compare("false") == 0) return 0;
44
45 std::istringstream converter(numberString);
46
47 if(typeid(NumberType)==typeid(bool))
48 {
49 int result;
50 return (converter >> result).fail() ? false : !!result;
51 }
52
53 NumberType result;
54 return (converter >> result).fail() ? 0 : result;
55}
56
57template<class NumberType>
58inline std::string numberToString(const NumberType &number)
59{
60 std::ostringstream converter;
61
62 if(typeid(NumberType)==typeid(bool))
63 {
64 return number ? "true" : "false";
65 }
66
67 return (converter << number).fail() ? "" : converter.str();
68}
69
70FlashValue::FlashValue() : numValue(0), boolValue(0), valueType(FT_NULL)
71{
72}
73
74FlashValue::FlashValue(bool booleanValue) : numValue(0), boolValue(booleanValue), valueType(FT_BOOLEAN)
75{
76}
77
78FlashValue::FlashValue(int numericValue) : numValue((float) numericValue), boolValue(0), valueType(FT_NUMBER)
79{
80}
81
82FlashValue::FlashValue(float numericValue) : numValue(numericValue), boolValue(0), valueType(FT_NUMBER)
83{
84}
85
86FlashValue::FlashValue(const char* stringValue) : strValue(stringValue), numValue(0), boolValue(0), valueType(FT_STRING)
87{
88}
89
90
91/********************* DEPRECATED
92FlashValue::FlashValue(const wchar_t* stringValue) : strValue(stringValue), numValue(0), boolValue(0), valueType(FT_STRING)
93{
94}*/
95
96FlashValue::FlashValue(const std::string& stringValue) : strValue(stringValue), numValue(0), boolValue(0), valueType(FT_STRING)
97{
98}
99
100FlashValue::FlashValue(const std::wstring& stringValue) : wstrValue(stringValue), strValue(""), numValue(0), boolValue(0), valueType(FT_WSTRING)
101{
102}
103
104/********************* DEPRECATED
105FlashValue::FlashValue(const dspStringBase& stringValue) : strValue(stringValue), numValue(0), boolValue(0), valueType(FT_STRING)
106{
107}*/
108
110{
111 return valueType;
112}
113
115{
116 return valueType == FT_NULL;
117}
118
120{
121 strValue.clear();
122 numValue = 0;
123 boolValue = false;
124 valueType = FT_NULL;
125}
126
128{
129 if(valueType == FT_BOOLEAN)
130 return boolValue;
131 else if(valueType == FT_NUMBER)
132 return !!((int)numValue);
133 /*else if(valueType == FT_STRING)
134 return toNumber<bool>(strValue);*/
135
136 return false;
137}
138
140{
141 if(valueType == FT_NUMBER)
142 return numValue;
143 else if(valueType == FT_BOOLEAN)
144 return (float)boolValue;
145 /*else if(valueType == FT_STRING)
146 return toNumber<floatBase>(strValue);*/
147
148 return 0;
149}
150
152{
153 if(valueType != FT_NUMBER){
154 colorValueBase defaultZERO;
155 defaultZERO.b = 0;
156 defaultZERO.g = 0;
157 defaultZERO.r = 0;
158 return defaultZERO;
159 }
160 colorValueBase result;
161 result.b = ((int)numValue % 256) / 255.0f;
162 result.g = (((int)numValue / 256) % 256) / 255.0f;
163 result.r = (((int)numValue / 256 / 256) % 256) / 255.0f;
164
165 return result;
166}
167
168std::string FlashValue::getString() const
169{
170 if(valueType == FT_STRING)
171 return strValue;
172 /*else if(valueType == FT_BOOLEAN)
173 return numberToString<bool>(boolValue);*/
174 /*else if(valueType == FT_NUMBER)
175 return numberToString<floatBase>(numValue);*/
176
177 return "";
178}
179
180std::wstring FlashValue::getWString() const
181{
182 if(valueType == FT_WSTRING)
183 return wstrValue;
184 /*else if(valueType == FT_BOOLEAN)
185 return numberToString<bool>(boolValue);*/
186 /*else if(valueType == FT_NUMBER)
187 return numberToString<floatBase>(numValue);*/
188
189 return L"";
190}
192{
193}
194
196{
197 this->swap(v);
198}
199
200Args::Args(const FlashValue& firstArg) : Arguments(1, firstArg)
201{
202}
203
205{
206 this->push_back(newArg);
207 return *this;
208}
std::string numberToString(const NumberType &number)
NumberType toNumber(std::string numberString)
Args & operator()(const FlashValue &newArg)
std::wstring getWString() const
bool getBool() const
float getNumber() const
bool isNull() const
short getType() const
std::string getString() const
colorValueBase getNumberAsColor() const
@ FT_WSTRING
Definition FlashValue.h:55
@ FT_STRING
Definition FlashValue.h:54
@ FT_NUMBER
Definition FlashValue.h:53
@ FT_NULL
Definition FlashValue.h:51
@ FT_BOOLEAN
Definition FlashValue.h:52
_HikariExport std::vector< FlashValue > Arguments
Definition FlashValue.h:188