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

Abstract base class representing a data field in a binary file. More...

#include <DataField.h>

Inheritance diagram for Binary::DataField:
Binary::RawField Binary::IntField< uint8_t, 1 > Binary::IntField< uint16_t, 2 > Binary::IntField< uint32_t, 3 > Binary::IntField< uint32_t, 4 > Binary::IntField< uint64_t, 8 > Binary::IntField< int8_t, 1 > Binary::IntField< int16_t, 2 > Binary::IntField< int32_t, 3 > Binary::IntField< int32_t, 4 > Binary::IntField< int64_t, 8 > Binary::BufferStream Binary::IntField< IntType, IntSize > Binary::StringField

Public Member Functions

virtual ~DataField ()=default
 Default destructor; properly destroys the instance.
virtual size_t Size () const =0
 Gets the size of the data in the field.
virtual char * RawData ()=0
 Provides access to the field's raw data via pointer.
virtual const char * RawData () const =0
 Provides access to the field's raw data via const pointer.
virtual void CopyRawDataTo (DataField *other)
 Copies the raw data to another DataField.
virtual std::string ToString () const =0
 Converts the field's data to a string representation.
virtual std::string ToString (StringFormat format) const =0
 Converts the field's data to a string representation.

Detailed Description

Abstract base class representing a data field in a binary file.

Classes that represent a data field in a binary file should derive from this class. The Binary::Stream class accepts pointers to instances of DataField for reading and writing data fields to binary data sources. By properly inheriting from this class, the Binary::Stream class and its derivatives will automatically support reading and writing your derived type.

Constructor & Destructor Documentation

◆ ~DataField()

virtual Binary::DataField::~DataField ( )
virtualdefault

Default destructor; properly destroys the instance.

Member Function Documentation

◆ CopyRawDataTo()

virtual void Binary::DataField::CopyRawDataTo ( DataField * other)
virtual

Copies the raw data to another DataField.

This method copies the raw data to another DataField, truncating the data if the other field is smaller than this one.

Parameters
otherA pointer to the other DataField to copy the data to.
Precondition
Other must not be null.
Postcondition
The raw data from this field is copied to the other field.
Exceptions
std::invalid_argumentif other is null.

◆ RawData() [1/2]

virtual const char * Binary::DataField::RawData ( ) const
pure virtual

Provides access to the field's raw data via const pointer.

Provides read-only access to the raw data stored in the field. Note that this class should manage the lifecycle of the data, so do not attempt to deallocate the memory behind the pointer manually.

Returns
A raw pointer to the data.

Implemented in Binary::RawField.

◆ RawData() [2/2]

virtual char * Binary::DataField::RawData ( )
pure virtual

Provides access to the field's raw data via pointer.

Provides access to the raw data stored in the field. Note that this class should manage the lifecycle of the data, so do not attempt to deallocate the memory behind the pointer manually.

Returns
A raw pointer to the data.

Implemented in Binary::RawField.

◆ Size()

virtual size_t Binary::DataField::Size ( ) const
pure virtual

Gets the size of the data in the field.

Returns
The size of the data in the field, in bytes.

Implemented in Binary::RawField.

◆ ToString() [1/2]

◆ ToString() [2/2]

virtual std::string Binary::DataField::ToString ( StringFormat format) const
pure virtual

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