From 9766b5c63a6194fff6fa2ee5994ec95c1e004299 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 10 Jun 2014 23:57:06 +0100 Subject: [PATCH] refs #245 & #210 style --- src/blackmisc/tuple.h | 49 +++++++++++++---------------------- src/blackmisc/tuple_private.h | 30 +++++---------------- 2 files changed, 25 insertions(+), 54 deletions(-) diff --git a/src/blackmisc/tuple.h b/src/blackmisc/tuple.h index f1ab2d34a..7fe91f341 100644 --- a/src/blackmisc/tuple.h +++ b/src/blackmisc/tuple.h @@ -3,9 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/*! - \file -*/ +//! \file #ifndef BLACKMISC_TUPLE_H #define BLACKMISC_TUPLE_H @@ -13,7 +11,7 @@ #include "tuple_private.h" /*! - * \defgroup Tuples Tuples Simplified handling of class members (CValueObject) by std::tuple + * \defgroup Tuples Tuple conversion of object data members */ /*! @@ -64,7 +62,7 @@ return members; \ } \ public: \ - static auto constToTuple(const T &o) -> decltype(BlackMisc::tie MEMBERS) \ + static auto constToTuple(const T &o) -> decltype(BlackMisc::tie MEMBERS) \ { \ return BlackMisc::tie MEMBERS; \ } \ @@ -123,39 +121,27 @@ namespace BlackMisc // BLACK_DECLARE_TUPLE_CONVERSION generates an explicit specialization of TupleConverter, // so this unspecialized template will only be used if the macro is missing. It is also // a good place to put Doxygen comments to document the API of the macro-generated specializations. + + static_assert(std::is_void::value, // always false; is_void<> trick is just to make the condition dependent on the template parameter T + "Missing BLACK_DECLARE_TUPLE_CONVERSION macro for T"); + public: /*! * \name Static Private Member Functions - * \brief Returns a tuple of references to object's data members as they were declared in BLACK_DECLARE_TUPLE_CONVERSION(). + * \brief Returns a tuple of references to object's data members listed in BLACK_DECLARE_TUPLE_CONVERSION(). * Can be used like std::tie . */ //! @{ - static std::tuple<> toTuple(const T &object) - { - static_assert(std::is_void::value, // always false; is_void<> trick is just to make the condition dependent on the template parameter T - "Missing BLACK_DECLARE_TUPLE_CONVERSION macro for T"); - Q_UNUSED(object); - return std::tuple<>(); - } - static std::tuple<> toTuple(T &object) - { - static_assert(std::is_void::value, // always false; is_void<> trick is just to make the condition dependent on the template parameter T - "Missing BLACK_DECLARE_TUPLE_CONVERSION macro for T"); - Q_UNUSED(object); - return std::tuple<>(); - } - static std::tuple<> constToTuple(const T &object) - { - return toTuple(object); - } - static const QStringList jsonMembers() - { - static_assert(std::is_void::value, // always false; is_void<> trick is just to make the condition dependent on the template parameter T - "Missing BLACK_DECLARE_TUPLE_CONVERSION macro for T"); - static QStringList members; - return members; - } + static std::tuple<> toTuple(const T &object); + static std::tuple<> toTuple(T &object); + static std::tuple<> constToTuple(const T &object); //! @} + + /*! + * \name Static Private Member Functions + * \brief Returns a list of the names of the tuple members. + */ + static const QStringList &jsonMembers(); }; // Needed so that our qHash overload doesn't hide the qHash overloads in the global namespace. @@ -165,6 +151,7 @@ namespace BlackMisc /*! * \brief Works like std::tie, and allows us to hook in our own customizations. + * \ingroup Tuples */ template auto tie(Ts &&... args) -> decltype(std::make_tuple(Private::tieHelper(args)...)) diff --git a/src/blackmisc/tuple_private.h b/src/blackmisc/tuple_private.h index 8e2befe2e..942fa368f 100644 --- a/src/blackmisc/tuple_private.h +++ b/src/blackmisc/tuple_private.h @@ -3,11 +3,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/*! - \file - Private implementation details used by tuple.h -*/ - #ifndef BLACKMISC_TUPLE_PRIVATE_H #define BLACKMISC_TUPLE_PRIVATE_H @@ -30,15 +25,13 @@ namespace BlackMisc namespace Private { - // Using SFINAE to help detect missing BLACK_ENABLE_TUPLE_CONVERSION macro in static_assert - //! \private - std::false_type hasEnabledTupleConversionHelper(...); + // Inhibit doxygen warnings about missing documentation + //! \cond PRIVATE - //! \private + // Using SFINAE to help detect missing BLACK_ENABLE_TUPLE_CONVERSION macro in static_assert + std::false_type hasEnabledTupleConversionHelper(...); template typename T::EnabledTupleConversion hasEnabledTupleConversionHelper(T *); - - //! \private template struct HasEnabledTupleConversion { @@ -47,15 +40,12 @@ namespace BlackMisc }; // Using tag dispatch to select which implementation of compare() to use - //! \private - //! @{ template int compareHelper(const T &a, const T &b, std::true_type isCValueObjectTag) { Q_UNUSED(isCValueObjectTag); return compare(a, b); } - template int compareHelper(const T &a, const T &b, std::false_type isCValueObjectTag) { @@ -71,11 +61,8 @@ namespace BlackMisc typedef typename std::decay::type>::type Element; return compareHelper(std::get(a), std::get(b), typename std::is_base_of::type()); } - //! @} // Our own implementation of std::index_sequence (because not implemented by MSVC2013) - //! \private - //! @{ template struct index_sequence { @@ -94,20 +81,15 @@ namespace BlackMisc }; template using make_index_sequence = typename GenSequence<0, C>::type; - //! @} // Helper which will allow us to hook in our own customizations into BlackMisc::tie - //! \private - //! @{ template std::reference_wrapper tieHelper(T &obj) { return obj; } - //! @} - // Applying operations to all elements in a tuple, using index_sequence instead of recursion - //! \private + // Applying operations to all elements in a tuple, using index_sequence for clean recursion class TupleHelper { public: @@ -217,6 +199,8 @@ namespace BlackMisc static uint hashImpl(uint head, Ts... tail) { return head ^ hashImpl(tail...); } }; + //! \endcond + } // namespace Private } // namespace BlackMisc