ergo
|
Write and read objects to/from file. More...
#include <FileWritable.h>
Classes | |
struct | Manager |
struct | Stats |
Public Member Functions | |
void | writeToFile () |
Write object to file if filewrite is active. | |
void | readFromFile () |
Read object from file if filewrite is active. | |
bool | isOnFile () |
Check if object is on file. | |
long int | fileSize () |
Return file size. | |
Static Public Member Functions | |
static void | setPath (char const *const newPath) |
Set the path to which the objects will be written. | |
static void | activate () |
Activate the filewriting. | |
static std::string | getStatsFileSizes () |
static std::string | writeAndReadAll () |
static void | resetStats () |
static std::string | getStatsTimeWrite () |
static std::string | getStatsTimeRead () |
static std::string | getStatsTimeCopyAndAssign () |
static std::string | getStatsCountWrite () |
static std::string | getStatsCountRead () |
static std::string | getStatsCountCopyAndAssign () |
Protected Types | |
typedef std::map< std::string, double > | TypeTimeMap |
typedef std::map< std::string, int > | TypeCountMap |
typedef std::set< FileWritable * > | ObjPtrSet |
Protected Member Functions | |
virtual void | clear ()=0 |
Release memory for the information written to file. | |
virtual void | inMemorySet (bool)=0 |
Make object invalid (false) via this function when object is written to file and valid (true) when object is read from file. | |
virtual void | writeToFileProt (std::ofstream &) const =0 |
Write object to file. | |
virtual void | readFromFileProt (std::ifstream &)=0 |
Read object from file. | |
FileWritable () | |
Gives each object a unique ID-number and filename. | |
virtual | ~FileWritable () |
Removes file, if any. | |
FileWritable (FileWritable const &) | |
FileWritable & | operator= (FileWritable const &) |
virtual std::string | obj_type_id () const =0 |
Static Protected Member Functions | |
static std::string | getStatsTime (TypeTimeMap &theMap) |
static std::string | getStatsCount (TypeCountMap &theMap) |
static std::string | getStatsFileSizes (ObjPtrSet const &set) |
Private Attributes | |
unsigned int const | IDNumber |
Each object has its unique ID-number. | |
char * | fileName |
Each object has its unique filename. | |
bool | objectIsOnFile |
States whether the object is on file or not. | |
Static Private Attributes | |
static unsigned int | nObjects = 0 |
The number of instantiated objects. | |
static char * | path = NULL |
The path to which files will be written. | |
static bool | active = false |
States whether the filewriting is active. |
Write and read objects to/from file.
This is an abstract class. Classes that are derived from this class must define the following pure virtual functions to be able to instantiate objects:
typedef std::set<FileWritable*> mat::FileWritable::ObjPtrSet [protected] |
typedef std::map<std::string, int> mat::FileWritable::TypeCountMap [protected] |
typedef std::map<std::string, double> mat::FileWritable::TypeTimeMap [protected] |
mat::FileWritable::FileWritable | ( | ) | [protected] |
Gives each object a unique ID-number and filename.
References nObjects, IDNumber, path, fileName, and mat::FileWritable::Manager::registerObj().
mat::FileWritable::~FileWritable | ( | ) | [protected, virtual] |
Removes file, if any.
References mat::FileWritable::Manager::unRegisterObj(), active, objectIsOnFile, and fileName.
mat::FileWritable::FileWritable | ( | FileWritable const & | other | ) | [protected] |
References nObjects, mat::Time::tic(), IDNumber, path, fileName, active, objectIsOnFile, mat::copy_file(), mat::FileWritable::Stats::instance(), mat::FileWritable::Stats::wallTimeCopyAndAssign, obj_type_id(), mat::Time::toc(), mat::FileWritable::Stats::countCopyAndAssign, and mat::FileWritable::Manager::registerObj().
void mat::FileWritable::activate | ( | ) | [static] |
virtual void mat::FileWritable::clear | ( | ) | [protected, pure virtual] |
Release memory for the information written to file.
Implemented in mat::MatrixBase, and mat::VectorGeneral.
Referenced by writeToFile().
long int mat::FileWritable::fileSize | ( | ) |
std::string mat::FileWritable::getStatsCount | ( | TypeCountMap & | theMap | ) | [static, protected] |
Referenced by getStatsCountWrite(), getStatsCountRead(), and getStatsCountCopyAndAssign().
std::string mat::FileWritable::getStatsCountCopyAndAssign | ( | ) | [static] |
References getStatsCount(), and mat::FileWritable::Stats::instance().
Referenced by get_dens_from_fock_sparse(), and mainFun().
std::string mat::FileWritable::getStatsCountRead | ( | ) | [static] |
References getStatsCount(), and mat::FileWritable::Stats::instance().
Referenced by get_dens_from_fock_sparse(), and mainFun().
std::string mat::FileWritable::getStatsCountWrite | ( | ) | [static] |
References getStatsCount(), and mat::FileWritable::Stats::instance().
Referenced by get_dens_from_fock_sparse(), and mainFun().
std::string mat::FileWritable::getStatsFileSizes | ( | ) | [static] |
References mat::FileWritable::Manager::instance().
Referenced by writeAndReadAll().
std::string mat::FileWritable::getStatsFileSizes | ( | ObjPtrSet const & | set | ) | [static, protected] |
std::string mat::FileWritable::getStatsTime | ( | TypeTimeMap & | theMap | ) | [static, protected] |
Referenced by getStatsTimeWrite(), getStatsTimeRead(), and getStatsTimeCopyAndAssign().
std::string mat::FileWritable::getStatsTimeCopyAndAssign | ( | ) | [static] |
References getStatsTime(), and mat::FileWritable::Stats::instance().
Referenced by get_dens_from_fock_sparse(), and mainFun().
std::string mat::FileWritable::getStatsTimeRead | ( | ) | [static] |
References getStatsTime(), and mat::FileWritable::Stats::instance().
Referenced by get_dens_from_fock_sparse(), and mainFun().
std::string mat::FileWritable::getStatsTimeWrite | ( | ) | [static] |
References getStatsTime(), and mat::FileWritable::Stats::instance().
Referenced by get_dens_from_fock_sparse(), and mainFun().
virtual void mat::FileWritable::inMemorySet | ( | bool | ) | [protected, pure virtual] |
Make object invalid (false) via this function when object is written to file and valid (true) when object is read from file.
Implemented in mat::VectorGeneral, and mat::MatrixBase.
Referenced by writeToFile(), and readFromFile().
bool mat::FileWritable::isOnFile | ( | ) | [inline] |
virtual std::string mat::FileWritable::obj_type_id | ( | ) | const [protected, pure virtual] |
Implemented in mat::MatrixBase, and mat::VectorGeneral.
Referenced by writeToFile(), readFromFile(), FileWritable(), and operator=().
FileWritable & mat::FileWritable::operator= | ( | FileWritable const & | other | ) | [protected] |
void mat::FileWritable::readFromFile | ( | ) |
Read object from file if filewrite is active.
References objectIsOnFile, mat::Time::tic(), inMemorySet(), active, fileName, readFromFileProt(), mat::FileWritable::Stats::instance(), mat::FileWritable::Stats::wallTimeRead, obj_type_id(), mat::Time::toc(), and mat::FileWritable::Stats::countRead.
virtual void mat::FileWritable::readFromFileProt | ( | std::ifstream & | ) | [protected, pure virtual] |
Read object from file.
Defined in derived class.
Implemented in mat::VectorGeneral.
Referenced by readFromFile().
void mat::FileWritable::resetStats | ( | ) | [static] |
References mat::FileWritable::Stats::instance(), mat::FileWritable::Stats::wallTimeWrite, mat::FileWritable::Stats::wallTimeRead, mat::FileWritable::Stats::wallTimeCopyAndAssign, mat::FileWritable::Stats::countWrite, mat::FileWritable::Stats::countRead, and mat::FileWritable::Stats::countCopyAndAssign.
Referenced by get_dens_from_fock_sparse(), and mainFun().
void mat::FileWritable::setPath | ( | char const *const | newPath | ) | [static] |
std::string mat::FileWritable::writeAndReadAll | ( | ) | [static] |
void mat::FileWritable::writeToFile | ( | ) |
Write object to file if filewrite is active.
Object is "cleared" in this call.
References objectIsOnFile, mat::Time::tic(), active, fileName, writeToFileProt(), clear(), inMemorySet(), mat::FileWritable::Stats::instance(), mat::FileWritable::Stats::wallTimeWrite, obj_type_id(), mat::Time::toc(), and mat::FileWritable::Stats::countWrite.
virtual void mat::FileWritable::writeToFileProt | ( | std::ofstream & | ) | const [protected, pure virtual] |
Write object to file.
Defined in derived class.
Implemented in mat::VectorGeneral.
Referenced by writeToFile().
bool mat::FileWritable::active = false [static, private] |
States whether the filewriting is active.
Referenced by activate(), writeToFile(), readFromFile(), fileSize(), ~FileWritable(), FileWritable(), and operator=().
char* mat::FileWritable::fileName [private] |
Each object has its unique filename.
Referenced by writeToFile(), readFromFile(), fileSize(), FileWritable(), ~FileWritable(), and operator=().
unsigned int const mat::FileWritable::IDNumber [private] |
Each object has its unique ID-number.
Referenced by FileWritable().
unsigned int mat::FileWritable::nObjects = 0 [static, private] |
The number of instantiated objects.
Note that the objects may be of different types derived from this base class.
Referenced by setPath(), activate(), and FileWritable().
bool mat::FileWritable::objectIsOnFile [private] |
States whether the object is on file or not.
Referenced by writeToFile(), readFromFile(), ~FileWritable(), FileWritable(), operator=(), and isOnFile().
char * mat::FileWritable::path = NULL [static, private] |
The path to which files will be written.
Referenced by setPath(), and FileWritable().