Model.h revision 10447:a465576671d4
1#ifndef __DSENT_MODEL_MODEL_H__
2#define __DSENT_MODEL_MODEL_H__
3
4#include <vector>
5
6#include "util/CommonType.h"
7
8namespace DSENT
9{
10    using std::vector;
11
12    class TechModel;
13    class Result;
14
15    // Base class for all the models
16    class Model
17    {
18        protected:
19            class SubModel
20            {
21                public:
22                    SubModel(Model* model_, double num_models_);
23                    ~SubModel();
24
25                public:
26                    Model* getModel();
27                    const Model* getModel() const;
28                    double getNumModels() const;
29
30                    SubModel* clone() const;
31
32                protected:
33                    SubModel(const SubModel& sub_model_);
34
35                private:
36                    // Pointer to the actual model instance
37                    Model* m_model_;
38                    // Number of models are added
39                    double m_num_models_;
40            };
41
42        public:
43            // Model Constants
44            static const char TYPE_SEPARATOR[];
45            static const char HIERARCHY_SEPARATOR[];
46            static const char SUBFIELD_SEPARATOR[];
47            static const char DETAIL_SEPARATOR[];
48
49        public:
50            Model(const String& instance_name_, const TechModel* tech_model_);
51            virtual ~Model();
52
53        public:
54            // Set the name of this instance
55            void setInstanceName(const String& instance_name_);
56            // Get the name of this instance
57            const String& getInstanceName() const;
58
59            // Set if the model is the top model
60            void setIsTopModel(bool is_top_model_);
61            bool getIsTopModel() const;
62
63            // Add a parameter name (with and without default)
64            void addParameterName(const String& parameter_name_);
65            void addParameterName(const String& parameter_name_, const String& parameter_default_);
66            const vector<String>* getParameterNames() const;
67
68            // Add a property name
69            void addPropertyName(const String& property_name_);
70            void addPropertyName(const String& property_name_, const String& property_default_);
71            const vector<String>* getPropertyNames() const;
72
73            // Check if all parameters needed exist in the m_parameters_
74            void checkParameters() const;
75            // Check if all properties needed exist in the m_properties_
76            void checkProperties() const;
77
78            // Get the pointer to parameters
79            const ParameterMap* getParameters() const;
80            const String getParameter(const String& parameter_name_) const;
81            void setParameter(const String& parameter_name_, const String& parameter_value_);
82
83            // Get the pointer to properties
84            const PropertyMap* getProperties() const;
85            const String getProperty(const String& property_name_) const;
86            void setProperty(const String& property_name_, const String& property_value_);
87
88            // Get the pointer to generated properties
89            PropertyMap* getGenProperties();
90            const PropertyMap* getGenProperties() const;
91
92            // Add an instance to this model. num_sub_instances_ specifies the
93            // number of the same instance is added.
94            void addSubInstances(Model* sub_instance_, double num_sub_instances_);
95            // Get an instance by name.
96            Model* getSubInstance(const String& sub_instance_name_);
97            const Model* getSubInstance(const String& sub_instance_name_) const;
98            // Check if an instance exists
99            bool hasSubInstance(const String& sub_instance_name_) const;
100
101            // Add a new area
102            void addAreaResult(Result* area_);
103            // Get the pointer to an area. The area is specified by name.
104            Result* getAreaResult(const String& area_name_);
105            const Result* getAreaResult(const String& area_name_) const;
106            // Check if an area exists
107            bool hasAreaResult(const String& area_name_) const;
108
109            // Add a new ndd_power
110            void addNddPowerResult(Result* ndd_power_);
111            // Get the pointer to an ndd_power. The ndd_power is specified by name.
112            Result* getNddPowerResult(const String& ndd_power_name_);
113            const Result* getNddPowerResult(const String& ndd_power_name_) const;
114            // Check if a ndd_power exists
115            bool hasNddPowerResult(const String& ndd_power_name_) const;
116
117            // Add a new event
118            void addEventResult(Result* event_);
119            // Get the pointer to an event. The event is specified by name.
120            Result* getEventResult(const String& event_name_);
121            const Result* getEventResult(const String& event_name_) const;
122            // Check if an event exists
123            bool hasEventResult(const String& event_name_) const;
124
125            // Get the pointer to the TechModel.
126            const TechModel* getTechModel() const;
127
128            // Clone and return a new instance
129            virtual Model* clone() const;
130
131            // Checks to make sure all required parameters are present, makes sure that the model
132            // has not been constructed yet, and calls constructModel. This function is not meant
133            // to be overwritten by child classes; constructModel should be overwritten instead
134            void construct();
135            // Update checks whether the model needs updating, whether all properties have been specified,
136            // and calls updateModel if update is necessary. This function is not meant
137            // to be overwritten by child classes; updateModel should be overwritten instead
138            void update();
139            // Evaluate checks whether the model needs to be evaluated. Note that this function is
140            // not meant to be overwritten by child classes; evaluateModel should be overwritten
141            // instead
142            void evaluate();
143            void use(const String& event_name_);
144            void use();
145
146            // Resolve query hierarchy and process query
147            const void* parseQuery(const String& query_type_, const String& query_hier_, const String& query_sub_field_);
148            // Process the query
149            virtual const void* processQuery(const String& query_type_, const String& query_sub_field_);
150
151            // Print hierarchically
152            void printHierarchy(const String& query_type_, const String& query_sub_field_, const String& prepend_str_, int detail_level_, ostream& ost_) const;
153            void printInstHierarchy(const String& prepend_str_, int detail_level_, ostream& ost_) const;
154
155        protected:
156            // Query area
157            const Result* queryArea(const String& area_name_) const;
158            // Query non-data-dependent power
159            const Result* queryNddPower(const String& ndd_power_name_);
160            // Query event energy cost
161            const Result* queryEventEnergyCost(const String& event_name_);
162
163            // Constructs the model
164            virtual void constructModel() = 0;
165            // Updates timing related information of the model
166            virtual void updateModel();
167            // Evaluate non data dependent power of the model
168            virtual void evaluateModel();
169            virtual void useModel(const String& event_name_);
170            virtual void useModel();
171
172        private:
173            // Private copy constructor. Use clone to perform copy operation.
174            Model(const Model& model_);
175
176        private:
177            // Name of this instance
178            String m_instance_name_;
179            // Set if this model is the top model
180            bool m_is_top_model_;
181
182            // Contains the parameters of a model
183            // Parameters are needed in order to constructModel() and CANNOT be
184            // changed after constructModel() has been called
185            ParameterMap* m_parameters_;
186            // Contains the names of all model parameters
187            vector<String>* m_parameter_names_;
188            // Contains the properties of a model
189            // Properties are required in order to updateModel() and CAN be
190            // changed be changed after constructModel(). Call updateModel()
191            // after properties have been changed to use the new properties
192            PropertyMap* m_properties_;
193            // Contains the property names needed to update the model
194            vector<String>* m_property_names_;
195            // Contains generated properties of the model
196            // Generated properties are used mostly as a scratch space for
197            // variables used in the model that must be passed from one
198            // function to another
199            PropertyMap* m_generated_properties_;
200
201            // Contains the instances of this model
202            Map<SubModel*>* m_sub_instances_;
203            // Contains the area resulst of a model
204            Map<Result*>* m_area_map_;
205            // Contains the noo power results of a model
206            Map<Result*>* m_ndd_power_map_;
207            // Contains the event results of a model
208            Map<Result*>* m_event_map_;
209            // Pointer to a TechModel which contains the technology information
210            const TechModel* m_tech_model_;
211
212            // Set when a model is constructed
213            bool m_constructed_;
214            // Set when a model is updated
215            bool m_updated_;
216            // Set when a model is evaluated
217            bool m_evaluated_;
218
219    }; // class Model
220} // namespace DSENT
221
222#endif // __DSENT_MODEL_MODEL_H__
223
224