00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "torc/generic/om/DumpRestoreConfig.hpp"
00017
00018 #ifndef HAVE_CONFIG_H
00019 #include "torc/generic/config.h"
00020 #endif
00021
00022 #ifdef GENOM_SERIALIZATION
00023 #include <boost/archive/binary_iarchive.hpp>
00024 #include <boost/archive/binary_oarchive.hpp>
00025 #include <boost/serialization/is_abstract.hpp>
00026 #include <boost/serialization/shared_ptr.hpp>
00027 #endif //GENOM_SERIALIZATION
00028
00029 #include "torc/generic/om/Cell.hpp"
00030 #include "torc/generic/om/Library.hpp"
00031 #include "torc/generic/om/VisitorType.hpp"
00032 #include "torc/generic/om/View.hpp"
00033
00034 namespace torc {
00035
00036 namespace generic {
00037
00038 #ifdef GENOM_SERIALIZATION
00039 class RestoredViewUpdater {
00040 public:
00041 void
00042 operator()( const ViewSharedPtr &inView
00043 ) const throw(Error) {
00044 try
00045 {
00046 inView->setParent( mCell );
00047 inView->restoreActions();
00048 }
00049 catch( Error &e )
00050 {
00051 e.setCurrentLocation(
00052 __FUNCTION__, __FILE__, __LINE__ );
00053 throw;
00054 }
00055 }
00056
00057 RestoredViewUpdater ( const CellSharedPtr &inCell )
00058 : mCell( inCell ) {
00059 }
00060 private:
00061 CellSharedPtr mCell;
00062 };
00063 #endif //GENOM_SERIALIZATION
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 CellSharedPtr
00076 Cell::Factory::newCellPtr( const std::string &inName,
00077 const LibrarySharedPtr &inLibraryPtr,
00078 const Cell::Type &inCellType,
00079 const std::string &inOriginalName ) throw(Error) {
00080 try
00081 {
00082 CellSharedPtr newCell;
00083 create( newCell );
00084 newCell->setName(inName);
00085 newCell->setParent( inLibraryPtr );
00086 inLibraryPtr->addCell( newCell );
00087 newCell->setType( inCellType );
00088 newCell->setOriginalName( inOriginalName );
00089 return newCell;
00090 }
00091 catch( Error &e )
00092 {
00093 e.setCurrentLocation(
00094 __FUNCTION__, __FILE__, __LINE__ );
00095 throw;
00096 }
00097 }
00098
00099 void
00100 Cell::accept(BaseVisitor & inoutVisitor) throw(Error) {
00101 try
00102 {
00103 runVisitor( *this, inoutVisitor );
00104 }
00105 catch( Error &e )
00106 {
00107 e.setCurrentLocation(
00108 __FUNCTION__, __FILE__, __LINE__ );
00109 throw;
00110 }
00111 }
00112
00113
00114
00115
00116
00117
00118 void
00119 Cell::setType(const Cell::Type & inSource) throw() {
00120 mType = inSource;
00121 }
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 void
00133 Cell::addView(const ViewSharedPtr & inView) throw(Error) {
00134 if( !inView )
00135 {
00136 return;
00137 }
00138 std::string name = inView->getName();
00139 if( name.empty() )
00140 {
00141 Error e( eMessageIdErrorEmptyItemName,
00142 __FUNCTION__, __FILE__, __LINE__ );
00143 e.saveContextData("Empty View type", name);
00144 throw e;
00145 }
00146 if( false == mViewSymTab.set( name, inView ) )
00147 {
00148 Error e( eMessageIdErrorItemAlreadyExists,
00149 __FUNCTION__, __FILE__, __LINE__ );
00150 e.saveContextData("View name", name);
00151 throw e;
00152 }
00153 inView->setParent( getSharedThis() );
00154 }
00155
00156
00157
00158
00159
00160
00161
00162
00163 ViewSharedPtr
00164 Cell::findView(const std::string &inName) throw() {
00165 if( inName.empty() )
00166 {
00167 Error e( eMessageIdErrorEmptyItemName,
00168 __FUNCTION__, __FILE__, __LINE__ );
00169 e.saveContextData("Empty Cell name", inName);
00170 throw e;
00171 }
00172 ViewSharedPtr view;
00173 mViewSymTab.get( inName, view );
00174 return view;
00175 }
00176
00177
00178
00179
00180
00181
00182
00183
00184 void
00185 Cell::removeView( const std::string &inName ) throw(Error) {
00186 if( inName.empty() )
00187 {
00188 Error e( eMessageIdErrorEmptyItemName,
00189 __FUNCTION__, __FILE__, __LINE__ );
00190 e.saveContextData("View name", inName);
00191 throw e;
00192 }
00193 if( false == mViewSymTab.remove( inName ) )
00194 {
00195 Error e( eMessageIdErrorItemNotFound,
00196 __FUNCTION__, __FILE__, __LINE__ );
00197 e.saveContextData("View name", inName);
00198 throw e;
00199 }
00200 return;
00201 }
00202
00203 Cell::Cell()
00204 :Commentable(),
00205 Extern(),
00206 Nameable(),
00207 ParentedObject<Library>(),
00208 PropertyContainer(),
00209 Renamable(),
00210 Visitable(),
00211 SelfReferencing<Cell>(),
00212 UserDataContainer(),
00213 StatusContainer(),
00214 mViewSymTab(),
00215 mType( eTypeGeneric ) {
00216 }
00217
00218 Cell::~Cell() throw() {
00219 }
00220
00221 #ifdef GENOM_SERIALIZATION
00222 template<class Archive> void
00223 Cell::serialize( Archive &ar, unsigned int ) {
00224 ar & boost::serialization::base_object<Commentable>( *this );
00225 ar & boost::serialization::base_object<Extern>( *this );
00226 ar & boost::serialization::base_object<Nameable>( *this );
00227 ar & boost::serialization::base_object<PropertyContainer>(*this);
00228 ar & boost::serialization::base_object<Renamable>( *this );
00229 ar & boost::serialization::base_object<Visitable>( *this );
00230 ar & boost::serialization::base_object<
00231 SelfReferencing<Cell> >( *this );
00232 ar & mViewSymTab;
00233
00234 }
00235
00236 void
00237 Cell::restoreActions() throw(Error) {
00238 try
00239 {
00240 mViewSymTab.applyOnAll(
00241 RestoredViewUpdater( getSharedThis() ) );
00242 }
00243 catch( Error &e )
00244 {
00245 e.setCurrentLocation(
00246 __FUNCTION__, __FILE__, __LINE__ );
00247 throw;
00248 }
00249 }
00250
00251
00252 template void
00253 Cell::serialize<boost::archive::binary_iarchive>(
00254 boost::archive::binary_iarchive & ar, const unsigned int);
00255
00256 template void
00257 Cell::serialize<boost::archive::binary_oarchive>(
00258 boost::archive::binary_oarchive & ar, const unsigned int);
00259
00260 #endif //GENOM_SERIALIZATION
00261
00262 }
00263
00264 }