00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef TORC_GENERIC_OM_INSTANCEARRAY_HPP
00017 #define TORC_GENERIC_OM_INSTANCEARRAY_HPP
00018
00019 #include "torc/generic/om/PointerTypes.hpp"
00020 #include "torc/generic/om/DumpRestoreConfig.hpp"
00021
00022 #include <algorithm>
00023
00024 #ifdef GENOM_SERIALIZATION
00025 #include <boost/serialization/access.hpp>
00026 #endif //GENOM_SERIALIZATION
00027
00028 #include "torc/generic/om/Instance.hpp"
00029 #include "torc/generic/om/Vector.hpp"
00030 #include "torc/generic/om/FactoryType.hpp"
00031 #include "torc/generic/om/VisitorType.hpp"
00032 #include "torc/generic/om/Composite.hpp"
00033 #include <vector>
00034
00035 #include "torc/generic/util/Error.hpp"
00036 #include "torc/generic/om/InstanceArrayMember.hpp"
00037
00038 namespace torc { namespace generic { class BaseVisitor; } }
00039
00040 namespace torc {
00041
00042 namespace generic {
00043
00044
00045
00046
00047
00048
00049 class InstanceArray :
00050 public Instance,
00051 public Vector<Instance, InstanceArrayMember,
00052 InstanceArrayMember::Factory, false> {
00053 #ifdef GENOM_SERIALIZATION
00054 friend class boost::serialization::access;
00055 #endif //GENOM_SERIALIZATION
00056
00057 friend class FactoryType<InstanceArray>;
00058
00059 public:
00060 typedef Vector<Instance, InstanceArrayMember,
00061 InstanceArrayMember::Factory, false> BaseVectorType;
00062
00063
00064
00065
00066 class Factory: public FactoryType<InstanceArray>
00067 {
00068 public:
00069 using FactoryType<InstanceArray>::create;
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 virtual InstanceArraySharedPtr
00083 newInstanceArrayPtr( const std::string &inName,
00084 const ViewSharedPtr &inViewPtr,
00085 const ViewSharedPtr &inMaster,
00086 const size_t &inSize,
00087 const ChildFactorySharedPtr &inFactory
00088 = BaseVectorType::ChildFactorySharedPtr(
00089 new BaseVectorType::ChildFactory() ),
00090 const std::string &inOriginalName = std::string()) throw(Error);
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 virtual InstanceArraySharedPtr
00105 newInstanceArrayPtr( const std::string &inName,
00106 const ViewSharedPtr &inViewPtr,
00107 const ViewSharedPtr &inMaster,
00108 const std::vector<size_t> &inLimits,
00109 const ChildFactorySharedPtr &inFactory
00110 = BaseVectorType::ChildFactorySharedPtr(
00111 new BaseVectorType::ChildFactory() ),
00112 const std::string &inOriginalName = std::string()) throw(Error);
00113 };
00114
00115 typedef VisitorType<InstanceArray> Visitor;
00116
00117 virtual void
00118 accept(BaseVisitor & inoutVisitor) throw(Error);
00119
00120 virtual void
00121 setParent( const ViewSharedPtr &inParent ) throw();
00122
00123 virtual void
00124 bindToMasterView(
00125 const ViewSharedPtr &inMaster,
00126 bool inMapPortReferences = true ) throw(Error);
00127
00128
00129
00130
00131
00132
00133
00134 virtual void
00135 addPortReference(
00136 const PortReferenceSharedPtr &inPortRef) throw(Error);
00137
00138
00139
00140
00141
00142
00143
00144 virtual PortReferenceSharedPtr
00145 findPortReference(const std::string &inPortRef) throw(Error);
00146
00147
00148
00149
00150
00151
00152
00153
00154 virtual void
00155 removePortReference(const std::string &inName) throw(Error);
00156
00157
00158
00159
00160
00161
00162
00163 virtual void
00164 getPortReferences(
00165 std::vector< PortReferenceSharedPtr > &) const throw();
00166
00167
00168
00169
00170
00171
00172
00173 virtual void
00174 setPortReferences(
00175 const std::vector< PortReferenceSharedPtr > & inSource) throw(Error);
00176
00177
00178
00179
00180 virtual void
00181 flatten() throw(Error);
00182
00183
00184
00185
00186
00187
00188 template<typename _Action>
00189 inline void
00190 applyOnAllBits( const _Action &action ) throw(Error);
00191
00192 virtual
00193 ~InstanceArray() throw();
00194
00195 protected:
00196 virtual void
00197 onChildCreate( const boost::shared_ptr<BaseVectorType::ChildType> &inCreatedChild
00198 ) const throw(Error);
00199
00200 InstanceArray();
00201
00202 private:
00203 #ifdef GENOM_SERIALIZATION
00204 template<class Archive> void
00205 serialize( Archive &ar, unsigned int );
00206 #endif //GENOM_SERIALIZATION
00207
00208 };
00209
00210
00211
00212
00213
00214
00215 template<typename _Action>
00216 inline void
00217 InstanceArray::applyOnAllBits( const _Action &action ) throw(Error)
00218 {
00219 try
00220 {
00221 std::vector< InstanceSharedPtr > children;
00222 getChildren( children );
00223 std::for_each( children.begin(), children.end(), action );
00224 }
00225 catch(Error &e)
00226 {
00227 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00228 throw;
00229 }
00230 }
00231
00232 }
00233
00234 }
00235 #endif // TORC_GENERIC_OM_INSTANCEARRAY_HPP