ZeusMath-Library  2.0.4
XFormulaAutomaton.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Math Library
5  * Module : XFormulaAutomaton
6  * Package : Zeus.ZeusMath.System
7  * Author : Benjamin Hadorn
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef XFormulaAutomatonH
33 #define XFormulaAutomatonH
34 
37 #include <zeusbase/System/SingleLinkedList.hpp>
38 #include <zeusbase/System/XObject.h>
39 #include <zeusbase/System/VariableResolver.h>
40 #include <zeusbase/System/StringMap.hpp>
41 #include <zeusbase/System/Set.hpp>
42 #include <zeusbase/System/XObjectFactory.h>
43 
44 BEGIN_NAMESPACE_Zeus
45 
46 class TFormulaParser;
47 class IXFormulaAutomatonObserver;
48 
49 /*****************************************************************************/
53 /*****************************************************************************/
55 {
56  public:
57  TXFormulaAutomaton(IXMLNode& rNode);
58 
59  //Methods of IXFormulaAutomaton
60  virtual Retval MQUALIFIER getValue(const IString& rName, Float& rfValue);
61  virtual bool MQUALIFIER isLocked() const;
62  virtual bool MQUALIFIER isValid() const;
63  virtual void MQUALIFIER lockEvaluation();
64  virtual void MQUALIFIER unlockEvaluation();
65  virtual Retval MQUALIFIER setInputValue(const IString& rName, const Float& rfValue);
66 
67  //Methods of IXObject
68  virtual bool MQUALIFIER freeze();
69  virtual bool MQUALIFIER unfreeze();
70 
71  //Methods of ISubject
72  virtual Retval MQUALIFIER attach(IObserver& rObserver);
73  virtual Retval MQUALIFIER detach(IObserver& rObserver);
74 
75  //Methods of IZUnknown
76  MEMORY_MANAGER_DECL
77 
78  REG_SUB_BEGIN(TXFormulaAutomaton)
79  REG_SUB_ADD(TXFormulaAutomaton, L"TXFormulaAutomaton");
80  REG_SUB_END
81 
82  protected:
83  virtual ~TXFormulaAutomaton();
84 
85  Retval evaluate_internal(bool bAll);
86 
87  private:
88  /************************************************************************/
91  /************************************************************************/
92  class TPredicate : public TVariableResolver
93  {
94  public:
95  TPredicate(IXMLNode& rNode, IAngle::ESystem eAngleSystem);
96 
97  void attachObserver(IXFormulaAutomatonObserver& rObserver);
98  void detachObserver(IXFormulaAutomatonObserver& rObserver);
99  Retval calculateValue(TSet<TPredicate*>& rSetOfUnCalculatedPredicates);
100 
101  inline Float getCalculationValue() const { return m_fValue; }
102  inline TString getCondition() const { return m_strCondition; }
103  inline TString getFormula() const { return m_mapFormula.getItemConst(TString(L"")); }
104  inline TString getFormula(const TString& rConditionValue) const { return m_mapFormula.getItemConst(rConditionValue); }
105  inline TString getName() const { return m_strName; }
106  inline bool isCalculated() const { return m_bCalculated; }
107  inline bool isValid() const { return m_bValid; }
108 
109  void resetCalculationValue();
110  inline void setCalculationValue(const Float& rValue) { m_fValue = rValue; }
111 
112  void resolveDependancies(TStringMap<TPredicate*>& rMap);
113  void releaseDependancies();
114  void releaseObservers();
115 
116  protected:
117  virtual ~TPredicate();
118  void addPredecessor(TPredicate& rPredicate);
119  void addSuccessor(TPredicate& rPredicate);
120  void notifyObservers();
121 
122  //Method of TVariableResolver
123  virtual Retval resolveVariable(const TString& rName, TString& rValue);
124 
125  private:
127  IXMLNode& m_rNode;
129  TString m_strName;
131  TString m_strCondition;
133  TStringMap<TString> m_mapFormula;
135  bool m_bCalculated;
137  bool m_bValid;
139  Float m_fValue;
141  TStringMap<TPredicate*> m_mapPredecessors;
143  TStringMap<TPredicate*> m_mapSuccessors;
145  IAngle::ESystem m_eAngleSystem;
147  TSingleLinkedList<IXFormulaAutomatonObserver*> m_lstObservers;
148  };
149 
151  Int m_iLock;
153  TStringMap<TPredicate*> m_mapInputVariables;
155  TStringMap<TPredicate*> m_mapPredicates;
157  TStringMap<TPredicate*> m_mapOutputVariables;
158 
159  void releaseInstances();
160 };
161 
162 /*****************************************************************************/
165 /*****************************************************************************/
166 inline bool MQUALIFIER TXFormulaAutomaton::isLocked() const
167 {
168  return (m_iLock > 0);
169 }
170 
171 /*****************************************************************************/
174 /*****************************************************************************/
175 inline void MQUALIFIER TXFormulaAutomaton::lockEvaluation()
176 {
177  ++m_iLock;
178 }
179 
180 /*****************************************************************************/
183 /*****************************************************************************/
184 inline void MQUALIFIER TXFormulaAutomaton::unlockEvaluation()
185 {
186  m_iLock--;
187  if (m_iLock <= 0)
188  {
189  m_iLock = 0;
190  evaluate_internal(true);
191  }
192 }
193 
194 END_NAMESPACE_Zeus
195 
196 #endif
Definition: IXFormulaAutomaton.hpp:48
#define zeusmath_class
Definition: PlatformDefines.hpp:48
Definition: IXFormulaAutomatonObserver.hpp:50
ESystem
Definition: IAngle.hpp:53
Definition: XFormulaAutomaton.h:54


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Wed Sep 14 2016 06:45:54