Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

devicemanager.h

Go to the documentation of this file.
00001 /*-*-c++-*-*****************************************************************
00002  devicemanager.h
00003  ---------------
00004  begin       : Sat Dec 20 2003
00005  copyright   : (C) 2003 by Martin Preuss
00006  email       : martin@libchipcard.de
00007 
00008  ***************************************************************************
00009  *                                                                         *
00010  *   This library is free software; you can redistribute it and/or         *
00011  *   modify it under the terms of the GNU Lesser General Public            *
00012  *   License as published by the Free Software Foundation; either          *
00013  *   version 2.1 of the License, or (at your option) any later version.    *
00014  *                                                                         *
00015  *   This library is distributed in the hope that it will be useful,       *
00016  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00017  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00018  *   Lesser General Public License for more details.                       *
00019  *                                                                         *
00020  *   You should have received a copy of the GNU Lesser General Public      *
00021  *   License along with this library; if not, write to the Free Software   *
00022  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00023  *   MA  02111-1307  USA                                                   *
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 //#include <list>
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     // Read in a propertylist for a given device. If necessary,
00093     // recursively use this function for its parent devices.
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     // Read a propertylist from a node for the given device. No more
00104     // recursion inside here.
00105     static void _readPropertylistNode(PropertyList &pl,
00106                       GWEN_XMLNODE *pnode,
00107                       const std::string &dname);
00108 
00109     // Read the overriddenproperties element here and remove the
00110     // respective elements from the given propertylist
00111     static void _readOverriddenPropNode(PropertyList &pl,
00112                       GWEN_XMLNODE *pnode,
00113                       const std::string &dname);
00114 
00115     // Read a interfacelist from a node for the given device. No
00116     // more recursion inside here.
00117     static void _readInterfacelistNode(IfaceList& iiflist,
00118                        GWEN_XMLNODE *pnode,
00119                        const std::string &dname);
00120 
00121     // Construct a DeviceDescription from the specified devicenode.
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     // For a given non-absolute filename, check whether it can be
00293     // found in the search path. Return the absolute filename if yes.
00294     std::string _getFilePath(const std::string &fname) const 
00295     throw(file_not_found);
00296 
00297     // Read in the given file name into the given rootnode and return
00298     // a pointer to the devicelist node.
00299     GWEN_XMLNODE *_getDevicelistFromFile(const std::string &fname,
00300                      GWEN_XMLNODE *rootnode)
00301     throw(file_not_found, bad_device_file);
00302 
00303     // Replace all whitespace characters (tab, newline etc) in a
00304     // string with one whitespace.
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 } /* namespace */
00442 
00443 
00444 #endif /* SIMTHETIC_DEVICEMANAGER_H */
00445 
00446 
00447 

Generated on Mon Aug 15 13:54:26 2005 for simthetic by  doxygen 1.4.1