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
00031 #ifndef SIMTHETIC_DEVICEMANAGER_H
00032 #define SIMTHETIC_DEVICEMANAGER_H
00033
00034 #include <simthetic/propertylist.h>
00035 #include <simthetic/exceptions.h>
00036 #include <string>
00037
00038 #include <map>
00039
00040 typedef struct GWEN__XMLNODE GWEN_XMLNODE;
00041
00042 namespace simth {
00043
00057 class DLLIMPORT DeviceDescription {
00058 friend class DeviceManager;
00059 public:
00060 class IfaceDescr {
00061 public:
00062 IfaceDescr();
00063 IfaceDescr(const std::string& type,
00064 const std::string& description,
00065 const std::string& multiplied_by = "");
00067 std::string type;
00069 std::string description;
00076 std::string multiplied_by;
00077 };
00078 typedef std::vector<IfaceDescr> IfaceList;
00079 private:
00080 std::string _name;
00081 std::string _type;
00082 std::string _type_escaped;
00083 std::string _extends;
00084 PropertyList _properties;
00085 Property::list_string _libraries;
00086 bool _abstract;
00087 std::string _description;
00088 IfaceList _input_interfaces;
00089 IfaceList _output_interfaces;
00090
00091
00092
00093
00094 static void
00095 _readDeviceProperties(PropertyList &pl,
00096 GWEN_XMLNODE *dn,
00097 const std::string &dname,
00098 int depth,
00099 Property::list_string &sl,
00100 IfaceList& input_interfaces,
00101 IfaceList& output_interfaces);
00102
00103
00104
00105 static void _readPropertylistNode(PropertyList &pl,
00106 GWEN_XMLNODE *pnode,
00107 const std::string &dname);
00108
00109
00110
00111 static void _readOverriddenPropNode(PropertyList &pl,
00112 GWEN_XMLNODE *pnode,
00113 const std::string &dname);
00114
00115
00116
00117 static void _readInterfacelistNode(IfaceList& iiflist,
00118 GWEN_XMLNODE *pnode,
00119 const std::string &dname);
00120
00121
00122 DeviceDescription (GWEN_XMLNODE *devicenode,
00123 GWEN_XMLNODE *devicelist,
00124 const std::string& dname);
00125
00126 public:
00128 DeviceDescription();
00130 ~DeviceDescription();
00131
00133 bool operator==(const DeviceDescription& d) const;
00134
00137 bool operator<(const DeviceDescription& d) const;
00138
00142 const std::string &name() const ;
00143
00147 const std::string &type() const ;
00148
00153 const std::string &extends() const ;
00154
00161 const std::string &type_escaped() const ;
00162
00164 unsigned nr_input_interfaces() const;
00166 unsigned nr_output_interfaces() const;
00170 const DeviceDescription::IfaceList& input_interfaces() const;
00174 const DeviceDescription::IfaceList& output_interfaces() const;
00175
00179 const PropertyList &properties() const;
00180
00184 const Property::list_string &libraries() const;
00185
00190 bool isAbstract() const;
00191
00195 const std::string& description() const;
00196
00198 void toStream(std::ostream &os) const;
00199
00204 static std::string typename_escape(const std::string& s);
00205
00210 static std::string typename_unescape(const std::string& s);
00211 };
00212
00213
00214
00215
00254 class DLLIMPORT DeviceManager {
00255
00256 public:
00258 typedef simth::DeviceDescription DeviceDescription;
00259
00261 typedef std::string DDMapKey;
00262
00283 typedef std::map<DDMapKey, DeviceDescription> DDMap;
00284
00286 typedef std::vector<DeviceDescription> DeviceDescriptionList;
00287
00288 private:
00289 typedef Property::list_string list_string;
00290 list_string _folderlist;
00291
00292
00293
00294 std::string _getFilePath(const std::string &fname) const
00295 throw(file_not_found);
00296
00297
00298
00299 GWEN_XMLNODE *_getDevicelistFromFile(const std::string &fname,
00300 GWEN_XMLNODE *rootnode)
00301 throw(file_not_found, bad_device_file);
00302
00303
00304
00305 static std::string condensedString(const std::string &s);
00306
00307 public:
00317 DeviceManager(const std::string &folder="");
00318
00322 virtual ~DeviceManager();
00323
00326 const std::string& folder() const throw();
00327
00330 const Property::list_string& folderlist() const throw();
00331
00344 DDMap allAvailableDescriptions()
00345 throw(bad_device_file, bad_device_description, type_error);
00346
00351 DeviceDescriptionList allAvailableDescriptionsList()
00352 throw(bad_device_file, bad_device_description, type_error);
00353
00374 DeviceDescriptionList
00375 allDescriptionsFromFile(const std::string &fname)
00376 throw(file_not_found, bad_device_file, bad_device_description,
00377 type_error);
00378
00400 DeviceDescription descriptionFromFile(const std::string &fname,
00401 const std::string &dname)
00402 throw(file_not_found, bad_device_file, device_not_found, type_error);
00403
00406 Property::list_string allXMLFiles() const;
00407
00411 static GWEN_XMLNODE *findDeviceNode(GWEN_XMLNODE *dn,
00412 const std::string &dname);
00413
00415 static bool string_to_bool(const std::string abstr);
00416
00418 static std::string getStringData(GWEN_XMLNODE *node);
00419
00422 static GWEN_XMLNODE *findNodeByName(GWEN_XMLNODE *node,
00423 const std::string& node_name,
00424 const std::string& filename,
00425 bool required = true)
00426 throw(simth::bad_device_file);
00428
00429 };
00430
00431 #ifndef __GNUC__
00434 EXPIMP_TEMPLATE template DLLIMPORT DeviceManager::DDMap;
00435 EXPIMP_TEMPLATE template DLLIMPORT DeviceManager::DeviceDescriptionList;
00436 #endif
00437
00439 std::ostream& operator<<(std::ostream&os, const DeviceManager::DDMap& dds);
00440
00441 }
00442
00443
00444 #endif
00445
00446
00447