00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 #ifndef __DSIM_VARIABLE__
00011 #define __DSIM_VARIABLE__
00012 
00013 #include <MatrixLib/MatrixLib.h>
00014 #include "dsim_value.h"
00015 #include "dsim_exceptions.h"
00016 #include <map>
00017 
00018 class dsim_variable_record;
00019 
00029 class dsim_variable
00030 {
00031     public:
00033         dsim_variable();
00035         dsim_variable(const dsim_variable &base);
00037         dsim_variable &operator=(const dsim_variable &base);
00038         
00039         ~dsim_variable();
00040         
00046         enum dsim_variable_usage {  dsim_invalid_value=0, 
00047                                     dsim_parameter_value=1, 
00048                                     dsim_input_value=2, 
00049                                     dsim_output_value=3, 
00050                                     dsim_state_value=4, 
00051                                     dsim_integrated_value=5 
00052                                  };
00053         
00055         inline bool valid() const { return _record?true:false; }
00057         dsim_variable::dsim_variable_usage usage() const;
00058         
00059         
00061         int type() const;
00063         dsim_value value() const;
00065         dsim_value base_value() const;
00067         dsim_value cointegrated_value() const;
00069         void *raw_value() const;
00071         bool extract_raw_value(void *destination) const;
00073         const char *units() const;
00075         const char *description() const;
00077         int nominal_rows() const;
00079         int nominal_columns() const;
00081         void set_nominal_dimensions(int rows,int columns);
00082         
00084         bool cointegrated() const { return _cointegrated; }
00086         void set_cointegrated(bool flag) { _cointegrated = flag; }
00087         
00089         int value_as_int() const;
00091         void set_value_as_int(int val);
00093         double value_as_double() const;
00095         void set_value_as_double(double val);
00097         ml_matrix value_as_matrix() const;
00099         void set_value_as_matrix(const ml_matrix &val);
00101         const char *value_as_string() const;
00103         void set_value_as_string(const char *val);
00104         
00106         void set_value(int type,void *new_value);
00108         void set_value(const dsim_value &new_value);
00109         
00111         void set_derivative(int type,void *deriv) throw(dsim_type_mismatch_exception);
00113         void set_derivative(const dsim_value &deriv) throw(dsim_type_mismatch_exception);
00115         dsim_value derivative() const;
00116         
00117         void start_integration();
00118         void finish_integration();
00119         
00121         void *integration_ptr();
00123         void set_integration_ptr(void *ptr);
00124         
00125         void write_string_representation(FILE *file);
00126         
00127         bool parse_value_from_string(const char *str);
00128         void unpack_value_from_data(unsigned int length,void *data);
00129         
00131         void set_attribute(const std::string &name,const std::string &value);
00133         bool has_attribute(const std::string &name);
00135         std::string get_attribute(const std::string &name);
00137         std::map<std::string,std::string>::iterator attribute_iterator();
00139         std::map<std::string,std::string>::iterator end_attribute_iterator();
00140         
00142         void mark_telemetry();
00144         void mark_command();
00146         void mark_command_and_telemetry();
00148         void mark_telemetry_and_command();
00150         bool is_telemetry() const;
00152         bool is_command() const;
00153         
00155         bool has_changed() const;
00157         void mark_unchanged();
00158     
00159     private:
00160         dsim_variable(dsim_variable_record *record,bool read_only);
00161         void *record_ptr() const;
00162         
00163         dsim_variable_record *_record;
00164         bool _read_only;
00165         bool _cointegrated;
00166         
00167     friend class dsim_variable_record;
00168 };
00169 
00170 #endif