LibCppBinary
Modern cross-platform C++ binary parsing library
Loading...
Searching...
No Matches
Binary::StringField Class Reference

Represents a string field in a binary file. More...

#include <StringField.h>

Inheritance diagram for Binary::StringField:
Binary::RawField Binary::DataField

Public Member Functions

 StringField (size_t size)
 Constructor; creates a new instance of StringField.
 StringField (std::string value)
 Constructor; creates a new instance of StringField.
 StringField (const StringField &other)
 Copy constructor; creates a deep copy of the field.
std::string Value () const
 Gets the value of the field as a string.
void SetValue (std::string value)
 Sets the value of the field.
std::string ToString () const override
 Converts the field's data to a string representation.
std::string ToString (StringFormat format) const override
 Converts the field's data to a string representation.
StringFieldoperator= (const StringField &other)
 Assignment operator for StringField.
Public Member Functions inherited from Binary::RawField
 RawField (size_t size)
 Constructor; creates a new instance of Field.
 RawField (const RawField &other)
 Copy constructor; creates a deep copy of the field.
size_t Size () const override
 Gets the size of the data in the field.
char * RawData () override
 Provides access to the field's raw data via pointer.
const char * RawData () const override
 Provides access to the field's raw data via const pointer.
RawFieldoperator= (const RawField &other)
 Assignment operator for RawField.
Public Member Functions inherited from Binary::DataField
virtual ~DataField ()=default
 Default destructor; properly destroys the instance.
virtual void CopyRawDataTo (DataField *other)
 Copies the raw data to another DataField.

Additional Inherited Members

Protected Member Functions inherited from Binary::RawField
std::string FormatData (StringFormat format) const
 Format's the field's data as a string in a specific format.
Protected Attributes inherited from Binary::RawField
size_t size
std::unique_ptr< char[]> rawData

Detailed Description

Represents a string field in a binary file.

Binary files can sometimes still contain text fields or strings. Use the string field to read or write these types of fields from and to a Binary::Stream, such as a Binary::FileStream.

Constructor & Destructor Documentation

◆ StringField() [1/3]

Binary::StringField::StringField ( size_t size)
inline

Constructor; creates a new instance of StringField.

Parameters
sizeThe size of the field, in bytes.
Precondition
Size is > 0.

◆ StringField() [2/3]

Binary::StringField::StringField ( std::string value)
inline

Constructor; creates a new instance of StringField.

This constructor creates a new StringField instance of the same size as the specified string and initializes it to the same value as the specified string.

Parameters
valueThe string to create the field from.
Precondition
Specified string length is > 0.
Exceptions
std::invalid_argumentif specified string length is 0.

◆ StringField() [3/3]

Binary::StringField::StringField ( const StringField & other)
inline

Copy constructor; creates a deep copy of the field.

Parameters
otherThe field to copy.

Member Function Documentation

◆ operator=()

StringField & Binary::StringField::operator= ( const StringField & other)

Assignment operator for StringField.

Parameters
otherThe StringField to copy from.
Returns
Reference to this StringField after assignment.

◆ SetValue()

void Binary::StringField::SetValue ( std::string value)

Sets the value of the field.

If the specified string's size is greater than the field's size, the specified value will be truncated to fit the field.

Parameters
valueThe string to set the field's value to.
Postcondition
Writes min(Size(), value.length()) bytes to the field.
Bytes beyond value.length() are unchanged.

◆ ToString() [1/2]

std::string Binary::StringField::ToString ( ) const
inlineoverridevirtual

Converts the field's data to a string representation.

Returns
A string representation of the field's data.

Reimplemented from Binary::RawField.

◆ ToString() [2/2]

std::string Binary::StringField::ToString ( StringFormat format) const
inlineoverridevirtual

Converts the field's data to a string representation.

Returns
A string representation of the field's data.

Reimplemented from Binary::RawField.

◆ Value()

std::string Binary::StringField::Value ( ) const

Gets the value of the field as a string.

Returns
A string representing the value of the field.

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