![]() |
cppassist
1.0.0.f4fab4f962ff
C++ sanctuary for small but powerful and frequently required, stand alone features.
|
Raw data with header file loader. More...
#include <cppassist/include/cppassist/fs/DescriptiveRawFile.h>
Public Types | |
enum | PropertyType : unsigned char { PropertyType::Unknown = 0, PropertyType::Integer = 1, PropertyType::Double = 2, PropertyType::String = 3 } |
Enumeration to all known data types of header properties. More... | |
Public Member Functions | |
DescriptiveRawFile () | |
Constructor. More... | |
~DescriptiveRawFile () | |
Destructor. More... | |
bool | load (const std::string &filePath, bool parseProperties=true) |
Load file contents. More... | |
bool | reload () |
Reload file contents. More... | |
const char * | data () const |
Get plain C pointer to file contents. More... | |
size_t | size () const |
Get number of bytes in file. More... | |
bool | isValid () const |
Get validity of file contents. More... | |
const std::string & | filePath () const |
Get file path. More... | |
const std::string & | stringProperty (const std::string &key) const |
Get string property. More... | |
int32_t | intProperty (const std::string &key) const |
Get integer property. More... | |
double | doubleProperty (const std::string &key) const |
Get floating-point property. More... | |
bool | hasStringProperty (const std::string &key) const |
Get availability of string property. More... | |
bool | hasIntProperty (const std::string &key) const |
Get availability of integer property. More... | |
bool | hasDoubleProperty (const std::string &key) const |
Get availability of floating-point property. More... | |
std::vector< std::string > | stringPropertyKeys () const |
Get keys of string properties. More... | |
std::vector< std::string > | intPropertyKeys () const |
Get keys of integer properties. More... | |
std::vector< std::string > | doublePropertyKeys () const |
Get keys of floating-point properties. More... | |
Static Public Attributes | |
static uint16_t | s_signature |
Magic file signature to detect descriptive raw files with header information. More... | |
Protected Member Functions | |
bool | readFile () |
Load contents from file path. More... | |
void | readProperties (std::ifstream &ifs, uint64_t offset) |
Read properties from stream. More... | |
void | readRawData (std::ifstream &ifs, uint64_t offset) |
Read raw data from stream. More... | |
Protected Attributes | |
std::string | m_filePath |
File path. More... | |
std::string | m_data |
Loaded file contents. More... | |
bool | m_parseProperties |
Whether to parse properties. More... | |
bool | m_valid |
Validity of loaded file contents. More... | |
std::map< std::string, std::string > | m_stringProperties |
Loaded string properties. More... | |
std::map< std::string, int32_t > | m_intProperties |
Loaded integer properties. More... | |
std::map< std::string, double > | m_doubleProperties |
Loaded floating-point properties. More... | |
Raw data with header file loader.
This class allows for loading raw data (e.g., textures) from files with additional header information. You have to exactly know how to interpret the content of the file, probably using the information of the header to parametrize the content interpretion.
|
strong |
cppassist::DescriptiveRawFile::DescriptiveRawFile | ( | ) |
Constructor.
cppassist::DescriptiveRawFile::~DescriptiveRawFile | ( | ) |
Destructor.
bool cppassist::DescriptiveRawFile::load | ( | const std::string & | filePath, |
bool | parseProperties = true |
||
) |
Load file contents.
[in] | filePath | Path to the file to load |
[in] | parseProperties | Flag whether to parse or omit header information |
true
if file contents could be loaded successfully, else false
bool cppassist::DescriptiveRawFile::reload | ( | ) |
Reload file contents.
true
if file contents could be loaded successfully, else false
const char* cppassist::DescriptiveRawFile::data | ( | ) | const |
Get plain C pointer to file contents.
nullptr
else size_t cppassist::DescriptiveRawFile::size | ( | ) | const |
Get number of bytes in file.
bool cppassist::DescriptiveRawFile::isValid | ( | ) | const |
Get validity of file contents.
true
if file contents could be loaded successfully, else false
const std::string& cppassist::DescriptiveRawFile::filePath | ( | ) | const |
Get file path.
const std::string& cppassist::DescriptiveRawFile::stringProperty | ( | const std::string & | key | ) | const |
Get string property.
[in] | key | The key to identify the property |
int32_t cppassist::DescriptiveRawFile::intProperty | ( | const std::string & | key | ) | const |
Get integer property.
[in] | key | The key to identify the property |
double cppassist::DescriptiveRawFile::doubleProperty | ( | const std::string & | key | ) | const |
Get floating-point property.
[in] | key | The key to identify the property |
bool cppassist::DescriptiveRawFile::hasStringProperty | ( | const std::string & | key | ) | const |
Get availability of string property.
[in] | key | The key to identify the property |
true
if string property with given name exists, false
else bool cppassist::DescriptiveRawFile::hasIntProperty | ( | const std::string & | key | ) | const |
Get availability of integer property.
[in] | key | The key to identify the property |
true
if integer property with given name exists, false
else bool cppassist::DescriptiveRawFile::hasDoubleProperty | ( | const std::string & | key | ) | const |
Get availability of floating-point property.
[in] | key | The key to identify the property |
true
if floating-point property with given name exists, false
else std::vector<std::string> cppassist::DescriptiveRawFile::stringPropertyKeys | ( | ) | const |
Get keys of string properties.
std::vector<std::string> cppassist::DescriptiveRawFile::intPropertyKeys | ( | ) | const |
Get keys of integer properties.
std::vector<std::string> cppassist::DescriptiveRawFile::doublePropertyKeys | ( | ) | const |
Get keys of floating-point properties.
|
protected |
Load contents from file path.
true
if file contents could be loaded successfully, else false
|
protected |
Read properties from stream.
[in] | ifs | The stream to read from |
[in] | offset | The offset of the next section |
|
protected |
Read raw data from stream.
[in] | ifs | The stream to read from |
[in] | offset | The start offset |
|
static |
Magic file signature to detect descriptive raw files with header information.
|
protected |
File path.
|
protected |
Loaded file contents.
|
protected |
Whether to parse properties.
|
protected |
Validity of loaded file contents.
|
protected |
Loaded string properties.
|
protected |
Loaded integer properties.
|
protected |
Loaded floating-point properties.