ergo
mat::FileWritable Class Referenceabstract

Write and read objects to/from file. More...

#include <FileWritable.h>

Inheritance diagram for mat::FileWritable:
mat::MatrixBase< Treal, Tmatrix >

Classes

struct  Manager
 
struct  Stats
 

Public Member Functions

void writeToFile ()
 Write object to file if filewrite is active. More...
 
void readFromFile ()
 Read object from file if filewrite is active. More...
 
void copyToFile (const char *destFileName)
 
void copyFromFile (const char *sourceFileName)
 
bool isOnFile ()
 Check if object is on file. More...
 
long int fileSize ()
 Return file size. More...
 

Static Public Member Functions

static void setPath (char const *const newPath)
 Set the path to which the objects will be written. More...
 
static void activate ()
 Activate the filewriting. More...
 
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. More...
 
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. More...
 
virtual void writeToFileProt (std::ofstream &) const =0
 Write object to file. More...
 
virtual void readFromFileProt (std::ifstream &)=0
 Read object from file. More...
 
 FileWritable ()
 Gives each object a unique ID-number and filename. More...
 
virtual ~FileWritable ()
 Removes file, if any. More...
 
 FileWritable (FileWritable const &)
 
FileWritableoperator= (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. More...
 
char * fileName
 Each object has its unique filename. More...
 
bool objectIsOnFile
 States whether the object is on file or not. More...
 

Static Private Attributes

static unsigned int nObjects = 0
 The number of instantiated objects. More...
 
static char * path = NULL
 The path to which files will be written. More...
 
static bool active = false
 States whether the filewriting is active. More...
 

Detailed Description

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:

  • clear()
  • write_to_buffer_count(int&) const
  • write_to_buffer(void*, int const) const
  • read_from_buffer(void*, int const)

Member Typedef Documentation

◆ ObjPtrSet

typedef std::set<FileWritable*> mat::FileWritable::ObjPtrSet
protected

◆ TypeCountMap

typedef std::map<std::string, int> mat::FileWritable::TypeCountMap
protected

◆ TypeTimeMap

typedef std::map<std::string, double> mat::FileWritable::TypeTimeMap
protected

Constructor & Destructor Documentation

◆ FileWritable() [1/2]

mat::FileWritable::FileWritable ( )
protected

Gives each object a unique ID-number and filename.

References fileName, IDNumber, nObjects, path, and mat::FileWritable::Manager::registerObj().

◆ ~FileWritable()

mat::FileWritable::~FileWritable ( )
protectedvirtual

◆ FileWritable() [2/2]

Member Function Documentation

◆ activate()

void mat::FileWritable::activate ( )
static

Activate the filewriting.

Without calling this function no filewriting will occur. This function can only be called before instantiation of objects.

References active, and nObjects.

Referenced by es_run().

◆ clear()

virtual void mat::FileWritable::clear ( )
protectedpure virtual

Release memory for the information written to file.

Implemented in mat::MatrixBase< Treal, Tmatrix >.

Referenced by copyFromFile(), and writeToFile().

◆ copyFromFile()

void mat::FileWritable::copyFromFile ( const char *  sourceFileName)

◆ copyToFile()

void mat::FileWritable::copyToFile ( const char *  destFileName)

◆ fileSize()

long int mat::FileWritable::fileSize ( )

Return file size.

Call only if obj is on file.

References active, fileName, and isOnFile().

◆ getStatsCount()

std::string mat::FileWritable::getStatsCount ( TypeCountMap theMap)
staticprotected

◆ getStatsCountCopyAndAssign()

std::string mat::FileWritable::getStatsCountCopyAndAssign ( )
static

◆ getStatsCountRead()

std::string mat::FileWritable::getStatsCountRead ( )
static

◆ getStatsCountWrite()

std::string mat::FileWritable::getStatsCountWrite ( )
static

◆ getStatsFileSizes() [1/2]

std::string mat::FileWritable::getStatsFileSizes ( )
static

◆ getStatsFileSizes() [2/2]

std::string mat::FileWritable::getStatsFileSizes ( ObjPtrSet const &  set)
staticprotected

◆ getStatsTime()

std::string mat::FileWritable::getStatsTime ( TypeTimeMap theMap)
staticprotected

◆ getStatsTimeCopyAndAssign()

std::string mat::FileWritable::getStatsTimeCopyAndAssign ( )
static

◆ getStatsTimeRead()

std::string mat::FileWritable::getStatsTimeRead ( )
static

◆ getStatsTimeWrite()

std::string mat::FileWritable::getStatsTimeWrite ( )
static

◆ inMemorySet()

virtual void mat::FileWritable::inMemorySet ( bool  )
protectedpure 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::MatrixBase< Treal, Tmatrix >.

Referenced by copyFromFile(), readFromFile(), and writeToFile().

◆ isOnFile()

bool mat::FileWritable::isOnFile ( )
inline

Check if object is on file.

References objectIsOnFile.

Referenced by fileSize().

◆ obj_type_id()

virtual std::string mat::FileWritable::obj_type_id ( ) const
protectedpure virtual

◆ operator=()

◆ readFromFile()

◆ readFromFileProt()

virtual void mat::FileWritable::readFromFileProt ( std::ifstream &  )
protectedpure virtual

Read object from file.

Defined in derived class.

Referenced by copyFromFile(), and readFromFile().

◆ resetStats()

◆ setPath()

void mat::FileWritable::setPath ( char const *const  newPath)
static

Set the path to which the objects will be written.

This function can only be called before instantiation of objects.

References nObjects, and path.

Referenced by es_run().

◆ writeAndReadAll()

◆ writeToFile()

void mat::FileWritable::writeToFile ( )

◆ writeToFileProt()

virtual void mat::FileWritable::writeToFileProt ( std::ofstream &  ) const
protectedpure virtual

Write object to file.

Defined in derived class.

Referenced by copyToFile(), and writeToFile().

Member Data Documentation

◆ active

bool mat::FileWritable::active = false
staticprivate

States whether the filewriting is active.

Referenced by activate(), copyFromFile(), copyToFile(), fileSize(), FileWritable(), operator=(), writeToFile(), and ~FileWritable().

◆ fileName

char* mat::FileWritable::fileName
private

Each object has its unique filename.

Referenced by copyFromFile(), copyToFile(), fileSize(), FileWritable(), operator=(), readFromFile(), writeToFile(), and ~FileWritable().

◆ IDNumber

unsigned int const mat::FileWritable::IDNumber
private

Each object has its unique ID-number.

Referenced by FileWritable().

◆ nObjects

unsigned int mat::FileWritable::nObjects = 0
staticprivate

The number of instantiated objects.

Note that the objects may be of different types derived from this base class.

Referenced by activate(), FileWritable(), and setPath().

◆ objectIsOnFile

bool mat::FileWritable::objectIsOnFile
private

States whether the object is on file or not.

Referenced by copyFromFile(), copyToFile(), FileWritable(), isOnFile(), operator=(), readFromFile(), writeToFile(), and ~FileWritable().

◆ path

char * mat::FileWritable::path = NULL
staticprivate

The path to which files will be written.

Referenced by FileWritable(), and setPath().


The documentation for this class was generated from the following files: