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 header

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 – C-style string containing ASCII header

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 auto get(const char *key) const -> T

Return the value of a parameter value stored in the header.

This is a convenience method for using the templated get method with two arguments

Template Parameters

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

Parameters

key – keyword to search for.

Returns

T value of the parameter named by key

template<typename T>
inline auto get_if_set(const char *key, T default_value) const -> T

Return the value of a parameter if it is set; otherwise, return the default value.

Template Parameters

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

Parameters
  • key – keyword for the parameter

  • default_value – the default value to return if the keyword is not found

Returns

T value of the parameter named by key

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

Set a keyword/value pair in the header.

Template Parameters

T – type of the value to set

Parameters
  • key – keyword that names the parameter

  • val – value of the parameter

template<typename T>
inline void set_array(const std::string &key, std::vector<T> values)

Set a keyword/value pair in the header for array of values.

The value set will be a comma separated string.

Template Parameters

T – type of the value to set

Parameters
  • key – keyword that names the parameter

  • values – the array of values to set

template<typename T>
inline auto get_array(const std::string &key) const -> std::vector<T>

Get an array of values from a key.

Template Parameters

T – type of the individual values

Parameters

key – keyword that names the parameter

Returns

a vector of type T

void del(const std::string &key)

delete a parameter from the header

Parameters

key – key of the parameter to be deleted

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

Report on the presence 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 the 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

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

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

Parameters
  • key – keyword that names the parameter

  • val – value of the parameter

void set_key_padding(uint32_t to_pad)

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

Parameters

to_pad – maximum 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

auto compute_bytes_per_file(double seconds_per_file) const -> uint64_t

Compute the number of bytes per file for the data stream described by the header, accounting for the resolution.

Note

This method ensures that the number of bytes computed is a multiple of the resolution, rounding up

Parameters

seconds_per_file – number of seconds of data that the file should contain

Returns

uint64_t number of bytes the file must contain

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 – path to file containing ASCII header

Returns

the value of the HDR_SIZE attribute in the ASCII header

Public Static Attributes

static constexpr uint32_t default_header_size = 4096

default size of the ASCII header in bytes