peakingduck::util namespace

Defines all utilities (string manip, file IO, etc) of the library.

Copyright

UK Atomic Energy Authority (UKAEA) - 2019-20

bool peakingduck::util::file_exists_quick(const std::string &filename)

uses POSIX stat to check

a function to check if a file exists on disk (fast approach)

Return

True if file exists, false otherwise

Parameters
  • filename: the name of the file.

bool peakingduck::util::file_exists(const std::string &filename)

uses C file

A function to check if a file exists on disk (not so quick approach, but still fast)

Return

True if file exists, false otherwise

Parameters
  • filename: the name of the file.

std::string peakingduck::util::read_stream_into_string(std::istream &instream)

Will return a string from a buffered stream.

A function to read a istream as a string

Return

A string containing the whole buffer

Exceptions
  • ios::failure: if cannot read the buffer

Parameters
  • instream: the istream buffer

template<char delimiter, class Container>
void peakingduck::util::split(std::istream &stream, Container &cont)

Split from a stream using single delimiter per line

void peakingduck::util::ltrim(std::string &s)
void peakingduck::util::rtrim(std::string &s)
void peakingduck::util::ltrim(std::string &s, char delimiter)
void peakingduck::util::rtrim(std::string &s, char delimiter)
void peakingduck::util::trim(std::string &s)
template<typename T>
std::vector<T> peakingduck::util::get_window(const std::vector<T> &values, int centerindex, int nouter = 5, int ninner = 0, bool includeindex = true)

Given a list of values take nouter points either side of the index given and ignore ninner points.

Examples:

  1. values = [8, 2, 5, 2, 6, 6, 9, 23, 12] index = 4 nouter = 3 ninner = 0 includeindex = True

    => [2, 5, 2, 6, 6, 9, 23]

  2. values = [8, 2, 5, 2, 6, 6, 9, 23, 12] index = 4 nouter = 3 ninner = 0 includeindex = False

    => [2, 5, 2, 6, 9, 23]

  3. values = [8, 2, 5, 2, 6, 6, 9, 23, 12] index = 4 nouter = 3 ninner = 1 includeindex = True

    => [2, 5, 6, 9, 23]

  4. values = [8, 2, 5, 2, 6, 6, 9, 23, 12] index = 4 nouter = 3 ninner = 1 includeindex = False

    => [2, 5, 9, 23]

Therefore:

  • ninner >= 0

  • ninner <= nouter

  • index >= nouter

  • index < values.size()

It will clip at (0, len(values))

template<typename IntegerType, IntegerType ibegin, IntegerType iend, IntegerType step = 1>
struct peakingduck::util::peakingduck::util::range
#include <range.hpp>

A simple range based struct. Assumes begin, end and step known at compile time Only used for trivial loops to save doing things like: std::vector<int> indices; for(int i=1, i<5; ++i) indices.push_back(i);.

Usage as:

auto rn = range<size_t,1,5,1>();
for (auto it=rn.begin();it!=rn.end();++it)
    std::cout << *it << ", ";

1, 2, 3, 4,

Public Functions

iterator begin()
iterator end()
iterator begin() const
iterator end() const
struct iterator

Public Types

using value_type = IntegerType
using size_type = std::size_t
using difference_type = IntegerType
using pointer = value_type*
using reference = value_type&
using iterator_category = std::random_access_iterator_tag

Public Functions

iterator(IntegerType v)
operator IntegerType() const
operator IntegerType&()
IntegerType operator*() const
IntegerType const *operator->() const
iterator &operator++()
iterator &operator++(int)
bool operator==(iterator const &other) const
bool operator!=(iterator const &other) const
template<typename IntegerType>
struct peakingduck::util::peakingduck::util::rrange
#include <range.hpp>

A simple range based struct. Assumes begin, end and step not known at compile time Only used for trivial loops to save doing things like: std::vector<int> indices; for(int i=1, i<5; ++i) indices.push_back(i);.

Usage as:

auto rn = range<size_t>(1,5,1);
for (auto it=rn.begin();it!=rn.end();++it)
    std::cout << *it << ", ";

1, 2, 3, 4,

Public Functions

rrange(IntegerType ibegin, IntegerType iend, IntegerType step = 1)
iterator begin()
iterator end()
iterator begin() const
iterator end() const
struct iterator

Public Types

using value_type = IntegerType
using size_type = std::size_t
using difference_type = IntegerType
using pointer = value_type*
using reference = value_type&
using iterator_category = std::random_access_iterator_tag

Public Functions

iterator(rrange<value_type> &range, IntegerType v)
operator IntegerType() const
operator IntegerType&()
IntegerType operator*() const
IntegerType const *operator->() const
iterator &operator++()
iterator &operator++(int)
bool operator==(iterator const &other) const
bool operator!=(iterator const &other) const