00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_SHAREVAR_H__
00020 #define __CS_SHAREVAR_H__
00021
00022 #include "csutil/nobjvec.h"
00023 #include "csutil/csstring.h"
00024 #include "csutil/csobject.h"
00025 #include "csutil/refarr.h"
00026 #include "iengine/sharevar.h"
00027
00028
00029 SCF_VERSION (csSharedVariable, 0, 0, 2);
00030
00034 class csSharedVariable : public csObject
00035 {
00036 private:
00037 int type;
00038 float value;
00039 csColor color;
00040 csVector3 vec;
00041 csRefArray<iSharedVariableListener> listeners;
00042
00043 void FireListeners ();
00044
00045 public:
00046
00047 SCF_DECLARE_IBASE_EXT (csObject);
00048
00053 csSharedVariable () : csObject()
00054 {
00055 SCF_CONSTRUCT_EMBEDDED_IBASE (scfiSharedVariable);
00056 value = 0;
00057 type = iSharedVariable::SV_UNKNOWN;
00058 }
00059
00060 void Set (float val)
00061 {
00062 value = val;
00063 type = iSharedVariable::SV_FLOAT;
00064 FireListeners ();
00065 }
00066
00067 float Get () const
00068 {
00069 return (type == iSharedVariable::SV_FLOAT) ? value : 0;
00070 }
00071
00072 void SetColor (const csColor& col)
00073 {
00074 color.Set(col.red,col.green,col.blue);
00075 type = iSharedVariable::SV_COLOR;
00076 FireListeners ();
00077 }
00078
00079 const csColor& GetColor() const
00080 {
00081 return (type == iSharedVariable::SV_COLOR)
00082 ? color
00083 : csColor (0,0,0),color;
00084 }
00085
00086 void SetVector (const csVector3& v)
00087 {
00088 vec = v;
00089 type = iSharedVariable::SV_VECTOR;
00090 FireListeners ();
00091 }
00092
00093 const csVector3& GetVector() const
00094 {
00095 return (type == iSharedVariable::SV_VECTOR) ? vec : csVector3 (0,0,0),vec;
00096 }
00097
00098 int GetType () const
00099 {
00100 return type;
00101 }
00102
00103 void AddListener (iSharedVariableListener* listener)
00104 {
00105 listeners.Push (listener);
00106 }
00107
00108 void RemoveListener (iSharedVariableListener* listener)
00109 {
00110 listeners.Delete (listener);
00111 }
00112
00113
00114 struct eiSharedVariable : public iSharedVariable
00115 {
00116 SCF_DECLARE_EMBEDDED_IBASE (csSharedVariable);
00117
00118 virtual iObject* QueryObject () { return scfParent; }
00119 virtual void Set(float val)
00120 { scfParent->Set(val); }
00121 virtual float Get() const
00122 { return scfParent->Get(); }
00123 virtual void SetName (const char *iName)
00124 { scfParent->SetName(iName); }
00125 virtual const char *GetName () const
00126 { return scfParent->GetName(); }
00127 virtual void SetColor (const csColor& color)
00128 { scfParent->SetColor (color); }
00129 virtual const csColor& GetColor() const
00130 { return scfParent->GetColor(); }
00131 virtual void SetVector (const csVector3& v)
00132 { scfParent->SetVector (v); }
00133 virtual const csVector3& GetVector () const
00134 { return scfParent->GetVector (); }
00135 int GetType () const
00136 { return scfParent->GetType (); }
00137 virtual void AddListener (iSharedVariableListener* listener)
00138 {
00139 scfParent->AddListener (listener);
00140 }
00141 virtual void RemoveListener (iSharedVariableListener* listener)
00142 {
00143 scfParent->RemoveListener (listener);
00144 }
00145 } scfiSharedVariable;
00146 friend struct eiSharedVariable;
00147 };
00148
00150 class csSharedVariableList : public csRefArrayObject<iSharedVariable>
00151 {
00152 public:
00153 SCF_DECLARE_IBASE;
00154
00156 csSharedVariableList ();
00158 virtual ~csSharedVariableList ();
00159
00161 csPtr<iSharedVariable> New() const;
00162
00163 class SharedVariableList : public iSharedVariableList
00164 {
00165 public:
00166 SCF_DECLARE_EMBEDDED_IBASE (csSharedVariableList);
00167
00168 virtual int GetCount () const;
00169 virtual iSharedVariable *Get (int n) const;
00170 virtual int Add (iSharedVariable *obj);
00171 virtual bool Remove (iSharedVariable *obj);
00172 virtual bool Remove (int n);
00173 virtual void RemoveAll ();
00174 virtual int Find (iSharedVariable *obj) const;
00175 virtual iSharedVariable *FindByName (const char *Name) const;
00176 virtual csPtr<iSharedVariable> New() const
00177 { return scfParent->New(); }
00178 } scfiSharedVariableList;
00179 };
00180
00181 #endif // __CS_SHAREVAR_H__
00182