48 #ifndef _MIRA_STRIPEDSTORAGE_H_ 49 #define _MIRA_STRIPEDSTORAGE_H_ 100 std::list<Path> list;
101 for (uint32 i = 0; i <
maxFiles; ++i)
110 foreach(
auto f, files)
111 boost::filesystem::remove(f);
144 template <
typename T>
156 MIRA_LOG(
TRACE) <<
"StripedStorageXML: Wrote to file " << filename <<
" with timestamp " << at.toUnixTimestamp();
171 template <
typename T>
172 std::pair<T, Time>
retrieve(
bool (*validCheckFunc)(
const T&) = NULL)
const 174 std::pair<T, Time> newestData;
175 std::pair<T, Time> pendingData;
180 for(uint32 i = 0; i <
maxFiles; ++i)
186 MIRA_LOG(
TRACE) <<
"StripedStorageXML: Trying to restore from file " << filename;
194 if(pendingData.second <= newestData.second)
195 MIRA_THROW(XLogical,
"Data timestamp below required freshness data, aborting");
199 if(!validCheckFunc || validCheckFunc(pendingData.first))
201 newestData = pendingData;
205 MIRA_LOG(
TRACE) <<
"StripedStorageXML: Could not restore from file " << filename <<
", exception: " << ex.
what();
212 MIRA_THROW(XIO,
"Unable to retrieve persistent information");
233 template <
typename T>
239 std::ofstream ofs(filename.c_str());
252 MIRA_THROW(XIO,
"Failed writing to " << filename);
254 MIRA_LOG(
TRACE) <<
"StripedStorageBinary: Wrote to file " << filename <<
" with timestamp " << at.toUnixTimestamp();
269 template <
typename T>
270 std::pair<T, Time>
retrieve(
bool (*validCheckFunc)(
const T&) = NULL)
const 272 std::pair<T, Time> newestData;
273 std::pair<T, Time> pendingData;
278 for(uint32 i = 0; i <
maxFiles; ++i)
284 MIRA_LOG(
TRACE) <<
"StripedStorageBinary: Trying to restore from file " << filename;
286 std::ifstream ifs(filename.c_str());
291 if(pendingData.second <= newestData.second)
292 MIRA_THROW(XLogical,
"Data timestamp below required freshness data, aborting");
298 if(sanityTime != pendingData.second)
299 MIRA_THROW(XLogical,
"Deserialized time sanity check failed");
301 if(!validCheckFunc || validCheckFunc(pendingData.first))
303 newestData = pendingData;
307 MIRA_LOG(
TRACE) <<
"StripedStorageBinary: Could not restore from file " << filename <<
", exception: " << ex.
what();
314 MIRA_THROW(XIO,
"Unable to retrieve persistent information");
Definition: BinarySerializer.h:324
const Path & getFilePath()
Definition: StripedStorage.h:86
A STL conform wrapper for libxml2 to read XML files as DOM.
Definition: XMLDom.h:73
Stores data sequentially into different files (striped) providing a reliable way to retrieve data lat...
Definition: StripedStorage.h:131
void saveToFile(const Path &filename, const std::string &encoding="UTF-8", bool resolve=true) const
Save the XML document to a file.
void setFilePath(const Path &path)
Resolves path and assigns to filePath.
Definition: StripedStorage.h:82
Path store(const T &data, const Time &at=Time::now())
Stores the given data in one of the files adding a timestamp and returns the filename of the written ...
Definition: StripedStorage.h:234
void deserialize(const std::string &name, T &value)
overwritten from Deserializer, to handle exceptions and to add additional information about file name...
Definition: XMLSerializer.h:340
Definition: XMLSerializer.h:121
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
boost::filesystem::path Path
Typedef of a Path (shorter version for boost::filesystem::path)
Definition: Path.h:69
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:529
Time and Duration wrapper class.
#define MIRA_RETHROW(ex, msg)
Macro for rethrowing an exception with file and line information and for adding additional informatio...
Definition: Exception.h:148
Definition: BinarySerializer.h:991
void loadFromFile(const Path &filename, bool resolve=true)
Load and parse an XML document from a file.
StripedStorageBase(std::string baseName, std::string extension, uint32 maxFiles)
Create a striped storage providing a base file name and the maximum number of files.
Definition: StripedStorage.h:69
Definition: LoggingCore.h:79
static Time unixEpoch()
Returns the unix epoch 1.1.1970 0:0:0.000.
Definition: Time.h:511
void serialize(const std::string &name, const T &value, const std::string &comment="")
Serializes the specified object value under the given name.
Definition: Serializer.h:204
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
void serialize(const T &value, bool enableTypeCheck=true)
Provides a special serialize interface for the BinarySerializer.
Definition: BinarySerializer.h:598
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:256
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:418
StripedStorageBinary()
Definition: StripedStorage.h:223
Output stream adapter that can be assigned to any output stream and allows binary output using the <<...
Definition: BinaryStream.h:293
Commonly used exception classes.
Binary serializer and deserializer.
StripedStorageBase()
Definition: StripedStorage.h:64
std::pair< T, Time > retrieve(bool(*validCheckFunc)(const T &)=NULL) const
Retrieves the data from one of the files.
Definition: StripedStorage.h:270
Definition: StripedStorage.h:61
uint32 mCurrentFileIdx
Definition: StripedStorage.h:121
StripedStorageXML(std::string baseName, uint32 maxFiles)
Definition: StripedStorage.h:135
std::list< Path > getFiles() const
Returns a list of filenames (including paths) for all files that are used for persistent storage...
Definition: StripedStorage.h:98
void deleteAllFiles()
Delete all files that were stored by the persistent storage.
Definition: StripedStorage.h:107
Path store(const T &data, const Time &at=Time::now())
Stores the given data in one of the files adding a timestamp and returns the filename of the written ...
Definition: StripedStorage.h:145
Path filePath
The path where the files are stored.
Definition: StripedStorage.h:120
StripedStorageXML(const Path &directory, std::string baseName, uint32 maxFiles)
Definition: StripedStorage.h:136
Base class for exceptions.
Definition: Exception.h:199
StripedStorageBinary(const Path &directory, std::string baseName, uint32 maxFiles)
Definition: StripedStorage.h:225
StripedStorageBase(const Path &directory, std::string baseName, std::string extension, uint32 maxFiles)
Create a striped storage providing a path, a base file name and the maximum number of files...
Definition: StripedStorage.h:75
Input stream adapter that can be assigned to any input stream and allows binary input using the >> st...
Definition: BinaryStream.h:523
void deserialize(T &value, bool enableTypeCheck=true, bool recursive=false)
Provides a special deserialize interface for the BinaryDeserializer.
Definition: BinarySerializer.h:1340
MIRA_BASE_EXPORT Path resolvePath(const Path &path, bool makeAbsolute=true)
Resolves a path.
Functions for modifying file system paths.
static Time now() static Time eternity()
Returns the current utc based time.
Definition: Time.h:481
Definition: StripedStorage.h:220
Path generateFilename(uint32 fileNr) const
Returns the filename (including path) of the file with the specified nr.
Definition: StripedStorage.h:91
XMLSerializer and XMLDeserializer.
std::pair< T, Time > retrieve(bool(*validCheckFunc)(const T &)=NULL) const
Retrieves the data from one of the files.
Definition: StripedStorage.h:172
virtual const char * what() const MIRA_NOEXCEPT_OR_NOTHROW
Returns the text of exception containing the information given in MIRA_THROW and MIRA_RETHROW as well...
uint32 maxFiles
Maximum number of used files.
Definition: StripedStorage.h:117
StripedStorageBinary(std::string baseName, uint32 maxFiles)
Definition: StripedStorage.h:224
StripedStorageXML()
Definition: StripedStorage.h:134
std::string fileNameBase
The base filename.
Definition: StripedStorage.h:115
std::string extension
The file name extension.
Definition: StripedStorage.h:116
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:313