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