cppassist  1.0.0.f4fab4f962ff
C++ sanctuary for small but powerful and frequently required, stand alone features.
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
cppassist::DescriptiveRawFile Class Reference

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...
 

Detailed Description

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.

Member Enumeration Documentation

◆ PropertyType

enum cppassist::DescriptiveRawFile::PropertyType : unsigned char
strong

Enumeration to all known data types of header properties.

Enumerator
Unknown 
Integer 
Double 
String 

Constructor & Destructor Documentation

◆ DescriptiveRawFile()

cppassist::DescriptiveRawFile::DescriptiveRawFile ( )

Constructor.

◆ ~DescriptiveRawFile()

cppassist::DescriptiveRawFile::~DescriptiveRawFile ( )

Destructor.

Member Function Documentation

◆ load()

bool cppassist::DescriptiveRawFile::load ( const std::string &  filePath,
bool  parseProperties = true 
)

Load file contents.

Parameters
[in]filePathPath to the file to load
[in]parsePropertiesFlag whether to parse or omit header information
Returns
true if file contents could be loaded successfully, else false
Remarks
Uses the passed file path and stores it for subsequent reloads.

◆ reload()

bool cppassist::DescriptiveRawFile::reload ( )

Reload file contents.

Returns
true if file contents could be loaded successfully, else false
Remarks
Uses the last passed file path to load.

◆ data()

const char* cppassist::DescriptiveRawFile::data ( ) const

Get plain C pointer to file contents.

Returns
Plain C pointer to file contents if successfully loaded, nullptr else

◆ size()

size_t cppassist::DescriptiveRawFile::size ( ) const

Get number of bytes in file.

Returns
Number of bytes in file if successfully loaded, 0 else

◆ isValid()

bool cppassist::DescriptiveRawFile::isValid ( ) const

Get validity of file contents.

Returns
true if file contents could be loaded successfully, else false

◆ filePath()

const std::string& cppassist::DescriptiveRawFile::filePath ( ) const

Get file path.

Returns
File path

◆ stringProperty()

const std::string& cppassist::DescriptiveRawFile::stringProperty ( const std::string &  key) const

Get string property.

Parameters
[in]keyThe key to identify the property
Returns
The string property

◆ intProperty()

int32_t cppassist::DescriptiveRawFile::intProperty ( const std::string &  key) const

Get integer property.

Parameters
[in]keyThe key to identify the property
Returns
The integer property

◆ doubleProperty()

double cppassist::DescriptiveRawFile::doubleProperty ( const std::string &  key) const

Get floating-point property.

Parameters
[in]keyThe key to identify the property
Returns
The floating-point property

◆ hasStringProperty()

bool cppassist::DescriptiveRawFile::hasStringProperty ( const std::string &  key) const

Get availability of string property.

Parameters
[in]keyThe key to identify the property
Returns
true if string property with given name exists, false else

◆ hasIntProperty()

bool cppassist::DescriptiveRawFile::hasIntProperty ( const std::string &  key) const

Get availability of integer property.

Parameters
[in]keyThe key to identify the property
Returns
true if integer property with given name exists, false else

◆ hasDoubleProperty()

bool cppassist::DescriptiveRawFile::hasDoubleProperty ( const std::string &  key) const

Get availability of floating-point property.

Parameters
[in]keyThe key to identify the property
Returns
true if floating-point property with given name exists, false else

◆ stringPropertyKeys()

std::vector<std::string> cppassist::DescriptiveRawFile::stringPropertyKeys ( ) const

Get keys of string properties.

Returns
List of string property keys

◆ intPropertyKeys()

std::vector<std::string> cppassist::DescriptiveRawFile::intPropertyKeys ( ) const

Get keys of integer properties.

Returns
List of integer property keys

◆ doublePropertyKeys()

std::vector<std::string> cppassist::DescriptiveRawFile::doublePropertyKeys ( ) const

Get keys of floating-point properties.

Returns
List of floating-point property keys

◆ readFile()

bool cppassist::DescriptiveRawFile::readFile ( )
protected

Load contents from file path.

Returns
true if file contents could be loaded successfully, else false

◆ readProperties()

void cppassist::DescriptiveRawFile::readProperties ( std::ifstream &  ifs,
uint64_t  offset 
)
protected

Read properties from stream.

Parameters
[in]ifsThe stream to read from
[in]offsetThe offset of the next section
Remarks
Reads from stream until position is the given offset.

◆ readRawData()

void cppassist::DescriptiveRawFile::readRawData ( std::ifstream &  ifs,
uint64_t  offset 
)
protected

Read raw data from stream.

Parameters
[in]ifsThe stream to read from
[in]offsetThe start offset

Member Data Documentation

◆ s_signature

uint16_t cppassist::DescriptiveRawFile::s_signature
static

Magic file signature to detect descriptive raw files with header information.

◆ m_filePath

std::string cppassist::DescriptiveRawFile::m_filePath
protected

File path.

◆ m_data

std::string cppassist::DescriptiveRawFile::m_data
protected

Loaded file contents.

◆ m_parseProperties

bool cppassist::DescriptiveRawFile::m_parseProperties
protected

Whether to parse properties.

◆ m_valid

bool cppassist::DescriptiveRawFile::m_valid
protected

Validity of loaded file contents.

◆ m_stringProperties

std::map<std::string, std::string> cppassist::DescriptiveRawFile::m_stringProperties
protected

Loaded string properties.

◆ m_intProperties

std::map<std::string, int32_t> cppassist::DescriptiveRawFile::m_intProperties
protected

Loaded integer properties.

◆ m_doubleProperties

std::map<std::string, double> cppassist::DescriptiveRawFile::m_doubleProperties
protected

Loaded floating-point properties.


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