Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Real.h

Go to the documentation of this file.
00001 /* SimData: Data Infrastructure for Simulations
00002  * Copyright (C) 2002 Mark Rose <tm2@stm.lbl.gov>
00003  * 
00004  * This file is part of SimData.
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  */
00020 
00021 
00022 #ifndef __SIMDATA_REAL_H__
00023 #define __SIMDATA_REAL_H__
00024 
00025 #include <SimData/BaseType.h>
00026 #include <SimData/Random.h>
00027 
00028 #include <string>
00029 #include <cmath>
00030 
00031 
00032 NAMESPACE_SIMDATA
00033 
00034 
00046 class SIMDATA_EXPORT Real: public BaseType {
00047         static random::Taus2 _rng;
00048         float _mean, _sigma;
00049         float _value;
00050 public:
00057         Real(float mean=0.0, float sigma=0.0);
00058 
00065         void set(float mean, float sigma);
00066 
00070         void regen();
00071 
00075         float getMean() const;
00076         
00080         float getSigma() const;
00081         
00085         float getValue() const;
00086 
00090         virtual std::string asString() const;
00091 
00095         virtual std::string typeString() const { return "type::Real"; }
00096 
00097         /*
00098         float __neg__();
00099         float __pos__();
00100         float __abs__();
00101         int __nonzero__();
00102         float __float__();
00103         int __int__();
00104         long __long__();
00105         float __add__(float v);
00106         float __radd__(float v);
00107         float __sub__(float v);
00108         float __rsub__(float v);
00109         float __mul__(float v);
00110         float __rmul__(float v);
00111         float __div__(float v);
00112         float __rdiv__(float v);
00113         float __rpow__(float v);
00114         float __pow__(float v);
00115         */
00116 
00117 #ifndef SWIG
00118 
00121         inline operator float() const { return _value; }
00122 #endif
00123         
00129         virtual void serialize(Archive&);
00130 
00136         virtual void parseXML(const char* cdata);
00137 
00138 // insert Python shadow class code to emulate "operator float()"
00139 #ifdef SWIG______NONO
00140 %insert("shadow") %{
00141     def __coerce__(self, other):
00142         if isinstance(other, Real):
00143             return (self.getValue(), other.getValue())
00144         return (self.getValue(), other)
00145 %}
00146 #endif // SWIG
00147 
00148 };
00149 
00150 #ifdef SWIG
00151 %extend Real {
00152         float __neg__() { return -(*self); }
00153         float __pos__() { return (*self); }
00154         float __abs__() { return static_cast<float>(fabs(*self)); }
00155         float __add__(float v) { return v + (*self); }
00156         float __radd__(float v) { return v + (*self); }
00157         float __sub__(float v) { return (*self) - v; }
00158         float __rsub__(float v) { return v - (*self); }
00159         float __mul__(float v) { return v * (*self); }
00160         float __rmul__(float v) { return v * (*self); }
00161         float __div__(float v) { assert(v != 0.0); return (*self) / v; }
00162         float __rdiv__(float v) { assert((*self) != 0.0); return v / (*self); }
00163         float __rpow__(float v) { return static_cast<float>(pow(v, (*self))); }
00164         float __pow__(float v) { return static_cast<float>(pow((*self), v)); }
00165         int __int__() { return (int)(*self); }
00166         long __long__() { return (long)(*self); }
00167         float __float__() { return (*self); }
00168         int __nonzero__() { return (*self) != 0.0; }
00169 }
00170 #endif // SWIG
00171 
00172 
00173 NAMESPACE_SIMDATA_END
00174 
00175 #endif //__SIMDATA_REAL_H__

SimData version pre-0.4.0. For more information on SimData, visit the SimData Homepage.

Generated on Tue Oct 14 12:06:39 2003, using Doxygen 1.2.18.

[SF.net]