From 5749565e526f932941db53bec1f0a742ec35e005 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Thu, 19 Nov 2020 15:28:48 -0500 Subject: [PATCH] FIx indentation for Values-inl.h --- gtsam/nonlinear/Values-inl.h | 183 ++++++++++++++++++----------------- 1 file changed, 92 insertions(+), 91 deletions(-) diff --git a/gtsam/nonlinear/Values-inl.h b/gtsam/nonlinear/Values-inl.h index 6829e859b6..ba4ed54d3f 100644 --- a/gtsam/nonlinear/Values-inl.h +++ b/gtsam/nonlinear/Values-inl.h @@ -259,97 +259,98 @@ namespace gtsam { } /* ************************************************************************* */ - template<> - inline bool Values::filterHelper(const boost::function filter, - const ConstKeyValuePair& key_value) { - // Filter and check the type - return filter(key_value.key); - } - - /* ************************************************************************* */ - - namespace internal { - - // Check the type and throw exception if incorrect - // Generic version, partially specialized below for various Eigen Matrix types - template - struct handle { - ValueType operator()(Key j, const Value* const pointer) { - try { - // value returns a const ValueType&, and the return makes a copy !!!!! - return dynamic_cast&>(*pointer).value(); - } catch (std::bad_cast&) { - throw ValuesIncorrectType(j, typeid(*pointer), typeid(ValueType)); - } - } - }; - - template - struct handle_matrix; - - // Handle dynamic matrices - template - struct handle_matrix, true> { - Eigen::Matrix operator()(Key j, const Value* const pointer) { - try { - // value returns a const Matrix&, and the return makes a copy !!!!! - return dynamic_cast>&>(*pointer).value(); - } catch (std::bad_cast&) { - // If a fixed matrix was stored, we end up here as well. - throw ValuesIncorrectType(j, typeid(*pointer), typeid(Eigen::Matrix)); - } - } - }; - - // Handle fixed matrices - template - struct handle_matrix, false> { - Eigen::Matrix operator()(Key j, const Value* const pointer) { - try { - // value returns a const MatrixMN&, and the return makes a copy !!!!! - return dynamic_cast>&>(*pointer).value(); - } catch (std::bad_cast&) { - Matrix A; - try { - // Check if a dynamic matrix was stored - A = handle_matrix()(j, pointer); // will throw if not.... - } catch (const ValuesIncorrectType&) { - // Or a dynamic vector - A = handle_matrix()(j, pointer); // will throw if not.... - } - // Yes: check size, and throw if not a match - if (A.rows() != M || A.cols() != N) - throw NoMatchFoundForFixed(M, N, A.rows(), A.cols()); - else - return A; // copy but not malloc - } - } - }; - - // Handle matrices - template - struct handle> { - Eigen::Matrix operator()(Key j, const Value* const pointer) { - return handle_matrix, - (M == Eigen::Dynamic || N == Eigen::Dynamic)>()(j, pointer); - } - }; - - } // internal - - /* ************************************************************************* */ - template - const ValueType Values::at(Key j) const { - // Find the item - KeyValueMap::const_iterator item = values_.find(j); - - // Throw exception if it does not exist - if (item == values_.end()) throw ValuesKeyDoesNotExist("at", j); - - // Check the type and throw exception if incorrect - // h() split in two lines to avoid internal compiler error (MSVC2017) - auto h = internal::handle(); - return h(j, item->second); + template<> + inline bool Values::filterHelper(const boost::function filter, + const ConstKeyValuePair& key_value) { + // Filter and check the type + return filter(key_value.key); + } + + /* ************************************************************************* */ + + namespace internal { + + // Check the type and throw exception if incorrect + // Generic version, partially specialized below for various Eigen Matrix types + template + struct handle { + ValueType operator()(Key j, const Value* const pointer) { + try { + // value returns a const ValueType&, and the return makes a copy !!!!! + return dynamic_cast&>(*pointer).value(); + } catch (std::bad_cast&) { + throw ValuesIncorrectType(j, typeid(*pointer), typeid(ValueType)); + } + } + }; + + template + struct handle_matrix; + + // Handle dynamic matrices + template + struct handle_matrix, true> { + Eigen::Matrix operator()(Key j, const Value* const pointer) { + try { + // value returns a const Matrix&, and the return makes a copy !!!!! + return dynamic_cast>&>(*pointer).value(); + } catch (std::bad_cast&) { + // If a fixed matrix was stored, we end up here as well. + throw ValuesIncorrectType(j, typeid(*pointer), typeid(Eigen::Matrix)); + } + } + }; + + // Handle fixed matrices + template + struct handle_matrix, false> { + Eigen::Matrix operator()(Key j, const Value* const pointer) { + try { + // value returns a const MatrixMN&, and the return makes a copy !!!!! + return dynamic_cast>&>(*pointer).value(); + } catch (std::bad_cast&) { + Matrix A; + try { + // Check if a dynamic matrix was stored + A = handle_matrix()(j, pointer); // will throw if not.... + } catch (const ValuesIncorrectType&) { + // Or a dynamic vector + A = handle_matrix()(j, pointer); // will throw if not.... + } + // Yes: check size, and throw if not a match + if (A.rows() != M || A.cols() != N) + throw NoMatchFoundForFixed(M, N, A.rows(), A.cols()); + else + return A; // copy but not malloc + } + } + }; + + // Handle matrices + template + struct handle> { + Eigen::Matrix operator()(Key j, const Value* const pointer) { + return handle_matrix, + (M == Eigen::Dynamic || N == Eigen::Dynamic)>()(j, pointer); + } + }; + + } // internal + + /* ************************************************************************* + */ + template + const ValueType Values::at(Key j) const { + // Find the item + KeyValueMap::const_iterator item = values_.find(j); + + // Throw exception if it does not exist + if (item == values_.end()) throw ValuesKeyDoesNotExist("at", j); + + // Check the type and throw exception if incorrect + // h() split in two lines to avoid internal compiler error (MSVC2017) + auto h = internal::handle(); + return h(j, item->second); } /* ************************************************************************* */