TBTK
|
Need a break? Support the development by playing Polarity Puzzles |
Read and write string resources from file, URL, etc. More...
#include <Resource.h>
Public Member Functions | |
Resource () | |
~Resource () | |
void | setData (const std::string &data) |
const std::string & | getData () const |
void | write (const std::string &uri) |
void | read (const std::string &uri) |
Read and write string resources from file, URL, etc.
The Resource provides the means for reading input data from files, URL's etc. It thus provides a unified mechanism for reading data that is agnostic of the underlying storage medium. Files can be accessed from the local disc or through any of the protocols supported by cURL (https://curl.haxx.se/). At the moment, it is only possible to write to a local file.
Resources are particularly useful in combination with serialization for storing and reading in TBTK objects. An empty resource is created using
Once created, it is possible to read a serialized Model from file
or a URL
Finally, we get the content of the resource using 'resource.getData()' and can use it to reconstruct a Model from its serialization
TBTK::Resource::Resource | ( | ) |
Constructor.
TBTK::Resource::~Resource | ( | ) |
Destructor.
|
inline |
Get the data from the resource.
void TBTK::Resource::read | ( | const std::string & | uri | ) |
Read a resource from a source.
uri | The unique resource identifier (URI) of the source. Should be the name of the file when reading from a local file. |
|
inline |
Set the data of the Resource.
data | The data the resource should contain. |
void TBTK::Resource::write | ( | const std::string & | uri | ) |
Write the resource to destination. Currently the destination can only be a local file.
uri | The unique resource identifier (URI) of the destination. Should be the name of the file when writing to a local file. |