Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef XFormulaAutomatonH
00033 #define XFormulaAutomatonH
00034
00035 #include <zeusmath/System/Interfaces/IXFormulaAutomaton.hpp>
00036 #include <zeusmath/System/Interfaces/IAngle.hpp>
00037 #include <zeusbase/System/SingleLinkedList.hpp>
00038 #include <zeusbase/System/XObject.h>
00039 #include <zeusbase/System/VariableResolver.h>
00040 #include <zeusbase/System/StringMap.hpp>
00041 #include <zeusbase/System/Set.hpp>
00042 #include <zeusbase/System/XObjectFactory.h>
00043
00044 BEGIN_NAMESPACE_Zeus
00045
00046 class TFormulaParser;
00047 class IXFormulaAutomatonObserver;
00048
00049
00053
00054 zeusmath_class TXFormulaAutomaton : public TXObject, public IXFormulaAutomaton
00055 {
00056 public:
00057 TXFormulaAutomaton(IXMLNode& rNode);
00058
00059
00060 virtual Retval MQUALIFIER getValue(const IString& rName, Float& rfValue);
00061 virtual bool MQUALIFIER isLocked() const;
00062 virtual bool MQUALIFIER isValid() const;
00063 virtual void MQUALIFIER lockEvaluation();
00064 virtual void MQUALIFIER unlockEvaluation();
00065 virtual Retval MQUALIFIER setInputValue(const IString& rName, const Float& rfValue);
00066
00067
00068 virtual bool MQUALIFIER freeze();
00069 virtual bool MQUALIFIER unfreeze();
00070
00071
00072 virtual Retval MQUALIFIER attach(IObserver& rObserver);
00073 virtual Retval MQUALIFIER detach(IObserver& rObserver);
00074
00075
00076 MEMORY_MANAGER_DECL
00077
00078 REG_SUB_BEGIN(TXFormulaAutomaton)
00079 REG_SUB_ADD(TXFormulaAutomaton, L"TXFormulaAutomaton");
00080 REG_SUB_END
00081
00082 protected:
00083 virtual ~TXFormulaAutomaton();
00084
00085 Retval evaluate_internal(bool bAll);
00086
00087 private:
00088
00091
00092 class TPredicate : public TVariableResolver
00093 {
00094 public:
00095 TPredicate(IXMLNode& rNode, IAngle::ESystem eAngleSystem);
00096
00097 void attachObserver(IXFormulaAutomatonObserver& rObserver);
00098 void detachObserver(IXFormulaAutomatonObserver& rObserver);
00099 Retval calculateValue(TSet<TPredicate*>& rSetOfUnCalculatedPredicates);
00100
00101 inline Float getCalculationValue() const { return m_fValue; }
00102 inline TString getCondition() const { return m_strCondition; }
00103 inline TString getFormula() const { return m_mapFormula.getItemConst(TString(L"")); }
00104 inline TString getFormula(const TString& rConditionValue) const { return m_mapFormula.getItemConst(rConditionValue); }
00105 inline TString getName() const { return m_strName; }
00106 inline bool isCalculated() const { return m_bCalculated; }
00107 inline bool isValid() const { return m_bValid; }
00108
00109 void resetCalculationValue();
00110 inline void setCalculationValue(const Float& rValue) { m_fValue = rValue; }
00111
00112 void resolveDependancies(TStringMap<TPredicate*>& rMap);
00113 void releaseDependancies();
00114 void releaseObservers();
00115
00116 protected:
00117 virtual ~TPredicate();
00118 void addPredecessor(TPredicate& rPredicate);
00119 void addSuccessor(TPredicate& rPredicate);
00120 void notifyObservers();
00121
00122
00123 virtual Retval resolveVariable(const TString& rName, TString& rValue);
00124
00125 private:
00127 IXMLNode& m_rNode;
00129 TString m_strName;
00131 TString m_strCondition;
00133 TStringMap<TString> m_mapFormula;
00135 bool m_bCalculated;
00137 bool m_bValid;
00139 Float m_fValue;
00141 TStringMap<TPredicate*> m_mapPredecessors;
00143 TStringMap<TPredicate*> m_mapSuccessors;
00145 IAngle::ESystem m_eAngleSystem;
00147 TSingleLinkedList<IXFormulaAutomatonObserver*> m_lstObservers;
00148 };
00149
00151 Int m_iLock;
00153 TStringMap<TPredicate*> m_mapInputVariables;
00155 TStringMap<TPredicate*> m_mapPredicates;
00157 TStringMap<TPredicate*> m_mapOutputVariables;
00158
00159 void releaseInstances();
00160 };
00161
00162
00165
00166 inline bool MQUALIFIER TXFormulaAutomaton::isLocked() const
00167 {
00168 return (m_iLock > 0);
00169 }
00170
00171
00174
00175 inline void MQUALIFIER TXFormulaAutomaton::lockEvaluation()
00176 {
00177 ++m_iLock;
00178 }
00179
00180
00183
00184 inline void MQUALIFIER TXFormulaAutomaton::unlockEvaluation()
00185 {
00186 m_iLock--;
00187 if (m_iLock <= 0)
00188 {
00189 m_iLock = 0;
00190 evaluate_internal(true);
00191 }
00192 }
00193
00194 END_NAMESPACE_Zeus
00195
00196 #endif