preCICE v3.1.2
Loading...
Searching...
No Matches
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 {
10namespace utils {
11
13template <class Out, class In>
14inline bool isTruncated(In in)
15{
16 return (in > std::numeric_limits<Out>::max()) ||
17 (In(-1) < In(0) && in < std::numeric_limits<Out>::min());
18}
19
21inline bool isValidPort(int port)
22{
23 return (port >= 0) && !utils::isTruncated<unsigned short>(port);
24}
25
27inline bool xOR(bool lhs, bool rhs)
28{
29 return (lhs && (!rhs)) || ((!lhs) && rhs);
30}
31
38template <typename ELEMENT_T>
39bool contained(const ELEMENT_T &element, const std::vector<ELEMENT_T> &vec)
40{
41 return std::find(vec.begin(), vec.end(), element) != vec.end();
42}
43
44template <typename KEY_T, typename ELEMENT_T>
46 const KEY_T & key,
48{
49 return map.find(key) != map.end();
50}
51
52template <typename KEY_T>
54 const KEY_T & key,
55 const std::set<KEY_T> &set)
56{
57 return set.find(key) != set.end();
58}
59
62
63} // namespace utils
64} // namespace precice
T begin(T... args)
T end(T... args)
T find(T... args)
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:39
bool isTruncated(In in)
Returns true, if numerical truncation happens in case of type conversion.
Definition Helpers.hpp:14
bool xOR(bool lhs, bool rhs)
Exclusive "or" logical operation. Returns true, if either lhs or rhs are true.
Definition Helpers.hpp:27
bool isValidPort(int port)
Returns true if the argument represents a valid port.
Definition Helpers.hpp:21
bool isMachineBigEndian()
Returns true if machine is big-endian needed for parallel vtk output.
Definition Helpers.cpp:5
Main namespace of the precice library.