00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_COMPOSITE_HPP
00017 #define TORC_GENERIC_OM_COMPOSITE_HPP
00018
00019 #include "torc/generic/om/DumpRestoreConfig.hpp"
00020
00021 #include <cstddef>
00022 #include <vector>
00023
00024
00025 #include <boost/shared_ptr.hpp>
00026 #include <boost/weak_ptr.hpp>
00027
00028 #ifdef GENOM_SERIALIZATION
00029 #include <boost/serialization/access.hpp>
00030 #include <boost/serialization/base_object.hpp>
00031 #include <boost/serialization/weak_ptr.hpp>
00032 #endif //GENOM_SERIALIZATION
00033
00034 #include "torc/generic/om/CompositionType.hpp"
00035 #include "torc/generic/util/Error.hpp"
00036 #include "torc/generic/om/SelfReferencing.hpp"
00037
00038 namespace torc {
00039
00040 namespace generic {
00041
00042
00043
00044
00045
00046
00047 template<typename _Type>
00048 class Composite: public SelfReferencing<_Type>
00049 {
00050 #ifdef GENOM_SERIALIZATION
00051 friend class boost::serialization::access;
00052 #endif
00053 public:
00054 typedef _Type Type;
00055
00056
00057
00058
00059 typedef boost::shared_ptr<Type> Pointer;
00060 typedef boost::weak_ptr<Type> WeakPointer;
00061
00062
00063
00064
00065 typedef std::vector<Pointer> List;
00066 typedef size_t SizeType;
00067
00068
00069 protected:
00070 virtual ~Composite() throw() {
00071 };
00072
00073
00074 public:
00075 Composite();
00076
00077
00078
00079
00080
00081
00082 virtual CompositionType
00083 getCompositionType() const throw() = 0;
00084
00085
00086
00087
00088
00089 virtual size_t
00090 getSize() const throw() = 0;
00091
00092
00093
00094
00095
00096
00097
00098
00099 virtual void
00100 getChildren( List &outChildren ) const throw(Error) = 0;
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 virtual const Pointer
00115 get(const std::vector<SizeType> & inIndices) const throw(Error) = 0;
00116
00117
00118
00119
00120
00121
00122 inline virtual void
00123 setParentCollection(const Pointer & inParentCollection) throw();
00124
00125
00126
00127
00128
00129
00130 inline virtual Pointer
00131 getParentCollection() const throw();
00132
00133 private:
00134
00135 #ifdef GENOM_SERIALIZATION
00136 template<class Archive> void
00137 serialize( Archive &ar, unsigned int );
00138 #endif //GENOM_SERIALIZATION
00139
00140 Composite(const Composite<_Type> &rhs) throw();
00141
00142 Composite<_Type> &
00143 operator=(const Composite<_Type> &rhs) throw();
00144
00145 WeakPointer mParentCollection;
00146
00147 };
00148
00149 template<typename _Type>
00150 Composite<_Type>::Composite()
00151 : SelfReferencing<_Type>(),
00152 mParentCollection() {
00153 }
00154
00155
00156
00157
00158
00159
00160 template<typename _Type>
00161 inline void
00162 Composite<_Type>::setParentCollection(
00163 const typename Composite<_Type>::Pointer & inParentCollection) throw() {
00164 mParentCollection = inParentCollection;
00165 }
00166
00167
00168
00169
00170
00171
00172 template<typename _Type>
00173 inline typename Composite<_Type>::Pointer
00174 Composite<_Type>::getParentCollection() const throw() {
00175 return mParentCollection.lock();
00176 }
00177
00178 #ifdef GENOM_SERIALIZATION
00179 template<typename _Type>
00180 template<class Archive> void
00181 Composite<_Type>::serialize( Archive &ar, unsigned int ) {
00182 ar & boost::serialization::base_object< SelfReferencing<_Type> >(
00183 *this );
00184
00185 }
00186 #endif //GENOM_SERIALIZATION
00187
00188 }
00189
00190 }
00191 #endif // TORC_GENERIC_OM_COMPOSITE_HPP