src/tools/values/vCore.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023 
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include <boost/lexical_cast.hpp>
00029 
00030 #include "vCore.h"
00031 
00032 namespace vValue {
00033 namespace Expr {
00034 namespace Core {
00035 
00039 Base::Base(int precision, int minsize, char fill):
00040         m_precision(precision),
00041         m_minsize(minsize),
00042         m_fill(fill)
00043 {}
00044 
00047 Base::Base(Base const &other) :
00048         m_precision(other.m_precision),
00049         m_minsize(other.m_minsize),
00050         m_fill(other.m_fill)
00051 { }
00052 
00055 void Base::SetPrecision(int precision) {
00056     m_precision = precision;
00057 }
00058 
00061 void Base::SetMinsize(int minsize) {
00062     m_minsize = minsize;
00063 }
00064 
00067 void Base::SetFill(char fill) {
00068     m_fill = fill;
00069 }
00070 
00071 Variant
00072 Base::GetValue(void) const {
00073     //std::cerr << "WARNING: Base::GetValue called!" << std::endl;
00074     return std::string("");
00075 }
00076 template<> Variant Base::Get<Variant>() const { return GetValue(); }
00077 
00080 int Base::GetInt(void) const {
00081     try {
00082         return boost::lexical_cast<int>(GetValue());
00083     }
00084     catch(boost::bad_lexical_cast &)
00085     {
00086         return 0;
00087     }
00088 }
00089 template<> int     Base::Get<int    >() const { return GetInt(); }
00090 
00093 float Base::GetFloat(void) const {
00094     try {
00095         return boost::lexical_cast<float>(GetValue());
00096     }
00097     catch(boost::bad_lexical_cast &)
00098     {
00099         return 0.0;
00100     }
00101 }
00102 template<> float   Base::Get<float  >() const { return GetFloat(); }
00103 
00106 tString Base::GetString(Base const *other) const {
00107     Variant v = GetValue();
00108     if (tString *iptr = boost::get<tString>(&v))
00109             return *iptr;
00110     return Output(v, other);
00111 }
00112 template<> tString Base::Get<tString>() const { return GetString(); }
00113 
00116 Base *Base::copy(void) const {
00117     return new Base();
00118 }
00119 
00120 bool Base::operator==(Base const &other) const { return false; }
00121 bool Base::operator!=(Base const &other) const { return true;  }
00122 bool Base::operator>=(Base const &other) const { return false; }
00123 bool Base::operator<=(Base const &other) const { return false; }
00124 bool Base::operator> (Base const &other) const { return false; }
00125 bool Base::operator< (Base const &other) const { return false; }
00126 
00127 }
00128 }
00129 namespace Type {
00130 
00133 Set::Set() : 
00134         m_min(new Expr::Base()),
00135         m_max(new Expr::Base()),
00136         m_val(new Expr::Base())
00137 {}
00138 
00141 Set::Set(BasePtr &val) : 
00142         m_min(new Expr::Base()),
00143         m_max(new Expr::Base()),
00144         m_val(val)
00145 {}
00146 
00151 Set::Set(BasePtr &val, BasePtr &min, BasePtr &max) : 
00152         m_min(min),
00153         m_max(max),
00154         m_val(val)
00155 {}
00156 
00159 Set::Set(Set const &other) :
00160         m_min(other.m_min),
00161         m_max(other.m_max),
00162         m_val(other.m_val)
00163 {}
00164 
00165 Set::~Set() {
00166 }
00167 
00170 void Set::operator=(Set const &other) {
00171     if(this != &other) {
00172         m_min = BasePtr(other.GetMin().copy());
00173         m_max = BasePtr(other.GetMax().copy());
00174         m_val = BasePtr(other.GetVal().copy());
00175     }
00176 }
00177 
00178 }
00179 namespace Expr {
00180 namespace Core {
00181 
00184 String::String(tString value):
00185         m_value(value)
00186 { }
00187 
00190 String::String(char const *value):
00191         m_value(tString(value))
00192 { }
00193 
00196 String::String(Base const &other):
00197         Base(other),
00198         m_value(other.GetString())
00199 { }
00200 
00203 Base *String::copy(void) const {
00204     return new String(*this);
00205 }
00206 
00207 Variant String::GetValue() const {
00208     return GetString();
00209 }
00210 
00213 tString String::GetString(Base const *other) const {
00214     return Output(m_value, other);
00215 }
00216 
00217 bool String::operator==(Base const &other) const { return m_value == static_cast<tString>(other); }
00218 bool String::operator!=(Base const &other) const { return m_value !=  static_cast<tString>(other); }
00219 bool String::operator>=(Base const &other) const { return m_value >=  static_cast<tString>(other); }
00220 bool String::operator<=(Base const &other) const { return m_value <=  static_cast<tString>(other); }
00221 bool String::operator> (Base const &other) const { return m_value >   static_cast<tString>(other); }
00222 bool String::operator< (Base const &other) const { return m_value <   static_cast<tString>(other); }
00223 
00224 
00227 UnaryOp::UnaryOp(BasePtr value) :
00228         m_value(value    )
00229 { }
00230 
00233 UnaryOp::UnaryOp(UnaryOp const &other) :
00234         Base (other         ),
00235         m_value(other.m_value->copy())
00236 { }
00237 
00238 Base *UnaryOp::copy(void) const {
00239     return new UnaryOp(*this);
00240 }
00241 
00245 BinaryOp::BinaryOp(BasePtr lvalue, BasePtr rvalue) :
00246         m_lvalue(lvalue    ),
00247         m_rvalue(rvalue    )
00248 { }
00249 
00252 BinaryOp::BinaryOp(BinaryOp const &other) :
00253         Base (other         ),
00254         m_lvalue(other.m_lvalue->copy()),
00255         m_rvalue(other.m_rvalue->copy())
00256 { }
00257 
00258 Base *BinaryOp::copy(void) const {
00259     return new BinaryOp(*this);
00260 }
00261 
00262 }
00263 }
00264 }
00265 
00266 

Generated on Sat Mar 15 22:56:03 2008 for Armagetron Advanced by  doxygen 1.5.4