preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Helpers.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <limits>
5#include <map>
6#include <set>
7#include <vector>
8
9namespace precice::utils {
10
12template <class Out, class In>
13inline bool isTruncated(In in)
14{
15 return (in > std::numeric_limits<Out>::max()) ||
16 (In(-1) < In(0) && in < std::numeric_limits<Out>::min());
17}
18
20inline bool isValidPort(int port)
21{
22 return (port >= 0) && !utils::isTruncated<unsigned short>(port);
23}
24
26inline bool xOR(bool lhs, bool rhs)
27{
28 return (lhs && (!rhs)) || ((!lhs) && rhs);
29}
30
37template <typename ELEMENT_T>
38bool contained(const ELEMENT_T &element, const std::vector<ELEMENT_T> &vec)
39{
40 return std::find(vec.begin(), vec.end(), element) != vec.end();
41}
42
43template <typename KEY_T, typename ELEMENT_T>
45 const KEY_T &key,
47{
48 return map.find(key) != map.end();
49}
50
51template <typename KEY_T>
53 const KEY_T &key,
54 const std::set<KEY_T> &set)
55{
56 return set.find(key) != set.end();
57}
58
61
62} // namespace precice::utils
T begin(T... args)
T end(T... args)
T find(T... args)
contains precice-related utilities.
bool contained(const ELEMENT_T &element, const std::vector< ELEMENT_T > &vec)
Returns true, if given element is in vector, otherwise false.
Definition Helpers.hpp:38
bool isTruncated(In in)
Returns true, if numerical truncation happens in case of type conversion.
Definition Helpers.hpp:13
bool xOR(bool lhs, bool rhs)
Exclusive "or" logical operation. Returns true, if either lhs or rhs are true.
Definition Helpers.hpp:26
bool isValidPort(int port)
Returns true if the argument represents a valid port.
Definition Helpers.hpp:20
bool isMachineBigEndian()
Returns true if machine is big-endian needed for parallel vtk output.
Definition Helpers.cpp:5