00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/generic/parser/Linker.hpp"
00017 #include "torc/generic/om/Instance.hpp"
00018
00019 namespace {
00020
00021 using namespace torc::generic;
00022
00023 class LinkAction
00024 {
00025 public:
00026 LinkAction( const ViewSharedPtr &inView )
00027 :mView( inView ) {
00028 }
00029
00030 void
00031 operator()( const InstanceSharedPtr &outInstance
00032 ) const throw( Error ) {
00033 try
00034 {
00035 outInstance->bindToMasterView( mView );
00036 }
00037 catch( Error &e )
00038 {
00039 e.setCurrentLocation( __FUNCTION__,
00040 __FILE__, __LINE__ );
00041 throw;
00042 }
00043 }
00044 private:
00045 ViewSharedPtr mView;
00046 };
00047 }
00048
00049 namespace torc {
00050
00051 namespace generic {
00052
00053 Linker::NameSpec::NameSpec()
00054 :mLibraryName(),
00055 mCellName(),
00056 mViewName() {
00057 }
00058
00059 Linker::NameSpec::NameSpec( const std::string &inLibraryName,
00060 const std::string &inCellName,
00061 const std::string &inViewName )
00062 : mLibraryName( inLibraryName ),
00063 mCellName( inCellName ),
00064 mViewName( inViewName ) {
00065 }
00066
00067 Linker::NameSpec::~NameSpec() throw() {
00068 }
00069
00070 Linker::NameSpec::NameSpec(const Linker::NameSpec &inSource)
00071 :mLibraryName( inSource.mLibraryName ),
00072 mCellName( inSource.mCellName ),
00073 mViewName( inSource.mViewName ) {
00074 }
00075
00076 Linker::NameSpec &
00077 Linker::NameSpec::operator=(
00078 const Linker::NameSpec &inSource) throw() {
00079 if( this != &inSource )
00080 {
00081 mLibraryName = inSource.mLibraryName;
00082 mCellName = inSource.mCellName;
00083 mViewName = inSource.mViewName;
00084 }
00085 return *this;
00086 }
00087
00088 void
00089 Linker::NameSpec::setLibraryName(
00090 const std::string &inValue) throw() {
00091 mLibraryName = inValue;
00092 }
00093
00094 void
00095 Linker::NameSpec::setCellName(const std::string &inValue) throw() {
00096 mCellName = inValue;
00097 }
00098
00099 void
00100 Linker::NameSpec::setViewName(const std::string & inValue) throw() {
00101 mViewName = inValue;
00102 }
00103
00104 void
00105 Linker::UnresolvedInstances::setExternView(
00106 const ViewSharedPtr & inValue) throw() {
00107 mExternView = inValue;
00108 }
00109
00110 void
00111 Linker::UnresolvedInstances::addInstance(
00112 const InstanceSharedPtr &inInstance) throw() {
00113 mInstances.push_back( inInstance );
00114 }
00115
00116 void
00117 Linker::UnresolvedInstances::setInstances(
00118 const std::vector< InstanceSharedPtr > &inValue
00119 ) throw() {
00120 mInstances = inValue;
00121 }
00122
00123 Linker::UnresolvedInstances::UnresolvedInstances()
00124 :mExternView(),
00125 mInstances() {
00126 }
00127
00128 Linker::UnresolvedInstances::~UnresolvedInstances() throw() {
00129 }
00130
00131 Linker::UnresolvedInstances::UnresolvedInstances(
00132 const Linker::UnresolvedInstances &inSource)
00133 :mExternView( inSource.mExternView ),
00134 mInstances( inSource.mInstances ) {
00135 }
00136
00137 Linker::UnresolvedInstances &
00138 Linker::UnresolvedInstances::operator=(
00139 const Linker::UnresolvedInstances &inSource) throw() {
00140 if( this != &inSource )
00141 {
00142 mExternView = inSource.mExternView;
00143 mInstances = inSource.mInstances;
00144 }
00145 return *this;
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155 ViewSharedPtr
00156 Linker::findExternView(
00157 const Linker::NameSpec &inNameSpec) throw() {
00158 UnresolvedInstancesPtr info;
00159 mInfos.get( inNameSpec, info );
00160 if( info )
00161 {
00162 return info->getExternView();
00163 }
00164 return ViewSharedPtr();
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 void
00174 Linker::setExternView(
00175 const Linker::NameSpec &inNameSpec,
00176 const ViewSharedPtr &inExternView) throw() {
00177 UnresolvedInstancesPtr info;
00178 mInfos.get( inNameSpec, info );
00179 if( !info )
00180 {
00181 info = UnresolvedInstancesPtr( new UnresolvedInstances() );
00182 mInfos.set( inNameSpec, info );
00183 }
00184 info->setExternView( inExternView );
00185 return;
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 bool
00197 Linker::findUnresolvedInstances(
00198 const Linker::NameSpec &inNameSpec,
00199 Linker::UnresolvedInstancesPtr &outInstances) throw(Error) {
00200 return mInfos.get( inNameSpec, outInstances );
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211 void
00212 Linker::registerUnresolvedInstance(
00213 const Linker::NameSpec &inNameSpec,
00214 const InstanceSharedPtr &inInstance) throw(Error) {
00215 UnresolvedInstancesPtr info;
00216 mInfos.get( inNameSpec, info );
00217 if( !info )
00218 {
00219 info = UnresolvedInstancesPtr( new UnresolvedInstances() );
00220 mInfos.set( inNameSpec, info );
00221 }
00222 info->addInstance( inInstance );
00223 return;
00224 }
00225
00226
00227
00228
00229
00230
00231 void
00232 Linker::removeUnresolvedInstances(
00233 const Linker::NameSpec &inNameSpec) throw(Error) {
00234 mInfos.remove( inNameSpec );
00235 }
00236
00237 void
00238 Linker::linkUnresolved(const NameSpec &inNameSpec,
00239 ViewSharedPtr &inView) throw(Error) {
00240 UnresolvedInstancesPtr info;
00241 mInfos.get( inNameSpec, info );
00242 LinkAction linkAction( inView );
00243 if( info )
00244 {
00245 try
00246 {
00247 info->applyActionOnInstances( linkAction );
00248 }
00249 catch( Error &e )
00250 {
00251 e.setCurrentLocation( __FUNCTION__, __FILE__, __LINE__ );
00252 throw;
00253 }
00254 removeUnresolvedInstances( inNameSpec );
00255 }
00256 }
00257
00258
00259
00260
00261
00262
00263 Linker::Linker(const RootSharedPtr &inRoot)
00264 :mRoot( inRoot ),
00265 mInfos() {
00266 }
00267
00268 Linker::~Linker() throw() {
00269 }
00270
00271 Linker::Linker(const Linker &inSource)
00272 : mRoot( inSource.mRoot ),
00273 mInfos( inSource.mInfos ) {
00274 }
00275
00276 Linker &
00277 Linker::operator=(const Linker &inSource) throw() {
00278 if( this != &inSource )
00279 {
00280 mRoot = inSource.mRoot;
00281 mInfos = inSource.mInfos;
00282 }
00283 return *this;
00284 }
00285
00286
00287 }
00288
00289 }