00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_BUNDLEFLATTENER_HPP
00017 #define TORC_GENERIC_OM_BUNDLEFLATTENER_HPP
00018
00019 #include "torc/generic/om/PointerTypes.hpp"
00020 #include "torc/generic/om/DumpRestoreConfig.hpp"
00021
00022 #include "torc/generic/om/Bundle.hpp"
00023 #include "torc/generic/om/ScalarPort.hpp"
00024 #include "torc/generic/om/VectorPort.hpp"
00025 #include "torc/generic/om/PortBundle.hpp"
00026 #include "torc/generic/om/VisitorApplier.hpp"
00027
00028 namespace torc {
00029
00030 namespace generic {
00031
00032
00033
00034
00035
00036
00037 template<typename _BaseType, typename _Scalar, typename _Vector,
00038 typename _VectorBit, typename _Bundle>
00039 class BundleFlattener :
00040 public _Scalar::Visitor,
00041 public _Vector::Visitor,
00042 public _VectorBit::Visitor,
00043 public _Bundle::Visitor {
00044 public:
00045
00046 typedef typename _BaseType::List List;
00047
00048 void
00049 visit( _Scalar &scalar ) throw(Error);
00050
00051 void
00052 visit( _Vector &vector ) throw(Error);
00053
00054 void
00055 visit( _VectorBit &vectorBit ) throw(Error);
00056
00057 void
00058 visit( _Bundle &bundle ) throw(Error);
00059
00060 inline void
00061 getChildren( typename Bundle<_BaseType>::List &outChildren ) const throw(Error);
00062
00063
00064 BundleFlattener();
00065
00066 ~BundleFlattener() throw();
00067
00068 private:
00069 typename Bundle<_BaseType>::List mChildren;
00070 };
00071
00072
00073
00074
00075
00076
00077
00078 template<typename _BaseType, typename _Scalar, typename _Vector,
00079 typename _VectorBit, typename _Bundle>
00080 void
00081 BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>
00082 ::getChildren(
00083 typename Bundle<_BaseType>::List &outChildren ) const throw(Error) {
00084 outChildren.insert( outChildren.end(),
00085 mChildren.begin(), mChildren.end() );
00086 return;
00087 }
00088
00089 template<typename _BaseType, typename _Scalar, typename _Vector,
00090 typename _VectorBit, typename _Bundle>
00091 void
00092 BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>
00093 ::visit( _Scalar &scalar ) throw(Error) {
00094 mChildren.push_back( scalar.getSharedThis() );
00095 }
00096
00097 template<typename _BaseType, typename _Scalar, typename _Vector,
00098 typename _VectorBit, typename _Bundle>
00099 void
00100 BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>
00101 ::visit( _Vector &vector ) throw(Error) {
00102 try
00103 {
00104 typename _Vector::List children;
00105 vector.getChildren( children );
00106 BundleFlattener<_BaseType, _Scalar, _Vector,
00107 _VectorBit, _Bundle> flattener;
00108 VisitorApplier< BundleFlattener<_BaseType, _Scalar,
00109 _Vector, _VectorBit, _Bundle> > applier( flattener );
00110 for_each( children.begin(), children.end(), applier );
00111 }
00112 catch( Error &e )
00113 {
00114 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00115 throw;
00116 }
00117 }
00118
00119 template<typename _BaseType, typename _Scalar, typename _Vector,
00120 typename _VectorBit, typename _Bundle>
00121 void
00122 BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>
00123 ::visit( _VectorBit &vectorBit ) throw(Error) {
00124 mChildren.push_back( vectorBit.getSharedThis() );
00125
00126 }
00127
00128 template<typename _BaseType, typename _Scalar, typename _Vector,
00129 typename _VectorBit, typename _Bundle>
00130 void
00131 BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>
00132 ::visit( _Bundle &bundle ) throw(Error) {
00133 try
00134 {
00135 BundleFlattener<_BaseType, _Scalar, _Vector,
00136 _VectorBit, _Bundle> flattener;
00137 VisitorApplier< BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle> >
00138 applier( flattener );
00139 bundle.applyOnAllChildren( applier );
00140
00141 }
00142 catch( Error &e )
00143 {
00144 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00145 throw;
00146 }
00147 }
00148
00149 template<typename _BaseType, typename _Scalar, typename _Vector,
00150 typename _VectorBit, typename _Bundle>
00151 BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>
00152 ::BundleFlattener()
00153 :mChildren( ) {
00154 }
00155
00156 template<typename _BaseType, typename _Scalar, typename _Vector,
00157 typename _VectorBit, typename _Bundle>
00158 BundleFlattener<_BaseType, _Scalar, _Vector, _VectorBit, _Bundle>
00159 ::~BundleFlattener() throw() {
00160 }
00161
00162 }
00163
00164 }
00165 #endif // TORC_GENERIC_OM_BUNDLEFLATTENER_HPP