00001 /******************************************************************************* 00002 00003 Copyright (C) 2007 by Brendon Costa 00004 00005 This library is free software; you can redistribute it and/or modify 00006 it under the terms of the "LGPL Like" License defined in the file COPYING 00007 that should have been distributed along with this source. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 You should have received a copy of the "LGPL Like" License 00014 along with this library; see the file COPYING. if not, it can be 00015 obtained from the EDoc++ website: 00016 http://edoc.sourceforge.net/license.html 00017 00018 *******************************************************************************/ 00019 #ifndef EDOC_SPECIFICMANAGEDOBJECT_H 00020 #define EDOC_SPECIFICMANAGEDOBJECT_H 00021 00022 #include "EDoc/ManagedObject.h" 00023 #include "EDoc/utils.h" 00024 00025 namespace EDoc 00026 { 00027 00028 //=========================================================================== 00029 /** \brief Provides a managed container for types that are specifically 00030 * derived from StringIdentifiedObject. 00031 * 00032 * Where ManagedObject is a generic container for StringIdentifiedObject's 00033 * this class is a container providing the same functionality but for 00034 * specific class types that derive from StringIdentifiedObject. For example 00035 * this is can contain types: File, Type, FunctionType, Function. 00036 */ 00037 template<typename T> 00038 class SpecificManagedObject : public ManagedObject 00039 { 00040 public: 00041 00042 //------------------------------------------------------------------------ 00043 /** \brief See ManagedObject::ManagedObject() 00044 */ 00045 SpecificManagedObject(Dictionary& dict_in) : 00046 ManagedObject(dict_in) 00047 { 00048 } 00049 00050 //------------------------------------------------------------------------ 00051 /** \brief See ManagedObject::operator=() 00052 */ 00053 SpecificManagedObject& operator=(const SpecificManagedObject& right) 00054 { 00055 ManagedObject::operator=(right); 00056 return *this; 00057 } 00058 00059 //------------------------------------------------------------------------ 00060 /** \brief Creates a new instance of the particular derived type that this 00061 * container manages. 00062 */ 00063 virtual StringIdentifiedObjectPtr New(Dictionary& dict, std::string name) 00064 { 00065 T* item = NULL; 00066 AllocNew(item, dict, name); 00067 return item; 00068 } 00069 00070 00071 //------------------------------------------------------------------------ 00072 /** \brief See ManagedObject::CGet() 00073 */ 00074 inline T* Get(std::string name) 00075 { 00076 return dynamic_cast<T*>(CGet(name)); 00077 } 00078 00079 //------------------------------------------------------------------------ 00080 /** \brief See ManagedObject::CGet() 00081 */ 00082 inline const T* Get(std::string name) const 00083 { 00084 return dynamic_cast<const T*>(CGet(name)); 00085 } 00086 00087 //------------------------------------------------------------------------ 00088 /** \brief See ManagedObject::CAlwaysGet() 00089 */ 00090 T* AlwaysGet(std::string name) 00091 { 00092 return dynamic_cast<T*>(CAlwaysGet(name)); 00093 } 00094 00095 //------------------------------------------------------------------------ 00096 /** \brief See ManagedObject::CAlwaysGet() 00097 */ 00098 T* AlwaysGet(const T& right) 00099 { 00100 return dynamic_cast<T*>(CAlwaysGet(right)); 00101 } 00102 00103 //------------------------------------------------------------------------ 00104 /** \brief Gets a map of the objects using their derived type. 00105 * 00106 * NOTE: Was specifically created for use from python. 00107 * 00108 * This is not efficient, but will do. Changes made to the resulting map 00109 * will not change the internal map only changes made to the objects 00110 * themselves will have any lasting effect. 00111 * 00112 * This means that from python erasing items from this map will not remove 00113 * them from the resulting SpecificManagedObject instance. 00114 */ 00115 std::map<std::string, T*> GetItems() 00116 { 00117 std::map<std::string, T*> ret; 00118 EDOC_FOREACH(StrIDObjPMap, it, items) 00119 { 00120 ret.insert(std::pair<std::string, T*>(it->first, 00121 dynamic_cast<T*>(it->second))); 00122 } 00123 00124 return ret; 00125 } 00126 00127 //------------------------------------------------------------------------ 00128 00129 }; 00130 //=========================================================================== 00131 00132 } 00133 00134 #endif // EDOC_SPECIFICMANAGEDOBJECT_H