00001
00002
00003
00004
00005
00006 #ifndef CSL_Variable_H
00007 #define CSL_Variable_H
00008
00009 #include "CSL_Core.h"
00010
00011
00012
00013 #ifdef USE_RANDOMS
00014 #include "newran/newran.h"
00015 #endif
00016
00017 namespace csl {
00018
00028
00029 class CVariable {
00030
00031 protected:
00032 float mValue;
00033
00034 public:
00035 CVariable() { };
00036 CVariable(float tvalue) : mValue(tvalue) { };
00038 float value() { return(mValue); };
00039 void setValue(float x) { mValue = x; };
00040 void setValue(int x) { mValue = (float) x; };
00041 void setValue(double x) { mValue = (float) x; };
00042 };
00043
00049
00050 class StaticVariable : public CVariable, public UnitGenerator {
00051
00052 public:
00053 StaticVariable(float x) : CVariable(x), UnitGenerator() { };
00054 StaticVariable(int x) : CVariable((float) x), UnitGenerator() { };
00055 StaticVariable(double x) : CVariable((float) x), UnitGenerator() { };
00056
00058 bool isFixed() { return true; };
00060 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00061
00062 float value() { return(CVariable::value()); };
00063 void setValue(float x) { CVariable::setValue(x); };
00064 void setValue(int x) { CVariable::setValue(x); };
00065 void setValue(double x) { CVariable::setValue(x); };
00066 };
00067
00068
00069
00070 #ifdef CSL_ENUMS
00071 typedef enum {
00072 kOpPlus,
00073 kOpTimes,
00074 kOpMinus,
00075 kOpDivided,
00076 kOpNegated
00077 } VOperator;
00078 #else
00079 #define kOpPlus 1
00080 #define kOpTimes 2
00081 #define kOpMinus 3
00082 #define kOpDivided 4
00083 #define kOpNegated 5
00084 typedef int VOperator;
00085 #endif
00086
00091
00092 class DynamicVariable : public CVariable, public Effect {
00093
00094 protected:
00095 VOperator mMode;
00096
00097 public:
00098 DynamicVariable(UnitGenerator & vox, float val) : CVariable(val), Effect(vox), mMode(kOpTimes) { };
00099 DynamicVariable(UnitGenerator & vox, double val) : CVariable((float) val), Effect(vox), mMode(kOpTimes) { };
00100 DynamicVariable(float val, UnitGenerator & vox) : CVariable(val), Effect(vox), mMode(kOpTimes) { };
00101 DynamicVariable(float val, UnitGenerator & vox, VOperator m) : CVariable(val), Effect(vox), mMode(m) { };
00102 DynamicVariable(UnitGenerator & vox, float val, VOperator m) : CVariable(val), Effect(vox), mMode(m) { };
00103
00104 DynamicVariable(int val, UnitGenerator & vox) : CVariable((float) val), Effect(vox), mMode(kOpTimes) { };
00105 DynamicVariable(UnitGenerator & vox, int val) : CVariable((float) val), Effect(vox), mMode(kOpTimes) { };
00106 DynamicVariable(int val, UnitGenerator & vox, VOperator m) : CVariable((float) val), Effect(vox), mMode(m) { };
00107 DynamicVariable(UnitGenerator & vox, int val, VOperator m) : CVariable((float) val), Effect(vox), mMode(m) { };
00108
00110
00111 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00112
00113 void setValue(float x) { CVariable::setValue(x); };
00114 void setValue(int x) { CVariable::setValue(x); };
00115 void setValue(double x) { CVariable::setValue(x); };
00116 };
00117
00118 #ifdef USE_RANDOMS
00119
00120 #ifdef CSL_ENUMS
00121
00125
00126 typedef enum {
00127 kUniform,
00128 kExponential,
00129 kCauchy,
00130 kNormal,
00131 kChiSq,
00132 kGamma,
00133 kPareto,
00134 kPoisson,
00135 kBinomial,
00136 kNegativeBinomial
00137 } Distribution;
00138
00139 #endif
00140
00144
00145 class RandomVariable : public CVariable, public UnitGenerator {
00146
00147 private:
00148 const static bool copySeedFromDisk = false;
00149 MotherOfAll urng;
00150
00151 Random * mVar;
00152 Distribution mDist;
00153 float mMean;
00154 float mVariance;
00155
00156 public:
00157 RandomVariable(Distribution d, float mean, float variance, float v1, float v2);
00158 ~RandomVariable();
00160 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00161 };
00162
00163 #endif // USE_RANDOMS
00164
00165 }
00166
00167 #endif