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 class CVariable {
00029
00030 protected:
00031 float mValue;
00032
00033 public:
00034 CVariable() { };
00035 CVariable(float value) : mValue(value) { };
00037 float value() { return(mValue); };
00038 void setValue(float x) { mValue = x; };
00039 void setValue(int x) { mValue = (float) x; };
00040 void setValue(double x) { mValue = (float) x; };
00041 };
00042
00048 class StaticVariable : public CVariable, public UnitGenerator {
00049
00050 public:
00051 StaticVariable(float x) : CVariable(x), UnitGenerator() { };
00052 StaticVariable(int x) : CVariable((float) x), UnitGenerator() { };
00053 StaticVariable(double x) : CVariable((float) x), UnitGenerator() { };
00054
00056 bool isFixed() { return true; };
00058 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00059
00060 float value() { return(CVariable::value()); };
00061 void setValue(float x) { CVariable::setValue(x); };
00062 void setValue(int x) { CVariable::setValue(x); };
00063 void setValue(double x) { CVariable::setValue(x); };
00064 };
00065
00066
00067
00068 #ifdef CSL_ENUMS
00069 typedef enum {
00070 kOpPlus,
00071 kOpTimes,
00072 kOpMinus,
00073 kOpDivided,
00074 kOpNegated
00075 } VOperator;
00076 #else
00077 #define kOpPlus 1
00078 #define kOpTimes 2
00079 #define kOpMinus 3
00080 #define kOpDivided 4
00081 #define kOpNegated 5
00082 typedef int VOperator;
00083 #endif
00084
00089 class DynamicVariable : public CVariable, public Effect {
00090
00091 protected:
00092 VOperator mMode;
00093
00094 public:
00095 DynamicVariable(UnitGenerator & vox, float val) : CVariable(val), Effect(vox), mMode(kOpTimes) { };
00096 DynamicVariable(UnitGenerator & vox, double val) : CVariable((float) val), Effect(vox), mMode(kOpTimes) { };
00097 DynamicVariable(float val, UnitGenerator & vox) : CVariable(val), Effect(vox), mMode(kOpTimes) { };
00098 DynamicVariable(float val, UnitGenerator & vox, VOperator m) : CVariable(val), Effect(vox), mMode(m) { };
00099 DynamicVariable(UnitGenerator & vox, float val, VOperator m) : CVariable(val), Effect(vox), mMode(m) { };
00100
00101 DynamicVariable(int val, UnitGenerator & vox) : CVariable((float) val), Effect(vox), mMode(kOpTimes) { };
00102 DynamicVariable(UnitGenerator & vox, int val) : CVariable((float) val), Effect(vox), mMode(kOpTimes) { };
00103 DynamicVariable(int val, UnitGenerator & vox, VOperator m) : CVariable((float) val), Effect(vox), mMode(m) { };
00104 DynamicVariable(UnitGenerator & vox, int val, VOperator m) : CVariable((float) val), Effect(vox), mMode(m) { };
00105
00107
00108 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00109
00110 void setValue(float x) { CVariable::setValue(x); };
00111 void setValue(int x) { CVariable::setValue(x); };
00112 void setValue(double x) { CVariable::setValue(x); };
00113 };
00114
00115 #ifdef USE_RANDOMS
00116
00117 #ifdef CSL_ENUMS
00118
00122 typedef enum {
00123 kUniform,
00124 kExponential,
00125 kCauchy,
00126 kNormal,
00127 kChiSq,
00128 kGamma,
00129 kPareto,
00130 kPoisson,
00131 kBinomial,
00132 kNegativeBinomial
00133 } Distribution;
00134
00135 #endif
00136
00140 class RandomVariable : public CVariable, public UnitGenerator {
00141
00142 private:
00143 const static bool copySeedFromDisk = false;
00144 MotherOfAll urng;
00145
00146 Random * mVar;
00147 Distribution mDist;
00148 float mMean;
00149 float mVariance;
00150
00151 public:
00152 RandomVariable(Distribution d, float mean, float variance, float v1, float v2);
00153 ~RandomVariable();
00155 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException);
00156 };
00157
00158 #endif // USE_RANDOMS
00159
00160 }
00161
00162 #endif