All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ModelInstance.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
5 
6 
7  == GNU General Public License Usage ==
8 
9  OpenFLUID is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OpenFLUID is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21 
22 
23  == Other Usage ==
24 
25  Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26  license, and requires a written agreement between You and INRA.
27  Licensees for Other Usage of OpenFLUID may use this file in accordance
28  with the terms contained in the written agreement between You and INRA.
29 
30 */
31 
32 
33 
34 /**
35  @file ModelInstance.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38  */
39 
40 
41 #ifndef __OPENFLUID_MACHINE_MODELINSTANCE_HPP__
42 #define __OPENFLUID_MACHINE_MODELINSTANCE_HPP__
43 
44 #include <list>
45 
46 #include <openfluid/dllexport.hpp>
51 
52 
53 
54 namespace openfluid { namespace ware {
55 
56 class PluggableSimulator;
57 
58 } }
59 
60 
61 namespace openfluid { namespace machine {
62 
63 class MachineListener;
64 class SimulationBlob;
65 class ModelItemInstance;
66 
67 
69 {
70  private:
71 
72  std::list<ModelItemInstance*> m_ModelItems;
73 
75 
77 
79 
80  openfluid::machine::SimulationBlob& m_SimulationBlob;
81 
82  std::list<ExecutionTimePoint> m_TimePointList;
83 
84  openfluid::ware::WareParams_t m_GlobalParams;
85 
86  bool m_Initialized;
87 
88  void appendItemToTimePoint(openfluid::core::TimeIndex_t TimeIndex, openfluid::machine::ModelItemInstance* Item);
89 
90  void checkDeltaTMode(openfluid::base::SchedulingRequest& SReq, const openfluid::ware::WareID_t& ID);
91 
92  protected:
93 
94  openfluid::ware::WareParams_t mergeParamsWithGlobalParams(const openfluid::ware::WareParams_t& Params) const;
95 
96 
97  public:
98 
101 
102  ~ModelInstance();
103 
104  void appendItem(ModelItemInstance* ItemInstance);
105 
106  /**
107  Insert a ModelItemInstance before the given postion (positions starts at index 0)
108  @param[in] ItemInstance the ModelItemInstance to insert
109  @param[in] Position the position
110  */
111  void insertItem(ModelItemInstance* ItemInstance, unsigned int Position);
112 
113  /**
114  Delete the ModelItemInstance located at the given postion (positions starts at index 0),
115  and remove it from the ModelInstance
116  @param[in] Position the position
117  */
118  void deleteItem(unsigned int Position);
119 
120  void clear();
121 
122  unsigned int getItemsCount() const { return m_ModelItems.size(); };
123 
124  openfluid::ware::WareParams_t& globalParameters() { return m_GlobalParams; };
125 
126  void setGlobalParameter(const openfluid::ware::WareParamKey_t& Key, const openfluid::ware::WareParamValue_t& Value);
127 
128  void setGlobalParameters(const openfluid::ware::WareParams_t& Params) { m_GlobalParams = Params; };
129 
130  const std::list<ModelItemInstance*>& items() const { return m_ModelItems; };
131 
132  void initialize(openfluid::base::SimulationLogger* SimLogger);
133 
134  void finalize();
135 
136  void call_initParams() const;
137 
138  void call_prepareData() const;
139 
140  void call_checkConsistency() const;
141 
142  void call_initializeRun();
143 
144  inline bool hasTimePointToProcess() const
145  { return !m_TimePointList.empty(); };
146 
147  void processNextTimePoint();
148 
150  {
151  if (m_TimePointList.empty()) return -2;
152  return m_TimePointList.front().getTimeIndex();
153  }
154 
155  void call_finalizeRun() const;
156 
157  void resetInitialized() { m_Initialized = false; }
158 
159 };
160 
161 
162 } } //namespaces
163 
164 
165 #endif /* __OPENFLUID_MACHINE_MODELINSTANCE_HPP__ */
openfluid::core::Duration_t getNextTimePointIndex() const
Definition: ModelInstance.hpp:149
Definition: ModelInstance.hpp:68
unsigned long long Duration_t
Definition: DateTime.hpp:68
std::string WareParamKey_t
Definition: TypeDefs.hpp:89
const std::list< ModelItemInstance * > & items() const
Definition: ModelInstance.hpp:130
Definition: SchedulingRequest.hpp:52
void resetInitialized()
Definition: ModelInstance.hpp:157
Definition: SimulationLogger.hpp:59
void setGlobalParameters(const openfluid::ware::WareParams_t &Params)
Definition: ModelInstance.hpp:128
unsigned int getItemsCount() const
Definition: ModelInstance.hpp:122
Definition: SimulationBlob.hpp:50
Definition: SimulationProfiler.hpp:62
Definition: ModelItemInstance.hpp:94
Definition: StringValue.hpp:91
Definition: MachineListener.hpp:55
Abstract class for simulator plugin.
Definition: PluggableSimulator.hpp:105
#define OPENFLUID_API
Definition: dllexport.hpp:87
unsigned long long TimeIndex_t
Definition: DateTime.hpp:62
std::map< WareParamKey_t, WareParamValue_t > WareParams_t
Definition: TypeDefs.hpp:93
bool hasTimePointToProcess() const
Definition: ModelInstance.hpp:144
openfluid::ware::WareParams_t & globalParameters()
Definition: ModelInstance.hpp:124
std::string WareID_t
Definition: TypeDefs.hpp:50