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 namespace simth {
00041 
00042   class DeviceDescriptionPriv;
00043   class DeviceManagerPriv;
00044 
00058   class DLLIMPORT DeviceDescription {
00059     friend class DeviceManager;
00060   public:
00061     class IfaceDescr {
00062       public:
00063       IfaceDescr();
00064       IfaceDescr(const std::string& type, 
00065          const std::string& description, 
00066          const std::string& multiplied_by = "");
00068       std::string type;
00070       std::string description;
00077       std::string multiplied_by;
00078     };
00079     typedef std::vector<IfaceDescr> IfaceList;
00080   private:
00081     DeviceDescriptionPriv *d_ptr;
00082 
00083     // Constructor with new private object
00084     DeviceDescription(DeviceDescriptionPriv *d_ptr);
00085 
00086   public:
00088     DeviceDescription();
00090     DeviceDescription(const DeviceDescription&);
00092     DeviceDescription& operator=(const DeviceDescription&);
00094     ~DeviceDescription();
00095     
00097     bool operator==(const DeviceDescription& d) const;
00098 
00101     bool operator<(const DeviceDescription& d) const;
00102 
00106     const std::string &name() const ;
00107 
00111     const std::string &type() const ;
00112 
00117     const std::string &extends() const ;
00118 
00125     const std::string &type_escaped() const ;
00126 
00128     unsigned nr_input_interfaces() const;
00130     unsigned nr_output_interfaces() const;
00134     const DeviceDescription::IfaceList& input_interfaces() const;
00138     const DeviceDescription::IfaceList& output_interfaces() const;
00139 
00143     const PropertyList &properties() const;
00144 
00148     const Property::list_string &libraries() const;
00149 
00154     bool isAbstract() const;
00155 
00159     const std::string& description() const;
00160 
00162     void toStream(std::ostream &os) const;
00163 
00168     static std::string typename_escape(const std::string& s);
00169     
00174     static std::string typename_unescape(const std::string& s);
00175   };
00176 
00177 
00178 
00179 
00218   class DLLIMPORT DeviceManager {
00219     friend class DeviceManagerPriv;
00220   public:
00222     typedef simth::DeviceDescription DeviceDescription;
00223 
00225     typedef std::string DDMapKey;
00226 
00247     typedef std::map<DDMapKey, DeviceDescription> DDMap;
00248 
00250     typedef std::vector<DeviceDescription> DeviceDescriptionList;
00251 
00252   private:
00253     typedef Property::list_string list_string;
00254     list_string _folderlist;
00255 
00256     // For a given non-absolute filename, check whether it can be
00257     // found in the search path. Return the absolute filename if yes.
00258     std::string _getFilePath(const std::string &fname) const 
00259     throw(file_not_found);
00260 
00261     // Replace all whitespace characters (tab, newline etc) in a
00262     // string with one whitespace.
00263     static std::string condensedString(const std::string &s);
00264 
00265   public:
00275     DeviceManager(const std::string &folder="");
00276 
00280     virtual ~DeviceManager();
00281 
00284     const std::string& folder() const throw();
00285 
00288     const Property::list_string& folderlist() const throw();
00289 
00302     DDMap allAvailableDescriptions()
00303     throw(bad_device_file, bad_device_description, type_error);
00304 
00309     DeviceDescriptionList allAvailableDescriptionsList()
00310     throw(bad_device_file, bad_device_description, type_error);
00311 
00332     DeviceDescriptionList
00333       allDescriptionsFromFile(const std::string &fname)
00334     throw(file_not_found, bad_device_file, bad_device_description, 
00335           type_error);
00336 
00358     DeviceDescription descriptionFromFile(const std::string &fname,
00359                                           const std::string &dname)
00360     throw(file_not_found, bad_device_file, device_not_found, type_error);
00361 
00364     Property::list_string allXMLFiles() const;
00365 
00369     static bool string_to_bool(const std::string abstr);
00371 
00372   };
00373 
00374 #ifndef __GNUC__
00377   EXPIMP_TEMPLATE template DLLIMPORT DeviceManager::DDMap;
00378   EXPIMP_TEMPLATE template DLLIMPORT DeviceManager::DeviceDescriptionList;
00379 #endif
00380 
00382   std::ostream& operator<<(std::ostream&os, const DeviceManager::DDMap& dds);
00383 
00384 } /* namespace */
00385 
00386 
00387 #endif /* SIMTHETIC_DEVICEMANAGER_H */
00388 
00389 
00390 

Generated on Mon Apr 24 21:19:19 2006 for simthetic by  doxygen 1.4.1