Main Page · Modules · All Classes · Class Hierarchy |
Binary data class. More...
#include <MCBinaryData.hpp>
Public Member Functions | |
MCBinaryData () | |
Class constructor. | |
MCBinaryData (int size) | |
Class constructor. More... | |
MCBinaryData (int size, unsigned char value) | |
Class constructor. More... | |
MCBinaryData (const MCBinaryData &other) | |
Copy constructor. More... | |
MCBinaryData (MCBinaryData &&other) | |
Move constructor. More... | |
void | Allocate (int size) |
Allocate a certain data size. More... | |
void | Shrink (int size) |
Shrink to a certain data size. More... | |
void | Free () |
Free the allocated data. | |
void | Clear () |
Clear the allocated data. More... | |
bool | IsEmpty () const |
Check if the binary data is not filled with invalid data. More... | |
void | Set (unsigned char *data, int size) |
Set binary data content. More... | |
void | Clone (const MCBinaryData &other) |
Clone an other binary data instance. More... | |
MCBinaryData * | Clone () |
Clone the binary data. | |
bool | WriteData (MCBinaryData &target, int capacity=-1) |
Write data into a target instance. More... | |
unsigned int | CopyData (MCBinaryData &target, int capacity=-1) const |
Copy data into a target instance. More... | |
bool | LoadFromFile (const std::string &file_name) |
Load data from a file. More... | |
bool | LoadFromQtResource (const QString &resource_str) |
Load data from a Qt resource. More... | |
bool | SaveToFile (const std::string &file_name) const |
Save data to a file. More... | |
MCBinaryData | GenerateMd5Hash () const |
Generate md5 hash. More... | |
void | AddUChar (unsigned char new_char) |
Add an unsigned char at the current position. More... | |
void | AddInt16 (int16_t new_int, bool reverse_order=false) |
Add a 16 bit integer at the current position. More... | |
void | AddInt32 (int32_t new_int, bool reverse_order=false) |
Add a 32 bit integer at the current position. More... | |
void | AddString (const std::string &str) |
Add a string at the current position. More... | |
unsigned char | GetUChar () |
Get an unsigned char from the current position. More... | |
int16_t | GetInt16 (bool reverse_order=false) |
Get a 16 bit integer from the current position. More... | |
int32_t | GetInt32 (bool reverse_order=false) |
Get a 32 bit integer from the current position. More... | |
bool | ValidateString (unsigned int length, const std::string &additional_chars="") |
Check if a string can be read from the current position. More... | |
std::string | GetString (unsigned int length, const std::string &additional_chars="") |
Get a string from the current position. More... | |
unsigned char * | GetData () const |
Get direct access to the binary data. More... | |
int | GetSize () const |
Get binary data size. More... | |
const std::vector< unsigned char > & | GetVectorData () const |
Get binary data in vector form. More... | |
int | GetPosition () const |
Get the current position in the binary data. More... | |
bool | IsPositionAtEnd () const |
Check if the current position is at the end of the binary data. More... | |
unsigned int | GetRemainingCapacity (unsigned int capacity) const |
Check if the binary data has enough remaining capacity. More... | |
void | SetPosition (unsigned int position) |
Set the cursor position. More... | |
void | IncrementPosition (unsigned int position=1) |
Increment the cursor position. More... | |
void | ResetPosition () |
Reset the cursor position back to the start position. | |
std::string | ToBase64 () const |
Convert the content to base64. More... | |
void | FromBase64 (const std::string &base64_str) |
Convert back from base64. More... | |
MCBinaryData & | operator= (MCBinaryData &&other) |
Move assignment operator. More... | |
MCBinaryData & | operator= (const MCBinaryData &other) |
Assignment operator. More... | |
bool | operator== (const MCBinaryData &other) const |
Equality (==) operator. More... | |
bool | operator!= (const MCBinaryData &other) const |
Inequality (!=) operator. More... | |
Protected Attributes | |
std::vector< unsigned char > | Data |
Pointer to the encapsulated data. | |
int | Size |
Size of the data. | |
int | Position |
Internal position index. | |
Binary data class.
Definition at line 50 of file MCBinaryData.hpp.
|
explicit |
MCBinaryData::MCBinaryData | ( | int | size, |
unsigned char | value | ||
) |
Class constructor.
size | Initial size |
value | Initialize the bufer with this value |
Definition at line 155 of file MCBinaryData.cpp.
MCBinaryData::MCBinaryData | ( | const MCBinaryData & | other | ) |
MCBinaryData::MCBinaryData | ( | MCBinaryData && | other | ) |
void MCBinaryData::AddInt16 | ( | int16_t | new_int, |
bool | reverse_order = false |
||
) |
Add a 16 bit integer at the current position.
new_int | New integer |
reverse_order | Reverse order mode |
Definition at line 391 of file MCBinaryData.cpp.
void MCBinaryData::AddInt32 | ( | int32_t | new_int, |
bool | reverse_order = false |
||
) |
Add a 32 bit integer at the current position.
new_int | New integer |
reverse_order | Reverse order mode |
Definition at line 412 of file MCBinaryData.cpp.
void MCBinaryData::AddString | ( | const std::string & | str | ) |
Add a string at the current position.
str | String |
Definition at line 437 of file MCBinaryData.cpp.
void MCBinaryData::AddUChar | ( | unsigned char | new_char | ) |
Add an unsigned char at the current position.
new_char | New character |
Definition at line 379 of file MCBinaryData.cpp.
void MCBinaryData::Allocate | ( | int | size | ) |
Allocate a certain data size.
size | Data size |
Definition at line 181 of file MCBinaryData.cpp.
void MCBinaryData::Clear | ( | ) |
Clear the allocated data.
The data is filled with 0xff as "invalid data".
Definition at line 230 of file MCBinaryData.cpp.
void MCBinaryData::Clone | ( | const MCBinaryData & | other | ) |
Clone an other binary data instance.
other | Other instance |
Definition at line 263 of file MCBinaryData.cpp.
unsigned int MCBinaryData::CopyData | ( | MCBinaryData & | target, |
int | capacity = -1 |
||
) | const |
Copy data into a target instance.
target | Target instance |
capacity | Capacity |
If capacity is -1, the target size is used for writing. The Position variable is not modified by this function and therefore it is const.
Definition at line 295 of file MCBinaryData.cpp.
void MCBinaryData::FromBase64 | ( | const std::string & | base64_str | ) |
Convert back from base64.
base64_str | Base64 string |
Definition at line 614 of file MCBinaryData.cpp.
MCBinaryData MCBinaryData::GenerateMd5Hash | ( | ) | const |
unsigned char * MCBinaryData::GetData | ( | ) | const |
Get direct access to the binary data.
Definition at line 548 of file MCBinaryData.cpp.
int16_t MCBinaryData::GetInt16 | ( | bool | reverse_order = false | ) |
Get a 16 bit integer from the current position.
reverse_order | Reverse order mode |
Definition at line 463 of file MCBinaryData.cpp.
int32_t MCBinaryData::GetInt32 | ( | bool | reverse_order = false | ) |
Get a 32 bit integer from the current position.
reverse_order | Reverse order mode |
Definition at line 483 of file MCBinaryData.cpp.
int MCBinaryData::GetPosition | ( | ) | const |
Get the current position in the binary data.
The cursor position is zero in the beginning and reading/writing increases the current position towards the end of the binary data.
Definition at line 566 of file MCBinaryData.cpp.
unsigned int MCBinaryData::GetRemainingCapacity | ( | unsigned int | capacity | ) | const |
Check if the binary data has enough remaining capacity.
capacity | Desired remaining capacity |
The remaining capacity is the size of the remaining bytes after the current cursor position.
Definition at line 572 of file MCBinaryData.cpp.
int MCBinaryData::GetSize | ( | ) | const |
std::string MCBinaryData::GetString | ( | unsigned int | length, |
const std::string & | additional_chars = "" |
||
) |
Get a string from the current position.
length | String length |
additional_chars | Additional valid characters |
The latin characters, numbers and space are valid, but additional characters can be specified by additional_chars.
Definition at line 534 of file MCBinaryData.cpp.
unsigned char MCBinaryData::GetUChar | ( | ) |
Get an unsigned char from the current position.
Definition at line 449 of file MCBinaryData.cpp.
const std::vector< unsigned char > & MCBinaryData::GetVectorData | ( | ) | const |
Get binary data in vector form.
Definition at line 560 of file MCBinaryData.cpp.
void MCBinaryData::IncrementPosition | ( | unsigned int | position = 1 | ) |
Increment the cursor position.
position | Position increment |
Definition at line 590 of file MCBinaryData.cpp.
bool MCBinaryData::IsEmpty | ( | ) | const |
Check if the binary data is not filled with invalid data.
Definition at line 239 of file MCBinaryData.cpp.
bool MCBinaryData::IsPositionAtEnd | ( | ) | const |
Check if the current position is at the end of the binary data.
Definition at line 578 of file MCBinaryData.cpp.
bool MCBinaryData::LoadFromFile | ( | const std::string & | file_name | ) |
Load data from a file.
file_name | File name |
Definition at line 317 of file MCBinaryData.cpp.
bool MCBinaryData::LoadFromQtResource | ( | const QString & | resource_str | ) |
Load data from a Qt resource.
resource_str | Resource string |
Definition at line 335 of file MCBinaryData.cpp.
bool MCBinaryData::operator!= | ( | const MCBinaryData & | other | ) | const |
Inequality (!=) operator.
other | Other instance |
Definition at line 670 of file MCBinaryData.cpp.
MCBinaryData & MCBinaryData::operator= | ( | MCBinaryData && | other | ) |
Move assignment operator.
other | Other instance |
Definition at line 627 of file MCBinaryData.cpp.
MCBinaryData & MCBinaryData::operator= | ( | const MCBinaryData & | other | ) |
Assignment operator.
other | Other instance |
Definition at line 646 of file MCBinaryData.cpp.
bool MCBinaryData::operator== | ( | const MCBinaryData & | other | ) | const |
Equality (==) operator.
other | Other instance |
Definition at line 656 of file MCBinaryData.cpp.
bool MCBinaryData::SaveToFile | ( | const std::string & | file_name | ) | const |
Save data to a file.
file_name | File name |
Definition at line 355 of file MCBinaryData.cpp.
void MCBinaryData::Set | ( | unsigned char * | data, |
int | size | ||
) |
Set binary data content.
data | New data |
size | Binary data size |
If the new data has different size then the binary data is reallocated.
Definition at line 250 of file MCBinaryData.cpp.
void MCBinaryData::SetPosition | ( | unsigned int | position | ) |
Set the cursor position.
position | New position |
Definition at line 584 of file MCBinaryData.cpp.
void MCBinaryData::Shrink | ( | int | size | ) |
Shrink to a certain data size.
size | New data size |
The data is freed if size is zero.
Definition at line 204 of file MCBinaryData.cpp.
std::string MCBinaryData::ToBase64 | ( | ) | const |
Convert the content to base64.
Definition at line 602 of file MCBinaryData.cpp.
bool MCBinaryData::ValidateString | ( | unsigned int | length, |
const std::string & | additional_chars = "" |
||
) |
Check if a string can be read from the current position.
length | String length |
additional_chars | Additional valid characters |
The latin characters, numbers and space are valid, but additional characters can be specified by additional_chars.
Definition at line 503 of file MCBinaryData.cpp.
bool MCBinaryData::WriteData | ( | MCBinaryData & | target, |
int | capacity = -1 |
||
) |
Write data into a target instance.
target | Target instance |
capacity | Capacity |
If capacity is -1, the target size is used for writing.
Definition at line 282 of file MCBinaryData.cpp.