mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
[wpimath] Add script for updating Drake (#3470)
Common functionality between the Drake and Eigen update scripts was refactored into a library.
This commit is contained in:
@@ -98,7 +98,7 @@ namespace assert {
|
||||
// require special handling.
|
||||
template <typename Condition>
|
||||
struct ConditionTraits {
|
||||
static constexpr bool is_valid = std::is_convertible<Condition, bool>::value;
|
||||
static constexpr bool is_valid = std::is_convertible_v<Condition, bool>;
|
||||
static bool Evaluate(const Condition& value) {
|
||||
return value;
|
||||
}
|
||||
@@ -113,7 +113,7 @@ struct ConditionTraits {
|
||||
#define DRAKE_DEMAND(condition) \
|
||||
do { \
|
||||
typedef ::drake::assert::ConditionTraits< \
|
||||
typename std::remove_cv<decltype(condition)>::type> Trait; \
|
||||
typename std::remove_cv_t<decltype(condition)>> Trait; \
|
||||
static_assert(Trait::is_valid, "Condition should be bool-convertible."); \
|
||||
if (!Trait::Evaluate(condition)) { \
|
||||
::drake::internal::AssertionFailed( \
|
||||
@@ -130,7 +130,7 @@ constexpr bool kDrakeAssertIsDisarmed = false;
|
||||
# define DRAKE_ASSERT(condition) DRAKE_DEMAND(condition)
|
||||
# define DRAKE_ASSERT_VOID(expression) do { \
|
||||
static_assert( \
|
||||
std::is_convertible<decltype(expression), void>::value, \
|
||||
std::is_convertible_v<decltype(expression), void>, \
|
||||
"Expression should be void."); \
|
||||
expression; \
|
||||
} while (0)
|
||||
@@ -142,10 +142,10 @@ constexpr bool kDrakeAssertIsDisarmed = true;
|
||||
} // namespace drake
|
||||
# define DRAKE_ASSERT(condition) static_assert( \
|
||||
::drake::assert::ConditionTraits< \
|
||||
typename std::remove_cv<decltype(condition)>::type>::is_valid, \
|
||||
typename std::remove_cv_t<decltype(condition)>>::is_valid, \
|
||||
"Condition should be bool-convertible.");
|
||||
# define DRAKE_ASSERT_VOID(expression) static_assert( \
|
||||
std::is_convertible<decltype(expression), void>::value, \
|
||||
std::is_convertible_v<decltype(expression), void>, \
|
||||
"Expression should be void.")
|
||||
#endif
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
namespace drake {
|
||||
namespace internal {
|
||||
|
||||
/// This is what DRAKE_ASSERT and DRAKE_DEMAND throw when our assertions are
|
||||
/// configured to throw.
|
||||
// This is what DRAKE_ASSERT and DRAKE_DEMAND throw when our assertions are
|
||||
// configured to throw.
|
||||
class assertion_error : public std::runtime_error {
|
||||
public:
|
||||
explicit assertion_error(const std::string& what_arg)
|
||||
|
||||
@@ -64,49 +64,3 @@ class Foo {
|
||||
(void) static_cast<Classname& (Classname::*)( \
|
||||
const Classname&)>(&Classname::operator=); \
|
||||
}
|
||||
|
||||
/** DRAKE_DECLARE_COPY_AND_MOVE_AND_ASSIGN declares (but does not define) the
|
||||
special member functions for copy-construction, copy-assignment,
|
||||
move-construction, and move-assignment. Drake's Doxygen is customized to
|
||||
render the declarations with appropriate comments.
|
||||
|
||||
This is useful when paired with DRAKE_DEFINE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN_T
|
||||
to work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57728 whereby the
|
||||
declaration and definition must be split. Once Drake no longer supports GCC
|
||||
versions prior to 6.3, this macro could be removed.
|
||||
|
||||
Invoke this this macro in the public section of the class declaration, e.g.:
|
||||
<pre>
|
||||
template <typename T>
|
||||
class Foo {
|
||||
public:
|
||||
DRAKE_DECLARE_COPY_AND_MOVE_AND_ASSIGN(Foo)
|
||||
|
||||
// ...
|
||||
};
|
||||
DRAKE_DEFINE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN_T(Foo)
|
||||
</pre>
|
||||
*/
|
||||
#define DRAKE_DECLARE_COPY_AND_MOVE_AND_ASSIGN(Classname) \
|
||||
Classname(const Classname&); \
|
||||
Classname& operator=(const Classname&); \
|
||||
Classname(Classname&&); \
|
||||
Classname& operator=(Classname&&); \
|
||||
/* Fails at compile-time if default-copy doesn't work. */ \
|
||||
static void DRAKE_COPYABLE_DEMAND_COPY_CAN_COMPILE() { \
|
||||
(void) static_cast<Classname& (Classname::*)( \
|
||||
const Classname&)>(&Classname::operator=); \
|
||||
}
|
||||
|
||||
/** Helper for DRAKE_DECLARE_COPY_AND_MOVE_AND_ASSIGN. Provides defaulted
|
||||
definitions for the four special member functions of a templated class.
|
||||
*/
|
||||
#define DRAKE_DEFINE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN_T(Classname) \
|
||||
template <typename T> \
|
||||
Classname<T>::Classname(const Classname<T>&) = default; \
|
||||
template <typename T> \
|
||||
Classname<T>& Classname<T>::operator=(const Classname<T>&) = default; \
|
||||
template <typename T> \
|
||||
Classname<T>::Classname(Classname<T>&&) = default; \
|
||||
template <typename T> \
|
||||
Classname<T>& Classname<T>::operator=(Classname<T>&&) = default;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
/// @file
|
||||
/// Provides a convenient wrapper to throw an exception when a condition is
|
||||
/// unmet. This is similar to an assertion, but uses exceptions instead of
|
||||
/// std::abort(), and cannot be disabled.
|
||||
/// ::abort(), and cannot be disabled.
|
||||
|
||||
namespace drake {
|
||||
namespace internal {
|
||||
@@ -23,7 +23,7 @@ void Throw(const char* condition, const char* func, const char* file, int line);
|
||||
#define DRAKE_THROW_UNLESS(condition) \
|
||||
do { \
|
||||
typedef ::drake::assert::ConditionTraits< \
|
||||
typename std::remove_cv<decltype(condition)>::type> Trait; \
|
||||
typename std::remove_cv_t<decltype(condition)>> Trait; \
|
||||
static_assert(Trait::is_valid, "Condition should be bool-convertible."); \
|
||||
if (!Trait::Evaluate(condition)) { \
|
||||
::drake::internal::Throw(#condition, __func__, __FILE__, __LINE__); \
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
|
||||
#include <Eigen/Core>
|
||||
|
||||
namespace drake::math {
|
||||
namespace drake {
|
||||
namespace math {
|
||||
|
||||
/// Computes the unique stabilizing solution X to the discrete-time algebraic
|
||||
/// Riccati equation:
|
||||
@@ -47,4 +48,6 @@ Eigen::MatrixXd DiscreteAlgebraicRiccatiEquation(
|
||||
const Eigen::Ref<const Eigen::MatrixXd>& Q,
|
||||
const Eigen::Ref<const Eigen::MatrixXd>& R,
|
||||
const Eigen::Ref<const Eigen::MatrixXd>& N);
|
||||
} // namespace drake::math
|
||||
} // namespace math
|
||||
} // namespace drake
|
||||
|
||||
|
||||
Reference in New Issue
Block a user