Class AsciiHeader

Class Documentation

class AsciiHeader

Provides an interface to a PSRDada style ASCII Header The PSRDada ASCII Header is stored in a configurable, fixed length C-style string (the header). The header contains meta data stored in key/value pairs. Key/value * pairs are separated by newlines, with each key and value delimited by white space(s).

Public Functions

AsciiHeader()

Construct a new Ascii Header object with the default header size.

explicit AsciiHeader(size_t header_size)

Construct a new Ascii Header object with the specified header size.

Parameters

header_size – size of the header in bytes

AsciiHeader(const AsciiHeader &obj)

Construct a new Ascii Header object initializing from the specified object.

Parameters

objAsciiHeader from which to copy the size and content

~AsciiHeader() = default

Destroy the Ascii Header object.

void clone(const AsciiHeader &obj)

Clone the provided AsciiHeader object.

Parameters

obj – object to be cloned

void clone_stream(const AsciiHeader &obj, unsigned stream)

Clone the provided AsciiHeader object Any key in the provided object which is of the form [key]_[stream] will be copied into the new object as [key], discarding the _[stream].

Parameters
  • obj – object to be cloned

  • stream – stream integer to be removed

void append_header(const AsciiHeader &obj)

Append provided header params.

Parameters

obj – object who’s params to append

auto raw() const -> std::string

Return a pointer the raw header stored.

Returns

char* C-style string

void resize(size_t new_size)

Resize the internal storage of the header.

Parameters

new_size – new size of the header in bytes

auto get_header_size() const -> size_t

Return the size of the internal storage for the header.

Returns

size_t size of header storage in bytes

auto get_header_length() const -> size_t

Return the length of the C-string stored in the internal storage.

Returns

size_t

inline void reset()

Clear the internal storage, resetting the header to an empty string.

void load_from_file(const std::string &filename)

Set the ascii key/value pairs from a file.

Parameters

filename – path to file containing ascii hea

void load_from_str(const char *header_str)

Set the ascii header key/value pairs from a string The string must contain newline separated key/value pairs, each of which is white space delimited.

Parameters

header_str – n

void load_from_string(const std::string &header_str)

Set the ascii header key/value pairs from a string The string must contain newline separated key/value pairs, each of which is white space delimited.

Parameters

header_str – n

void append_from_str(const char *header_str)

Append and update the key/value pairs in the header string to the header.

Parameters

header_str – string with key/value pairs

template<typename T>
inline void get(const std::string &search_key, T *val) const

Return the value of a parameter.

Template Parameters

T – type of the parameter to return [any type with an extraction operator]

Parameters
  • search_key – keyword for the parameter

  • val – pointer to variable in which to return the value

template<typename T>
inline void set(const std::string &key, T val)

Set keyword/value pair in the header.

Template Parameters

T – type of the value to set

Parameters
  • key – keyword to use

  • val – value to use

void del(const std::string &key)

delete the keyword from the header

Parameters

key – key of the parameter to be deleted

auto has(const std::string &key) const -> bool

Report on the prescence of a keyword in the header.

Parameters

key – ker of the parameter to be report

Returns

true if the parameter exists

Returns

false if the parameter does not exist

auto header_get_keys() const -> std::vector<std::string>

Return a list of keys in the header.

Returns

std::vector<std::string> keys in the header

auto get_val(const std::string &key) const -> std::string

Return a string representation a parameter value stored in the header. Returns an empty string if not found.

Parameters

key – keyword to search for.

Returns

std::string value of the key

auto get_uint32(const std::string &key) const -> uint32_t

Return a uint32 representation a parameter value stored in the header.

This is a convenience method for using the templated get method.

Parameters

key – keyword to search for.

Returns

uint32 value of the key

auto get_int32(const std::string &key) const -> int32_t

Return a int32 representation a parameter value stored in the header.

This is a convenience method for using the templated get method.

Parameters

key – keyword to search for.

Returns

int32 value of the key

auto get_uint64(const std::string &key) const -> uint64_t

Return a uint64 representation a parameter value stored in the header.

This is a convenience method for using the templated get method.

Parameters

key – keyword to search for.

Returns

uint64_t value of the key

auto get_float(const std::string &key) const -> float

Return a float representation a parameter value stored in the header.

This is a convenience method for using the templated get method.

Parameters

key – keyword to search for.

Returns

float value of the key

auto get_double(const std::string &key) const -> double

Return a double representation a parameter value stored in the header.

This is a convenience method for using the templated get method.

Parameters

key – keyword to search for.

Returns

double value of the key

void set_val(const std::string &key, const std::string &val)

Set a key/value pair in the AsciiHeader parameter list.

Parameters
  • key – key to set

  • val – value to set

void set_key_padding(uint32_t to_pad)

Set the padding (number of spaces) to use when generating the raw AsciiHeader.

Parameters

to_pad – maxmimum number of characters to pad.

auto get_key_padding() const -> uint32_t

Get the padding (number of spaces) that will be used when generating the raw AsciiHEader.

Returns

uint32_t maximum number of characters to pad

auto compute_bits_per_sample() const -> unsigned

Compute the number of bits per time sample for the data stream described by the header.

Parameters

header – parameters that describe the data stream

Returns

unsigned number of bytes per time sample

auto compute_bytes_per_second() const -> double

Compute the number of bytes per second for the data stream described by the header.

Parameters

header – parameters that describe the data stream

Returns

double number of bytes per second

Public Static Functions

static auto get_size(const char *filename) -> size_t

Get the HDR_SIZE attribute of the ascii header in filename.

Parameters

filename

Returns

size_t

Public Static Attributes

static constexpr uint32_t default_header_size = 4096

default size of the ASCII header in bytes