00001 #ifndef PSENV_ENVOBJECTSTORE_H
00002 #define PSENV_ENVOBJECTSTORE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <typeinfo>
00017 #include <boost/shared_ptr.hpp>
00018 #include <boost/enable_shared_from_this.hpp>
00019 #include <boost/utility.hpp>
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "pdsdata/xtc/Src.hh"
00029 #include "PSEvt/DataProxy.h"
00030 #include "PSEvt/EventKey.h"
00031 #include "PSEvt/ProxyDictI.h"
00032 #include "PSEvt/Source.h"
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 namespace PSEnv {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 class EnvObjectStore : public boost::enable_shared_from_this<EnvObjectStore>, boost::noncopyable {
00067 public:
00068
00069
00070 struct GetResultProxy {
00071
00072
00073 template<typename T>
00074 operator boost::shared_ptr<T>() {
00075 boost::shared_ptr<void> vptr = m_dict->get(&typeid(const T), m_source, m_key, m_foundSrc);
00076 return boost::static_pointer_cast<T>(vptr);
00077 }
00078
00079 boost::shared_ptr<PSEvt::ProxyDictI> m_dict;
00080 PSEvt::Source m_source;
00081 std::string m_key;
00082 Pds::Src* m_foundSrc;
00083 };
00084
00085
00086
00087
00088
00089
00090 explicit EnvObjectStore(const boost::shared_ptr<PSEvt::ProxyDictI>& dict) : m_dict(dict) {}
00091
00092
00093 ~EnvObjectStore() {}
00094
00095
00096
00097
00098
00099
00100
00101
00102 template <typename T>
00103 void putProxy(const boost::shared_ptr<PSEvt::Proxy<T> >& proxy, const Pds::Src& source,
00104 const std::string& key=std::string())
00105 {
00106 PSEvt::EventKey evKey(&typeid(const T), source, key);
00107 if ( m_dict->exists(evKey) ) {
00108 m_dict->remove(evKey);
00109 }
00110 m_dict->put(boost::static_pointer_cast<PSEvt::ProxyI>(proxy), evKey);
00111 }
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 template <typename T>
00124 void put(const boost::shared_ptr<T>& data, const Pds::Src& source,
00125 const std::string& key=std::string())
00126
00127 {
00128 boost::shared_ptr<PSEvt::ProxyI> proxyPtr(new PSEvt::DataProxy<T>(data));
00129 PSEvt::EventKey evKey(&typeid(const T), source, key);
00130 if ( m_dict->exists(evKey) ) {
00131 m_dict->remove(evKey);
00132 }
00133 m_dict->put(proxyPtr, evKey);
00134 }
00135
00136
00137
00138
00139
00140
00141
00142
00143 GetResultProxy get(const Pds::Src& source, const std::string& key=std::string())
00144 {
00145 GetResultProxy pxy = { m_dict, PSEvt::Source(source), key, NULL };
00146 return pxy;
00147 }
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 GetResultProxy get(const PSEvt::Source& source, Pds::Src* foundSrc=NULL, const std::string& key=std::string())
00159 {
00160 GetResultProxy pxy = { m_dict, source, key, foundSrc};
00161 return pxy;
00162 }
00163
00164
00165
00166
00167
00168
00169 std::list<PSEvt::EventKey> keys(const PSEvt::Source& source = PSEvt::Source()) const
00170 {
00171 std::list<PSEvt::EventKey> result;
00172 m_dict->keys(result, source);
00173 return result;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 const boost::shared_ptr<PSEvt::ProxyDictI>& proxyDict() const { return m_dict; }
00185
00186 protected:
00187
00188 private:
00189
00190
00191 boost::shared_ptr<PSEvt::ProxyDictI> m_dict;
00192
00193 };
00194
00195 }
00196
00197 #endif // PSENV_ENVOBJECTSTORE_H