00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/generic/om/InterfaceJoinedInfo.hpp"
00017 #include "torc/generic/om/Port.hpp"
00018 #include "torc/generic/om/PortList.hpp"
00019
00020 namespace torc {
00021
00022 namespace generic {
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 InterfaceJoinedInfoSharedPtr
00035 InterfaceJoinedInfo::Factory::newInterfaceJoinedInfoPtr(
00036 const std::list< PortSharedPtr > & inPorts,
00037 const std::list< PortListSharedPtr > & inPortLists,
00038 const ViewSharedPtr & inViewPtr,
00039 const InterfaceJoinedInfoSharedPtr & inParentJoinedInfo ) throw(Error) {
00040 try
00041 {
00042 InterfaceJoinedInfoSharedPtr newInterfaceJoinedInfo;
00043 create( newInterfaceJoinedInfo );
00044 newInterfaceJoinedInfo->setPorts( inPorts );
00045 if( inParentJoinedInfo )
00046 {
00047 inParentJoinedInfo->addChildJoinedInfo( newInterfaceJoinedInfo );
00048 }
00049 else if( inViewPtr )
00050 {
00051 inViewPtr->addInterfaceJoinedInfo( newInterfaceJoinedInfo );
00052 }
00053 return newInterfaceJoinedInfo;
00054 }
00055 catch( Error &e )
00056 {
00057 e.setCurrentLocation(
00058 __FUNCTION__, __FILE__, __LINE__ );
00059 throw;
00060 }
00061 }
00062
00063
00064
00065
00066
00067 void
00068 InterfaceJoinedInfo::setJoinedType(const JoinedType & value) throw() {
00069 mJoinedType = value;
00070 }
00071
00072
00073
00074
00075
00076
00077
00078 void
00079 InterfaceJoinedInfo::addPort( const PortSharedPtr & inPort ) throw(Error) {
00080 if( !inPort )
00081 {
00082 return;
00083 }
00084 std::string name = inPort->getName();
00085 if( name.empty() )
00086 {
00087 Error e( eMessageIdErrorEmptyItemName,
00088 __FUNCTION__, __FILE__, __LINE__ );
00089 e.saveContextData("Port name", name);
00090 throw e;
00091 }
00092 mJoinedPorts.push_back( inPort );
00093 }
00094
00095
00096
00097
00098
00099
00100 void
00101 InterfaceJoinedInfo::addPortList( const PortListSharedPtr & inPortList ) throw() {
00102 if( !inPortList )
00103 {
00104 return;
00105 }
00106 mJoinedPortLists.push_back( inPortList );
00107 }
00108
00109
00110
00111
00112
00113
00114 void
00115 InterfaceJoinedInfo::setPorts(
00116 const std::list< PortSharedPtr > & inSource ) throw() {
00117 std::list< PortSharedPtr >::const_iterator port = inSource.begin();
00118 std::list< PortSharedPtr >::const_iterator end = inSource.end();
00119 for(;port != end; ++port)
00120 {
00121 try
00122 {
00123 addPort( *port );
00124 }
00125 catch( Error &e )
00126 {
00127 e.setCurrentLocation(
00128 __FUNCTION__, __FILE__, __LINE__ );
00129 throw;
00130 }
00131 }
00132 }
00133
00134
00135
00136
00137
00138
00139 void
00140 InterfaceJoinedInfo::setPortLists(
00141 const std::list< PortListSharedPtr > & inSource ) throw() {
00142 std::list< PortListSharedPtr >::const_iterator portList = inSource.begin();
00143 std::list< PortListSharedPtr >::const_iterator end = inSource.end();
00144 for(;portList != end; ++portList)
00145 {
00146 try
00147 {
00148 addPortList( *portList );
00149 }
00150 catch( Error &e )
00151 {
00152 e.setCurrentLocation(
00153 __FUNCTION__, __FILE__, __LINE__ );
00154 throw;
00155 }
00156 }
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166 void
00167 InterfaceJoinedInfo::setChildren(
00168 const std::vector< InterfaceJoinedInfoSharedPtr > & inSource ) throw() {
00169 std::vector< InterfaceJoinedInfoSharedPtr >::const_iterator entry = inSource.begin();
00170 std::vector< InterfaceJoinedInfoSharedPtr >::const_iterator end = inSource.end();
00171 for(; entry != end; ++entry )
00172 {
00173 try
00174 {
00175 addChildJoinedInfo( *entry );
00176 }
00177 catch( Error &e )
00178 {
00179 e.setCurrentLocation(
00180 __FUNCTION__, __FILE__, __LINE__ );
00181 throw;
00182 }
00183 }
00184 }
00185
00186
00187
00188
00189
00190
00191 bool
00192 InterfaceJoinedInfo::addChildJoinedInfo(
00193 const InterfaceJoinedInfoSharedPtr & inChildJoinInfo) throw() {
00194 if( !inChildJoinInfo )
00195 {
00196 Error e( eMessageIdErrorPointerToItemDoesNotExist,
00197 __FUNCTION__, __FILE__, __LINE__ );
00198 e.saveContextData("Pointer to the joined info object does not exist", inChildJoinInfo);
00199 throw e;
00200 }
00201 if( inChildJoinInfo ) {
00202 mChildren.push_back( inChildJoinInfo );
00203 return true;
00204 }
00205 else {
00206 return false;
00207 }
00208 }
00209
00210 void
00211 InterfaceJoinedInfo::accept(BaseVisitor & visitor) throw(Error) {
00212 try
00213 {
00214 runVisitor( *this, visitor );
00215 }
00216 catch( Error &e )
00217 {
00218 e.setCurrentLocation(
00219 __FUNCTION__, __FILE__, __LINE__ );
00220 throw;
00221 }
00222 }
00223
00224
00225
00226
00227
00228
00229 void
00230 InterfaceJoinedInfo::setRelationType(const RelationType & inSource) throw() {
00231 mRelationType = inSource;
00232 }
00233
00234
00235
00236
00237
00238 size_t
00239 InterfaceJoinedInfo::getSize() const throw() {
00240 size_t size = 0;
00241 size_t pSize = 0;
00242 size_t cSize = 0;
00243 InterfaceJoinedInfo::RelationType rType = getRelationType();
00244
00245 std::vector< InterfaceJoinedInfoSharedPtr > outJoinedInfos;
00246 getChildren( outJoinedInfos );
00247 std::vector< InterfaceJoinedInfoSharedPtr >::iterator joinedInfoIt
00248 = outJoinedInfos.begin();
00249
00250 std::list< PortSharedPtr > outPorts;
00251 getPorts( outPorts );
00252 std::list< PortSharedPtr >::iterator portIt
00253 = outPorts.begin();
00254
00255 std::list< PortListSharedPtr > outPortLists;
00256 getPortLists( outPortLists );
00257 std::list< PortListSharedPtr >::iterator portListIt
00258 = outPortLists.begin();
00259
00260 if( InterfaceJoinedInfo::eRelationTypeParent == rType )
00261 {
00262 if( !outPorts.empty() )
00263 {
00264 pSize = (*portIt)->getSize();
00265 }
00266 else if( !outPortLists.empty() )
00267 {
00268 pSize = (*portListIt)->getSize();
00269 }
00270 else if( !outJoinedInfos.empty() )
00271 {
00272 for( ; joinedInfoIt != outJoinedInfos.end() ; joinedInfoIt ++ )
00273 {
00274 pSize += (*joinedInfoIt)->getSize();
00275 for( ; portIt != outPorts.end(); portIt ++ )
00276 {
00277 pSize += (*portIt)->getSize();
00278 }
00279 for( ; portListIt != outPortLists.end(); portListIt ++ )
00280 {
00281 pSize += (*portListIt)->getSize();
00282 }
00283 }
00284 }
00285 else
00286 {
00287 pSize = 0;
00288 }
00289 }
00290 else
00291 {
00292 if( !outPorts.empty() )
00293 {
00294 for( ; portIt != outPorts.end(); portIt ++ )
00295 {
00296 cSize += (*portIt)->getSize();
00297 }
00298 }
00299 if( !outPortLists.empty() )
00300 {
00301 for( ; portListIt != outPortLists.end(); portListIt ++ )
00302 {
00303 cSize += (*portListIt)->getSize();
00304 }
00305 }
00306 if( !outJoinedInfos.empty() )
00307 {
00308 for( ; joinedInfoIt != outJoinedInfos.end() ; joinedInfoIt ++ )
00309 {
00310 cSize += (*joinedInfoIt)->getSize();
00311 }
00312 }
00313 }
00314 size = pSize + cSize;
00315 return size;
00316 }
00317
00318 InterfaceJoinedInfo::InterfaceJoinedInfo()
00319 : Visitable(),
00320 SelfReferencing<InterfaceJoinedInfo>(),
00321 mJoinedType(),
00322 mRelationType(),
00323 mJoinedPorts(),
00324 mJoinedPortLists(),
00325 mChildren() {
00326 }
00327
00328 InterfaceJoinedInfo::~InterfaceJoinedInfo() throw() {
00329 }
00330
00331
00332 }
00333
00334 }