SwatDB
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
Data Class Reference

#include <data.h>

Public Member Functions

 Data ()=delete
 Disable base constructor.
 
 Data (const Data &other)=delete
 Disable copy constructor.
 
Dataoperator= (const Data &other)=delete
 Disable copy assignment constructor.
 
 Data (std::uint32_t size, const char *other_data)
 Constructor with given char array and size.
 
 Data (std::uint32_t size, std::uint32_t capacity)
 Constructor with given size and capacity.
 
 Data (std::uint32_t capacity)
 Constructor with given capacity.
 
 ~Data ()
 Destructor.
 
char * getData ()
 Getter for data char array.
 
std::uint32_t getSize ()
 Getter for size.
 
void setSize (std::uint32_t new_size)
 Setter for size.
 
std::uint32_t getCapacity ()
 Getter for capacity.
 

Private Member Functions

void _getOffsetLength (FieldId field_id, FieldOffset *offset, FieldOffset *length, FieldId num_fields)
 helper method to calculate the offset value and field length given a field_id.
 

Static Private Member Functions

static void _copyDataValue (Data *src, std::uint32_t src_offset, Data *dst, std::uint32_t dst_offset, std::uint32_t len)
 copy data from one Data object to another
 
static void _copyFromBuff (char *src, char *dst, std::uint32_t len)
 helper function for _copyDataValue that does low level copy from char bufs
 
static bool _compareFieldValue (Data *data1, FieldId field_id1, FieldId num_fields1, Data *data2, FieldId field_id2, FieldId num_fields2, Comp comp_op, FieldType field_type)
 compare a field value from one Data object to another (data1 comp_op data2)
 
static bool _compareFromBuff (char *data1, char *data2, Comp comp_op, FieldType field_type, FieldOffset length1, FieldOffset length2)
 helper function for _compareFieldValue that does low level compare on data char bufs
 

Private Attributes

char * data
 
std::uint32_t size
 
std::uint32_t capacity
 

Friends

class Key
 
class Record
 

Detailed Description

SwatDB Data Class. Data a is class that allows storing and moving data of specified size in a more convenient way. A lot of times used as a serialized object that could be given structure by storing it as data member of another object with appropriate methods.

Constructor & Destructor Documentation

◆ Data() [1/3]

Data::Data ( std::uint32_t  size,
const char *  other_data 
)

Constructor with given char array and size.

Precondition
Valid char* and size are provided.
Postcondition
size bytes long char array is dynamically allocated and the size number of bytes are copied from the given char* pointer. size and capacity are set to the given size.

◆ Data() [2/3]

Data::Data ( std::uint32_t  size,
std::uint32_t  capacity 
)

Constructor with given size and capacity.

Precondition
None.
Postcondition
capacity bytes long char array is dynamically allocated and capacity is set to the given capacity. size is set to the given size.
Exceptions
InvalidSizeDataIf size is greater than capacity.

◆ Data() [3/3]

Data::Data ( std::uint32_t  capacity)

Constructor with given capacity.

Precondition
None.
Postcondition
capacity bytes long char array is dynamically allocated and capacity is set to the given capacity. size is set to 0.

◆ ~Data()

Data::~Data ( )

Destructor.

Precondition
Data object is valid.
Postcondition
data array is deallocated.

Member Function Documentation

◆ _compareFieldValue()

static bool Data::_compareFieldValue ( Data data1,
FieldId  field_id1,
FieldId  num_fields1,
Data data2,
FieldId  field_id2,
FieldId  num_fields2,
Comp  comp_op,
FieldType  field_type 
)
staticprivate

compare a field value from one Data object to another (data1 comp_op data2)

Precondition
Assumes all passed values are correct and will not result in overflow of the object's data buffers (caller is responsible for ensuring passed values are okay for these two data objects)
Postcondition
returns LESS, GREATER, EQUAL, NOT_EQUAL, LESS_EQUAL, or GREATER_EQUAL based on comparing data1 to data2 on specified field values
Parameters
data1the first Data object
offset1offset into dtaa1's data buffer of the field to comp
data2the second Data object
offset2offset into dtaa2's data buffer of the field to comp
comp_opthe comparison to perform (LESS, GREATER, EQUAL, NOT_EQUAL, LESS_EQUAL, or GREATER_EQUAL)
field_typethe types of fields being compared
lennumber of bytes of the fields (for strings field types)
Returns
true if data1 comp_op data2 is true, false otherwise

◆ _compareFromBuff()

static bool Data::_compareFromBuff ( char *  data1,
char *  data2,
Comp  comp_op,
FieldType  field_type,
FieldOffset  length1,
FieldOffset  length2 
)
staticprivate

helper function for _compareFieldValue that does low level compare on data char bufs

this may be useful if don't have two Data objects, so we are making this a function instead of internal to implementation

◆ _copyDataValue()

static void Data::_copyDataValue ( Data src,
std::uint32_t  src_offset,
Data dst,
std::uint32_t  dst_offset,
std::uint32_t  len 
)
staticprivate

copy data from one Data object to another

Precondition
Assumes all passed values are correct and will not result in overflow of the destination Data object's data buffer
Postcondition
values from src data buffer are copied to dest data buffer at specified offset
Parameters
srcData object from which to copy value
src_offsetoffset into src's data buffer from which to copy
dstData object to which to copy value
dst_offsetoffset into dst's data buffer to copy value
lennumber of bytes to copy from src to dst

◆ _copyFromBuff()

static void Data::_copyFromBuff ( char *  src,
char *  dst,
std::uint32_t  len 
)
staticprivate

helper function for _copyDataValue that does low level copy from char bufs

this may be useful if don't have two Data objects, so we are making this a function instead of internal to implementation

◆ _getOffsetLength()

void Data::_getOffsetLength ( FieldId  field_id,
FieldOffset offset,
FieldOffset length,
FieldId  num_fields 
)
private

helper method to calculate the offset value and field length given a field_id.

This is a function for extracting formatted information out of the data object.

Parameters
FieldIdfield_id position of the desired record field
FieldOffset*length pointer to the length of the field passed in from caller
FieldOffset*offset pointer to the offset passed in from caller
num_fieldsFieldId number of fields, used to get length of last bucket.
Postcondition
offset and length are filled with the appropriate values based on field_id

◆ getCapacity()

std::uint32_t Data::getCapacity ( )

Getter for capacity.

Precondition
None.
Postcondition
capacity of the Data object is returned.
Returns
capacity of Data.

◆ getData()

char * Data::getData ( )

Getter for data char array.

Precondition
None.
Postcondition
char* to data array is returned.
Returns
char* to data array.

◆ getSize()

std::uint32_t Data::getSize ( )

Getter for size.

Precondition
None.
Postcondition
size is returned.
Returns
size of Data.

◆ setSize()

void Data::setSize ( std::uint32_t  new_size)

Setter for size.

Precondition
None.
Postcondition
size is set.
Parameters
sizeNew size to be set to.
Exceptions
InvalidSizeDataIf new_size is greater than capacity.

Member Data Documentation

◆ capacity

std::uint32_t Data::capacity
private

The actual size of dynamically allocated data array.

◆ data

char* Data::data
private

char* to dynamically allocated array that stores the data.

◆ size

std::uint32_t Data::size
private

Size in bytes up to which the data array is valid.


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