Resurgence (PY2022)
Codebase for the Husky Robotics 2021-2022 rover Resurgence
Toggle main menu visibility
Loading...
Searching...
No Matches
src
utils
core.h
1
#pragma once
2
3
#include <
functional
>
4
#include <
string
>
5
#include <
tuple
>
6
#include <
unordered_map
>
7
#include <
unordered_set
>
8
#include <
utility
>
9
10
#include <frozen/string.h>
11
12
namespace
util
{
13
22
bool
almostEqual
(
double
a,
double
b,
double
threshold = 1e-6);
23
30
template
<
typename
K,
typename
V>
31
std::unordered_set<K>
keySet
(
const
std::unordered_map<K, V>
& input) {
32
std::unordered_set<K>
output;
33
std::transform
(input.
begin
(), input.
end
(),
std::inserter
(output, output.
end
()),
34
[](
auto
pair) { return pair.first; });
35
return
output;
36
}
37
50
template
<
typename
T>
51
std::string
to_string(
const
T& val) {
52
return
std::to_string(val);
53
}
54
61
template
<>
62
std::string
to_string<bool>
(
const
bool
& val);
63
67
frozen::string
freezeStr
(
const
std::string
& str);
68
77
template
<
typename
T,
typename
U>
78
std::tuple<T, U>
pairToTuple
(
const
std::pair<T, U>
& pair) {
79
return
std::tuple<T, U>
(pair.
first
, pair.
second
);
80
}
81
85
class
RAIIHelper
{
86
public
:
92
RAIIHelper
(
const
std::function<
void
()>& f);
93
94
RAIIHelper
(
const
RAIIHelper
&) =
delete
;
95
104
RAIIHelper
(
RAIIHelper
&& other);
105
106
RAIIHelper
& operator=(
const
RAIIHelper
&) =
delete
;
107
111
~RAIIHelper
();
112
113
private
:
114
std::function<void()> f;
115
};
116
117
}
// namespace util
functional
string
tuple
unordered_map
unordered_set
utility
std::transform
_OutputIterator transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __unary_op)
std::inserter
insert_iterator< _Container > inserter(_Container &__x, _Iterator __i)
std::string
_GLIBCXX_END_NAMESPACE_CXX11 typedef basic_string< char > string
std::tuple
std::pair
std::pair::first
_T1 first
std::pair::second
_T2 second
std::unordered_map
std::unordered_map::end
iterator end() noexcept
std::unordered_map::begin
iterator begin() noexcept
std::unordered_set
std::unordered_set::end
iterator end() noexcept
util::RAIIHelper::RAIIHelper
RAIIHelper(const std::function< void()> &f)
Construct a new RAIIHelper.
Definition
core.cpp:18
util::RAIIHelper::~RAIIHelper
~RAIIHelper()
Destroy the RAIIHelper object, executing the given function, if not empty.
Definition
core.cpp:24
util
A collection of utility functions and classes with common use-cases.
Definition
SwerveController.cpp:145
util::freezeStr
frozen::string freezeStr(const std::string &str)
Convert the given std::string to a frozen::string.
Definition
core.cpp:14
util::almostEqual
bool almostEqual(double a, double b, double threshold)
Check if two numbers are approximately equal.
Definition
core.cpp:5
util::to_string< bool >
std::string to_string< bool >(const bool &val)
Converts a boolean to a string.
Definition
core.cpp:10
util::keySet
std::unordered_set< K > keySet(const std::unordered_map< K, V > &input)
Get the keys of the given map.
Definition
core.h:31
util::pairToTuple
std::tuple< T, U > pairToTuple(const std::pair< T, U > &pair)
Converts a pair to a tuple.
Definition
core.h:78
Generated by
1.17.0