00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_PERMUTABLE_HPP
00017 #define TORC_GENERIC_OM_PERMUTABLE_HPP
00018
00019 #include <vector>
00020
00021 #include "torc/generic/om/PointerTypes.hpp"
00022 #include "torc/generic/util/Error.hpp"
00023 #include "torc/generic/om/SelfReferencing.hpp"
00024 #include "torc/generic/om/Visitable.hpp"
00025 #include "torc/generic/om/VisitorType.hpp"
00026 #include "torc/generic/om/FactoryType.hpp"
00027
00028 namespace torc { namespace generic { class Port; } }
00029 namespace torc { namespace generic { class BaseVisitor; } }
00030
00031 namespace torc {
00032
00033 namespace generic {
00034
00035
00036
00037
00038
00039
00040
00041 class Permutable :
00042 public Visitable,
00043 public SelfReferencing<Permutable>
00044 {
00045
00046 friend class FactoryType<Permutable>;
00047
00048 public:
00049
00050
00051
00052
00053
00054
00055 enum PermutableType
00056 {
00057 ePermutableParent = 0,
00058 ePermutableChild
00059 };
00060
00061
00062
00063
00064 typedef VisitorType<Permutable> Visitor;
00065
00066
00067
00068
00069 class Factory: public FactoryType<Permutable>
00070 {
00071 public:
00072 using FactoryType<Permutable>::create;
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 PermutableSharedPtr
00083 virtual newPermutablePtr( const std::vector< PortSharedPtr > & inPorts,
00084 const ViewSharedPtr & inViewPtr,
00085 const PermutableSharedPtr & inParentPermutable
00086 = PermutableSharedPtr() ) throw(Error);
00087 };
00088
00089
00090
00091
00092
00093
00094 inline void
00095 getPorts( std::vector< PortSharedPtr > &outPorts ) const throw();
00096
00097
00098
00099
00100
00101
00102
00103
00104 void
00105 setPorts(const std::vector< PortSharedPtr > & inSource) throw(Error);
00106
00107
00108
00109
00110
00111
00112
00113
00114 void
00115 addPort(const PortSharedPtr & inPort) throw(Error);
00116
00117
00118
00119
00120
00121
00122 inline void
00123 getChildren(
00124 std::vector< PermutableSharedPtr > & outPermutables ) const throw();
00125
00126
00127
00128
00129
00130
00131 template<typename _Action>
00132 inline void
00133 applyOnAllChildren( const _Action &action ) throw(Error);
00134
00135
00136
00137
00138
00139
00140 void
00141 setChildren( const std::vector< PermutableSharedPtr >
00142 & inSource ) throw(Error);
00143
00144
00145
00146
00147
00148
00149 bool
00150 addChildPermutable(
00151 const PermutableSharedPtr & inPermutable) throw(Error);
00152
00153
00154
00155
00156
00157
00158 inline const bool
00159 getIsNonPermutable() const throw();
00160
00161 void
00162 setIsNonPermutable(const bool & value) throw();
00163
00164
00165
00166
00167
00168
00169 inline const PermutableType
00170 getPermutableType() const throw();
00171
00172
00173
00174
00175
00176
00177 void
00178 setPermutableType(const PermutableType & inSource) throw();
00179
00180
00181
00182
00183
00184 size_t
00185 getSize() const throw();
00186
00187 virtual
00188 ~Permutable() throw();
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 virtual void
00203 accept(BaseVisitor & visitor) throw(Error);
00204
00205 protected:
00206 Permutable();
00207
00208 private:
00209 std::vector< PortSharedPtr > mPorts;
00210 std::vector< PermutableSharedPtr > mChildren;
00211 bool mIsNonPermutable;
00212 PermutableType mPermutableType;
00213
00214 };
00215
00216
00217
00218
00219
00220
00221 inline void
00222 Permutable::getPorts(
00223 std::vector< PortSharedPtr > &outValues ) const throw() {
00224 outValues.insert( outValues.end(),
00225 mPorts.begin(), mPorts.end() );
00226 }
00227
00228
00229
00230
00231
00232
00233 inline void
00234 Permutable::getChildren(
00235 std::vector< PermutableSharedPtr > & outPermutables ) const throw() {
00236 outPermutables.insert( outPermutables.end(),
00237 mChildren.begin(), mChildren.end() );
00238 }
00239
00240
00241
00242
00243
00244
00245 template<typename _Action>
00246 inline void
00247 Permutable::applyOnAllChildren( const _Action &action ) throw(Error) {
00248 try
00249 {
00250 std::vector< PermutableSharedPtr >::iterator it = mChildren.begin();
00251 for(; it != mChildren.end(); ++ it )
00252 {
00253 action( *it );
00254 }
00255 }
00256 catch(Error &e)
00257 {
00258 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00259 throw;
00260 }
00261 }
00262
00263
00264
00265
00266
00267 inline const bool
00268 Permutable::getIsNonPermutable() const throw() {
00269 return mIsNonPermutable;
00270 }
00271
00272
00273
00274
00275
00276
00277 inline const Permutable::PermutableType
00278 Permutable::getPermutableType() const throw() {
00279 return mPermutableType;
00280 }
00281
00282 }
00283
00284 }
00285 #endif // TORC_GENERIC_OM_PERMUTABLE_HPP