Manifest.h
Go to the documentation of this file.
00001 //
00002 // Manifest.h
00003 //
00004 // $Id: //poco/1.3/Foundation/include/Poco/Manifest.h#1 $
00005 //
00006 // Library: Foundation
00007 // Package: SharedLibrary
00008 // Module:  ClassLoader
00009 //
00010 // Definition of the Manifest class.
00011 //
00012 // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
00013 // and Contributors.
00014 //
00015 // Permission is hereby granted, free of charge, to any person or organization
00016 // obtaining a copy of the software and accompanying documentation covered by
00017 // this license (the "Software") to use, reproduce, display, distribute,
00018 // execute, and transmit the Software, and to prepare derivative works of the
00019 // Software, and to permit third-parties to whom the Software is furnished to
00020 // do so, all subject to the following:
00021 // 
00022 // The copyright notices in the Software and this entire statement, including
00023 // the above license grant, this restriction and the following disclaimer,
00024 // must be included in all copies of the Software, in whole or in part, and
00025 // all derivative works of the Software, unless such copies or derivative
00026 // works are solely in the form of machine-executable object code generated by
00027 // a source language processor.
00028 // 
00029 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00030 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00031 // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
00032 // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
00033 // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
00034 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00035 // DEALINGS IN THE SOFTWARE.
00036 //
00037 
00038 
00039 #ifndef Foundation_Manifest_INCLUDED
00040 #define Foundation_Manifest_INCLUDED
00041 
00042 
00043 #include "Poco/Foundation.h"
00044 #include "Poco/MetaObject.h"
00045 #include <map>
00046 #include <typeinfo>
00047 
00048 
00049 namespace Poco {
00050 
00051 
00052 class Foundation_API ManifestBase
00055 {
00056 public:
00057         ManifestBase();
00058         virtual ~ManifestBase();
00059 
00060         virtual const char* className() const = 0;
00062 };
00063 
00064 
00065 template <class B>
00066 class Manifest: public ManifestBase
00073 {
00074 public:
00075         typedef AbstractMetaObject<B> Meta;
00076         typedef std::map<std::string, const Meta*> MetaMap;
00077 
00078         class Iterator
00080         {
00081         public:
00082                 Iterator(const typename MetaMap::const_iterator& it)
00083                 {
00084                         _it = it;
00085                 }
00086                 Iterator(const Iterator& it)
00087                 {
00088                         _it = it._it;
00089                 }
00090                 ~Iterator()
00091                 {
00092                 }
00093                 Iterator& operator = (const Iterator& it)
00094                 {
00095                         _it = it._it;
00096                         return *this;
00097                 }
00098                 inline bool operator == (const Iterator& it) const
00099                 {
00100                         return _it == it._it;
00101                 }
00102                 inline bool operator != (const Iterator& it) const
00103                 {
00104                         return _it != it._it;
00105                 }
00106                 Iterator& operator ++ () // prefix
00107                 {
00108                         ++_it;
00109                         return *this;
00110                 }
00111                 Iterator operator ++ (int) // postfix
00112                 {
00113                         Iterator result(_it);
00114                         ++_it;
00115                         return result;
00116                 }
00117                 inline const Meta* operator * () const
00118                 {
00119                         return _it->second;
00120                 }
00121                 inline const Meta* operator -> () const
00122                 {
00123                         return _it->second;
00124                 }
00125                 
00126         private:
00127                 typename MetaMap::const_iterator _it;
00128         };
00129 
00130         Manifest()
00132         {
00133         }
00134 
00135         virtual ~Manifest()
00137         {
00138                 clear();
00139         }
00140 
00141         Iterator find(const std::string& className) const
00145         {
00146                 return Iterator(_metaMap.find(className));
00147         }
00148 
00149         Iterator begin() const
00150         {
00151                 return Iterator(_metaMap.begin());
00152         }
00153 
00154         Iterator end() const
00155         {
00156                 return Iterator(_metaMap.end());
00157         }
00158 
00159         bool insert(const Meta* pMeta)
00163         {
00164                 return _metaMap.insert(typename MetaMap::value_type(pMeta->name(), pMeta)).second;
00165         }
00166 
00167         void clear()
00169         {
00170                 for (typename MetaMap::iterator it = _metaMap.begin(); it != _metaMap.end(); ++it)
00171                 {
00172                         delete it->second;
00173                 }
00174                 _metaMap.clear();
00175         }
00176 
00177         int size() const
00179         {
00180                 return int(_metaMap.size());
00181         }
00182 
00183         bool empty() const
00185         {
00186                 return _metaMap.empty();
00187         }
00188 
00189         const char* className() const
00190         {
00191                 return typeid(*this).name();
00192         }
00193 
00194 private:
00195         MetaMap _metaMap;
00196 };
00197 
00198 
00199 } // namespace Poco
00200 
00201 
00202 #endif // Foundation_Manifest_INCLUDED


pluginlib
Author(s): Tully Foote and Eitan Marder-Eppstein
autogenerated on Sat Dec 28 2013 17:20:19