23 #ifdef GENOM_SERIALIZATION
24 #include <boost/archive/binary_iarchive.hpp>
25 #include <boost/archive/binary_oarchive.hpp>
26 #include <boost/serialization/base_object.hpp>
27 #include <boost/serialization/is_abstract.hpp>
28 #include <boost/serialization/list.hpp>
29 #include <boost/serialization/shared_ptr.hpp>
30 #endif //GENOM_SERIALIZATION
35 #ifdef GENOM_SERIALIZATION
37 #endif //GENOM_SERIALIZATION
41 #ifdef GENOM_SERIALIZATION
42 class RestoredCellUpdater {
44 void operator()(
const CellSharedPtr& inCell)
const throw (Error) {
46 inCell->setParent(mLibrary);
47 inCell->restoreActions();
49 e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
60 #endif //GENOM_SERIALIZATION
77 newLibrary->setName(inName);
78 newLibrary->setParent(inRootPtr);
79 inRootPtr->addLibrary(newLibrary);
80 newLibrary->setLevel(inEdifLevel);
81 newLibrary->setOriginalName(inOriginalName);
144 if(cellName.empty()) {
149 #ifdef GENOM_SERIALIZATION
150 std::list<std::string>::iterator it = std::find(mDumpedCells.begin(), mDumpedCells.end(),
152 if(it != mDumpedCells.end()) {
157 #endif //GENOM_SERIALIZATION
158 if(
false == mCellSymTab.set(cellName, inCell)) {
163 inCell->setParent(getSharedThis());
180 mCellSymTab.get(inName, cell);
181 #ifdef GENOM_SERIALIZATION
182 if(!cell && !mDumpedCells.empty()) {
183 cell = restoreSingleCell(inName);
185 #endif //GENOM_SERIALIZATION
204 #ifdef GENOM_SERIALIZATION
205 std::list<std::string>::iterator it = std::find(mDumpedCells.begin(), mDumpedCells.end(),
207 if(it == mDumpedCells.end()) {
212 mDumpedCells.erase(it);
214 #endif //GENOM_SERIALIZATION
215 if(
false == mCellSymTab.remove(inName)) {
228 #ifdef GENOM_SERIALIZATION
230 #endif //GENOM_SERIALIZATION
245 mScaleFactors(), mLevel(), mCellSymTab(), mSimulationInfo() {}
248 log(
"Library destroyed \n");
251 #ifdef GENOM_SERIALIZATION
252 template <
class Archive>
void Library::save(Archive& ar,
unsigned int)
const {
253 typedef std::vector<CellSharedPtr> Cells;
254 ar & boost::serialization::base_object < Commentable > (*this);
255 ar & boost::serialization::base_object < Extern > (*this);
256 ar & boost::serialization::base_object < Nameable > (*this);
257 ar & boost::serialization::base_object < Renamable > (*this);
258 ar & boost::serialization::base_object < Visitable > (*this);
261 ar & boost::serialization::base_object < SelfReferencing<Library> > (*this);
266 Cells::iterator cell = cells.begin();
267 Cells::iterator end = cells.end();
268 for(; cell != end; ++cell) {
271 fileName += (*cell)->getName() +
".cell";
272 std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary);
276 boost::archive::binary_oarchive cellAr(fout);
283 mDumpedCells.push_back((*cell)->getName());
286 mDumpedCells.clear();
293 template <
class Archive>
void Library::load(Archive& ar,
unsigned int) {
294 ar & boost::serialization::base_object < Commentable > (*this);
295 ar & boost::serialization::base_object < Extern > (*this);
296 ar & boost::serialization::base_object < Nameable > (*this);
297 ar & boost::serialization::base_object < Renamable > (*this);
298 ar & boost::serialization::base_object < Visitable > (*this);
300 ar & boost::serialization::base_object < SelfReferencing<Library> > (*this);
310 std::list<std::string>::iterator it = std::find(mDumpedCells.begin(), mDumpedCells.end(),
312 if(it == mDumpedCells.end()) {
315 std::string fileName = getParent()->getDumpRestoreData().getDumpPath() +
"/";
316 fileName += getName() +
"_";
317 fileName += inName +
".cell";
318 std::ifstream fin(fileName.c_str(), std::ios::in | std::ios::binary);
322 boost::archive::binary_iarchive cellAr(fin);
325 mDumpedCells.erase(it);
326 RestoredCellUpdater updater(getSharedThis());
333 void Library::restoreAllCells() throw (Error)
335 std::vector < std::string > cells;
336 cells.insert(cells.end(), mDumpedCells.begin(), mDumpedCells.end());
337 for(std::vector<std::string>::iterator cell = cells.begin(); cell != cells.end(); ++cell) {
339 restoreSingleCell(*cell);
341 e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
347 e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
353 Library::load<boost::archive::binary_iarchive>(boost::archive::binary_iarchive& ar,
357 Library::save<boost::archive::binary_oarchive>(boost::archive::binary_oarchive& ar,
358 const unsigned int)
const;
364 if(inLibrary->getName().empty()) {
367 if(!inLibrary->getParent()) {
371 dump(inLibrary, inLibrary->getParent()->getDumpRestoreData());
373 e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
378 void dump(
const LibrarySharedPtr& inLibrary,
const DumpRestoreData& inData)
throw (Error) {
382 if(inLibrary->getName().empty()) {
385 if(inData.getDumpPath().empty()) {
389 fileName += inLibrary->getName() +
".lib";
390 std::ofstream fout(fileName.c_str(), std::ios::out | std::ios::binary);
394 boost::archive::binary_oarchive libAr(fout);
405 lib = restore(inName, inParent, inParent->getDumpRestoreData());
407 e.setCurrentLocation(__FUNCTION__, __FILE__, __LINE__);
414 const DumpRestoreData& inData)
throw (Error) {
420 fileName += inName +
".lib";
421 std::ifstream fin(fileName.c_str(), std::ios::in | std::ios::binary);
425 boost::archive::binary_iarchive libAr(fin);
428 library->setParent(inParent);
433 #endif //GENOM_SERIALIZATION
void getValues(std::vector< ValueType > &outValues) const
void log(const char *fmt,...)
void addCell(const CellSharedPtr &inCell)
bool setScaleFactor(Unit inUnit, const ScaleFactor &inScale)
An object that has a parent.
void setSimulationInfo(const SimulationInfoSharedPtr &inSource)
virtual void accept(BaseVisitor &inoutVisitor)
Represents class that can hold userData.
virtual void getCells(std::vector< CellSharedPtr > &outCells)
void runVisitor(_Tp &inoutVisited, BaseVisitor &inoutVisitor)
bool findScaleFactor(Unit inUnit, ScaleFactor &outResult) const
The Error object thrown by different methods of EdifOM.
boost::shared_ptr< Library > LibrarySharedPtr
A base class for Visitor.
boost::shared_ptr< SimulationInfo > SimulationInfoSharedPtr
SymTab< std::string, CellSharedPtr > mCellSymTab
const boost::shared_ptr< Root > getParent() const
void saveContextData(const std::string &inName, const boost::any &inSource)
SimulationInfoSharedPtr mSimulationInfo
virtual CellSharedPtr findCell(const std::string &inName)
void removeCell(const std::string &inName)
void setLevel(const EdifLevel &inSource)
SymTab< Unit, ScaleFactor > mScaleFactors
virtual LibrarySharedPtr newLibraryPtr(const std::string &inName, const RootSharedPtr &inRootPtr, const EdifLevel &inEdifLevel=eEdifLevel0, const std::string &inOriginalName=std::string())
Root of the EDIF Object Model.
virtual const std::string getName() const
boost::shared_ptr< Cell > CellSharedPtr
An object that has a name.
Pointer getSharedThis() const
Represents objects that can be renamed.
Represents objects that have status.
boost::shared_ptr< Root > RootSharedPtr
An object that receives an inoutVisitor.
Used to implement external object referencing.
void setCurrentLocation(const std::string &inFunction, const std::string &inFile, uint32_t inLine)