00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_BUNDLE_HPP
00017 #define TORC_GENERIC_OM_BUNDLE_HPP
00018
00019 #include "torc/generic/om/DumpRestoreConfig.hpp"
00020
00021 #include <algorithm>
00022 #include <vector>
00023
00024 #ifdef GENOM_SERIALIZATION
00025 #include <boost/bind.hpp>
00026 #include <boost/mem_fn.hpp>
00027 #include <boost/serialization/access.hpp>
00028 #include <boost/serialization/base_object.hpp>
00029 #include <boost/serialization/shared_ptr.hpp>
00030 #include <boost/serialization/split_member.hpp>
00031 #include <boost/serialization/vector.hpp>
00032 #endif //GENOM_SERIALIZATION
00033
00034 #include "torc/generic/om/Composite.hpp"
00035 #include "torc/generic/om/CompositionType.hpp"
00036 #include "torc/generic/util/Error.hpp"
00037
00038
00039 namespace torc {
00040
00041 namespace generic {
00042
00043
00044
00045
00046
00047
00048 template<typename _Type>
00049 class Bundle : public virtual Composite<_Type> {
00050 #ifdef GENOM_SERIALIZATION
00051 friend class boost::serialization::access;
00052 #endif
00053 public:
00054 typedef Composite<_Type> BaseType;
00055 typedef typename BaseType::Type Type;
00056 typedef typename BaseType::Pointer Pointer;
00057 typedef typename BaseType::List List;
00058 typedef typename BaseType::SizeType SizeType;
00059
00060 typedef Type ChildType;
00061
00062 protected:
00063 Bundle();
00064
00065 public:
00066 virtual
00067 ~Bundle() throw();
00068
00069
00070
00071
00072
00073
00074 virtual CompositionType
00075 getCompositionType() const throw();
00076
00077
00078
00079
00080
00081 virtual SizeType
00082 getSize() const throw();
00083
00084
00085
00086
00087
00088
00089
00090
00091 virtual void
00092 addChild(const boost::shared_ptr<Type> & child) throw(Error);
00093
00094
00095
00096
00097
00098
00099 virtual void
00100 getChildren( List &outChildren ) const throw(Error);
00101
00102 template<typename _Action>
00103 void
00104 applyOnAllChildren( const _Action &action ) throw(Error);
00105
00106
00107
00108
00109
00110
00111
00112
00113 virtual const Pointer
00114 get(const std::vector<SizeType> & indices) const throw(Error);
00115
00116 private:
00117 #ifdef GENOM_SERIALIZATION
00118 template<class Archive> void
00119 load( Archive &ar, unsigned int );
00120
00121 template<class Archive> void
00122 save( Archive &ar, unsigned int ) const;
00123
00124 BOOST_SERIALIZATION_SPLIT_MEMBER()
00125 #endif //GENOM_SERIALIZATION
00126
00127 List mChildren;
00128 };
00129
00130
00131 template<typename _Type>
00132 Bundle<_Type>::Bundle()
00133 :Composite<_Type>() {
00134 }
00135
00136 template<typename _Type>
00137 Bundle<_Type>::~Bundle() throw() {
00138 }
00139
00140
00141
00142
00143
00144
00145 template<typename _Type>
00146 CompositionType
00147 Bundle<_Type>::getCompositionType() const throw()
00148 {
00149 return eCompositionTypeBundle;
00150 }
00151
00152
00153
00154
00155
00156 template<typename _Type>
00157 typename Bundle<_Type>::SizeType
00158 Bundle<_Type>::getSize() const throw()
00159 {
00160 size_t size = 0;
00161 for( typename Bundle<_Type>::List::const_iterator it
00162 = mChildren.begin(); it != mChildren.end(); ++ it )
00163 {
00164 size += (*it)->getSize();
00165 }
00166 return size;
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176 template<typename _Type>
00177 void
00178 Bundle<_Type>::addChild(
00179 const boost::shared_ptr<Type> & child) throw(Error) {
00180 mChildren.push_back( child );
00181 child->setParentCollection(
00182 SelfReferencing<_Type>::getSharedThis() );
00183 }
00184
00185
00186
00187
00188
00189
00190 template<typename _Type>
00191 void
00192 Bundle<_Type>::getChildren(
00193 typename Bundle<_Type>::List &outChildren ) const throw(Error) {
00194 outChildren.insert( outChildren.end(),
00195 mChildren.begin(), mChildren.end() );
00196 return;
00197 }
00198
00199 template<typename _Type>
00200 template<typename _Action>
00201 void
00202 Bundle<_Type>::applyOnAllChildren(
00203 const _Action &action ) throw(Error) {
00204 try
00205 {
00206 std::for_each( mChildren.begin(), mChildren.end(), action );
00207 }
00208 catch(Error &e)
00209 {
00210 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00211 throw;
00212 }
00213
00214 }
00215
00216
00217
00218
00219
00220
00221
00222
00223 template<typename _Type>
00224 const typename Bundle<_Type>::Pointer
00225 Bundle<_Type>::get(
00226 const std::vector<typename Bundle<_Type>::SizeType> & indices) const throw(Error) {
00227 return Pointer();
00228 }
00229
00230 #ifdef GENOM_SERIALIZATION
00231 template<typename _Type>
00232 template<class Archive> void
00233 Bundle<_Type>::load( Archive &ar, unsigned int ) {
00234 ar & boost::serialization::base_object<BaseType>(*this);
00235 ar & mChildren;
00236 for_each( mChildren.begin(), mChildren.end(),
00237 boost::bind( boost::mem_fn(
00238 &Composite<_Type>::setParentCollection ), _1,
00239 SelfReferencing<_Type>::getSharedThis() ));
00240 }
00241
00242 template<typename _Type>
00243 template<class Archive> void
00244 Bundle<_Type>::save( Archive &ar, unsigned int ) const {
00245 ar & boost::serialization::base_object<BaseType>(*this);
00246 ar & mChildren;
00247 }
00248
00249 #endif //GENOM_SERIALIZATION
00250
00251
00252 }
00253
00254 }
00255 #endif // TORC_GENERIC_OM_BUNDLE_HPP