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, classContainer>
static voidpeakingduck::util::split(std::istream &stream, Container &cont)¶ Split from a stream using single delimiter per line
-
static void
peakingduck::util::ltrim(std::string &s)¶
-
static void
peakingduck::util::rtrim(std::string &s)¶
-
static void
peakingduck::util::ltrim(std::string &s, char delimiter)¶
-
static void
peakingduck::util::rtrim(std::string &s, char delimiter)¶
-
static void
peakingduck::util::trim(std::string &s)¶
-
template<typename
T>
static 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:
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]
values = [8, 2, 5, 2, 6, 6, 9, 23, 12] index = 4 nouter = 3 ninner = 0 includeindex = False
=> [2, 5, 2, 6, 9, 23]
values = [8, 2, 5, 2, 6, 6, 9, 23, 12] index = 4 nouter = 3 ninner = 1 includeindex = True
=> [2, 5, 6, 9, 23]
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, IntegerTypeibegin, IntegerTypeiend, IntegerTypestep= 1>
structrange¶ - #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,
-
struct
iterator¶ Public Types
-
template<>
usingvalue_type= IntegerType¶
-
template<>
usingsize_type= std::size_t¶
-
template<>
usingdifference_type= IntegerType¶
-
template<>
usingpointer= value_type *¶
-
template<>
usingreference= value_type&¶
-
template<>
usingiterator_category= std::random_access_iterator_tag¶
Public Functions
-
template<>
iterator(IntegerType v)¶
-
template<>
operator IntegerType() const¶
-
template<>
operator IntegerType&()¶
-
template<>
IntegerTypeoperator*() const¶
-
template<>
IntegerType const *operator->() const¶
-
template<>
iterator &operator++()¶
-
template<>
iterator &operator++(int)¶
-
template<>
booloperator==(iterator const &other) const¶
-
template<>
booloperator!=(iterator const &other) const¶
-
template<>
-
struct
-
template<typename
IntegerType>
structrrange¶ - #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)¶
-
struct
iterator¶ Public Types
-
template<>
usingvalue_type= IntegerType¶
-
template<>
usingsize_type= std::size_t¶
-
template<>
usingdifference_type= IntegerType¶
-
template<>
usingpointer= value_type *¶
-
template<>
usingreference= value_type&¶
-
template<>
usingiterator_category= std::random_access_iterator_tag¶
Public Functions
-
template<>
iterator(rrange<value_type> &range, IntegerType v)¶
-
template<>
operator IntegerType() const¶
-
template<>
operator IntegerType&()¶
-
template<>
IntegerTypeoperator*() const¶
-
template<>
IntegerType const *operator->() const¶
-
template<>
iterator &operator++()¶
-
template<>
iterator &operator++(int)¶
-
template<>
booloperator==(iterator const &other) const¶
-
template<>
booloperator!=(iterator const &other) const¶
-
template<>
-