00001 #ifndef PSEVT_PROXYDICTI_H 00002 #define PSEVT_PROXYDICTI_H 00003 00004 //-------------------------------------------------------------------------- 00005 // File and Version Information: 00006 // $Id: ProxyDictI.h 9681 2015-02-25 21:50:51Z davidsch@SLAC.STANFORD.EDU $ 00007 // 00008 // Description: 00009 // Class ProxyDictI. 00010 // 00011 //------------------------------------------------------------------------ 00012 00013 //----------------- 00014 // C/C++ Headers -- 00015 //----------------- 00016 #include <string> 00017 #include <list> 00018 #include <typeinfo> 00019 #include <boost/utility.hpp> 00020 #include <boost/shared_ptr.hpp> 00021 00022 //---------------------- 00023 // Base Class Headers -- 00024 //---------------------- 00025 00026 //------------------------------- 00027 // Collaborating Class Headers -- 00028 //------------------------------- 00029 #include "pdsdata/xtc/Src.hh" 00030 #include "PSEvt/AliasMap.h" 00031 #include "PSEvt/EventKey.h" 00032 #include "PSEvt/ProxyI.h" 00033 #include "PSEvt/HistI.h" 00034 #include "PSEvt/Source.h" 00035 00036 //------------------------------------ 00037 // Collaborating Class Declarations -- 00038 //------------------------------------ 00039 00040 // --------------------- 00041 // -- Class Interface -- 00042 // --------------------- 00043 00044 namespace PSEvt { 00045 00046 /** 00047 * @ingroup PSEvt 00048 * 00049 * @brief Class defining an interface for all proxy dictionary classes. 00050 * 00051 * The client-side interface of this class is non-virtual and it 00052 * forwards every class to virtual methods which define customization 00053 * points to be implemented in subclasses. 00054 * 00055 * Proxy dictionary stores proxy objects of type ProxyI which represent 00056 * actual objects and know how to create or retrieve an object when 00057 * requested. Proxy collection is indexed by the EventKey which identifies 00058 * object data type, data source address, and additional string key. 00059 * 00060 * This software was developed for the LCLS project. If you use all or 00061 * part of it, please give an appropriate acknowledgment. 00062 * 00063 * @see ProxyDict 00064 * 00065 * @version \$Id: ProxyDictI.h 9681 2015-02-25 21:50:51Z davidsch@SLAC.STANFORD.EDU $ 00066 * 00067 * @author Andrei Salnikov 00068 */ 00069 00070 class ProxyDictI : boost::noncopyable { 00071 public: 00072 00073 // Destructor 00074 virtual ~ProxyDictI () {} 00075 00076 /** 00077 * @brief Add one more proxy object to the dictionary. 00078 * 00079 * By default the request is forwarded to the virtual method 00080 * (customization point) but there is a possibility to do something 00081 * else too if needed. 00082 00083 * @param[in] proxy Proxy object for type T. 00084 * @param[in] key Event key for the data object. 00085 * 00086 * @throw ExceptionDuplicateKey 00087 * @throw ExceptionNoAliasMap 00088 */ 00089 void put( const boost::shared_ptr<ProxyI>& proxy, const EventKey& key ) 00090 { 00091 this->putImpl(proxy, key); 00092 } 00093 00094 /** 00095 * @brief Get an object from event 00096 * 00097 * @param[in] typeinfo Dynamic type info object 00098 * @param[in] source Source detector address. 00099 * @param[in] key Optional key to distinguish different objects of the same type. 00100 * @param[out] foundSrc If pointer is non-zero then pointed object will be assigned 00101 * with the exact source address of the returned object. 00102 * @return Shared pointer of void type. 00103 */ 00104 boost::shared_ptr<void> get( const std::type_info* typeinfo, 00105 const Source& source, 00106 const std::string& key, 00107 Pds::Src* foundSrc) 00108 { 00109 return this->getImpl(typeinfo, source, key, foundSrc); 00110 } 00111 00112 00113 /** 00114 * @brief Check if proxy of given type exists in the event 00115 * 00116 * This is optimized version of get() which only checks whether the proxy 00117 * is there but does not ask proxy to do any real work. 00118 * 00119 * @param[in] key Event key for the data object. 00120 * @return true if proxy exists 00121 */ 00122 bool exists(const EventKey& key) 00123 { 00124 return this->existsImpl(key); 00125 } 00126 00127 /** 00128 * @brief Remove object of given type from the event 00129 * 00130 * @param[in] key Event key for the data object. 00131 * @return false if object did not exist before this call 00132 */ 00133 bool remove(const EventKey& key) 00134 { 00135 return this->removeImpl(key); 00136 } 00137 00138 /** 00139 * @brief Get the list of event keys defined in event 00140 * 00141 * @param[in] source matching source address 00142 * @param[out] keys list of the EventKey objects 00143 */ 00144 void keys(std::list<EventKey>& keys, const Source& source) const 00145 { 00146 this->keysImpl(keys, source); 00147 } 00148 00149 /** 00150 * @brief return pointer to history interface object, if implemented 00151 * 00152 * If a derived class implements the HistI interface, it can return a 00153 * pointer to the history object here. The implementation of totalUpdates() 00154 * should be all updates, put's and remove's, made to the ProxyDict during 00155 * its existance. The implementation of updates(EventKey&) should be the 00156 * sum of all puts and removes for the given EventKey. 00157 */ 00158 virtual const HistI* hist() const { return 0; } 00159 00160 /** 00161 * @brief Return pointer to alias map 00162 * 00163 * Can return 0 pointer if alias map is not present. 00164 */ 00165 virtual const AliasMap* aliasMap() const { return 0; } 00166 00167 protected: 00168 00169 // Default constructor 00170 ProxyDictI () {} 00171 00172 00173 /** 00174 * @brief Add one more proxy object to the dictionary. 00175 * 00176 * @param[in] proxy Proxy object for type T. 00177 * @param[in] key Event key for the data object. 00178 */ 00179 virtual void putImpl( const boost::shared_ptr<ProxyI>& proxy, const EventKey& key ) = 0; 00180 00181 /** 00182 * @brief Get an object from event 00183 * 00184 * @param[in] typeinfo Dynamic type info object 00185 * @param[in] source Source detector address. 00186 * @param[in] key Optional key to distinguish different objects of the same type. 00187 * @param[out] foundSrc If pointer is non-zero then pointed object will be assigned 00188 * with the exact source address of the returned object. 00189 * @return Shared pointer of void type. 00190 */ 00191 virtual boost::shared_ptr<void> getImpl( const std::type_info* typeinfo, 00192 const Source& source, 00193 const std::string& key, 00194 Pds::Src* foundSrc ) = 0; 00195 00196 /** 00197 * @brief Check if proxy of given type exists in the event 00198 * 00199 * @param[in] key Event key for the data object. 00200 * @return true if proxy exists 00201 */ 00202 virtual bool existsImpl(const EventKey& key) = 0; 00203 00204 /** 00205 * @brief Remove object of given type from the event 00206 * 00207 * @param[in] key Event key for the data object. 00208 * @return false if object did not exist before this call 00209 */ 00210 virtual bool removeImpl(const EventKey& key) = 0; 00211 00212 /** 00213 * @brief Get the list of event keys defined in event 00214 * 00215 * @param[in] source matching source address 00216 * @param[out] keys list of the EventKey objects 00217 */ 00218 virtual void keysImpl(std::list<EventKey>& keys, const Source& source) const = 0; 00219 00220 private: 00221 00222 00223 }; 00224 00225 } // namespace PSEvt 00226 00227 #endif // PSEVT_PROXYDICTI_H