00001
00002
00003 #ifndef XAODCORE_AUXPERSVECTOR_H
00004 #define XAODCORE_AUXPERSVECTOR_H
00005
00006
00007 #include "AthContainers/AuxTypeRegistry.h"
00008 #include "AthContainers/tools/AuxTypeVector.h"
00009 #include "AthContainersInterfaces/IAuxSetOption.h"
00010
00011 namespace xAOD {
00012
00024 template< class T, class VEC=std::vector< T > >
00025 class AuxPersVector : public SG::IAuxTypeVector {
00026
00027 public:
00029 typedef VEC& vector_type;
00030
00032 AuxPersVector( vector_type vec ) : m_vec( vec ) {}
00033
00034 virtual SG::IAuxTypeVector* clone() const {
00035 return new AuxPersVector<T, VEC>(*this);
00036 }
00037
00038 virtual void* toPtr() {
00039 if (m_vec.empty())
00040 return 0;
00041 return &*m_vec.begin();
00042 }
00043 virtual void* toVector() {
00044 return &m_vec;
00045 }
00046 virtual size_t size() const {
00047 return m_vec.size();
00048 }
00049 virtual void resize( size_t sz ) {
00050 m_vec.resize( sz );
00051 }
00052 virtual void reserve( size_t sz ) {
00053 m_vec.reserve( sz );
00054 }
00055 virtual void shift( size_t pos, ptrdiff_t offs ) {
00056 if (offs < 0) {
00057 if (-offs > static_cast<off_t>(pos)) offs = -pos;
00058 std::copy (m_vec.begin()+pos, m_vec.end(), m_vec.begin()+pos+offs);
00059 m_vec.resize (m_vec.size() + offs);
00060 }
00061 else if (offs > 0) {
00062 size_t oldsz = m_vec.size();
00063 m_vec.resize (m_vec.size() + offs);
00064 std::copy (m_vec.rbegin()+offs, m_vec.rbegin()+offs+oldsz-pos,
00065 m_vec.rbegin());
00066 std::fill (m_vec.begin()+pos, m_vec.begin()+pos+offs, T());
00067 }
00068 }
00069
00070 virtual bool setOption (const SG::AuxDataOption& option) {
00071
00072
00073
00074 return DataModel_detail::setOptionHelper
00075 (&m_vec,
00076 option,
00077 typename std::is_base_of<SG::IAuxSetOption,vector_type>::type());
00078 }
00079
00080 virtual const std::type_info* objType() const {
00081 return &typeid( VEC );
00082 }
00083
00084 private:
00086 vector_type m_vec;
00087
00088 };
00089
00090 }
00091
00092 #endif // XAODCORE_AUXPERSVECTOR_H