diff --git a/include/ircd/stdinc.h b/include/ircd/stdinc.h index 220b28557..f30a59a49 100644 --- a/include/ircd/stdinc.h +++ b/include/ircd/stdinc.h @@ -191,11 +191,9 @@ namespace ircd #include "vector_view.h" #include "array_view.h" #include "byte_view.h" -#include "tuple.h" #include "allocator.h" #include "buffer.h" #include "date.h" -#include "timer.h" #include "logger.h" #include "nacl.h" #include "rand.h" @@ -203,7 +201,6 @@ namespace ircd #include "ed25519.h" #include "info.h" #include "localee.h" -#include "life_guard.h" #include "color.h" #include "lex_cast.h" #include "stringops.h" diff --git a/include/ircd/life_guard.h b/include/ircd/util/life_guard.h similarity index 84% rename from include/ircd/life_guard.h rename to include/ircd/util/life_guard.h index 12e878f39..bd6d6a360 100644 --- a/include/ircd/life_guard.h +++ b/include/ircd/util/life_guard.h @@ -20,27 +20,10 @@ */ #pragma once -#define HAVE_IRCD_LIFE_GUARD_H +#define HAVE_IRCD_UTIL_LIFE_GUARD_H -namespace ircd +namespace ircd::util { - // Tests if type inherits from std::enable_shared_from_this<> - template - constexpr typename std::enable_if::value, bool>::type - is_shared_from_this() - { - return std::is_base_of, T>(); - } - - // Unconditional failure for fwd-declared incomplete types, which - // obviously don't inherit from std::enable_shared_from_this<> - template - constexpr typename std::enable_if::value, bool>::type - is_shared_from_this() - { - return false; - } - // Convenience functions for types shared_from_this template std::shared_ptr shared_from(const T &t); template std::shared_ptr shared_from(T &t); @@ -70,7 +53,7 @@ namespace ircd /// } /// template -struct ircd::life_guard +struct ircd::util::life_guard :std::shared_ptr { // This constructor is used when the templated type inherits from std::enable_shared_from_this<> @@ -103,28 +86,28 @@ struct ircd::life_guard template std::weak_ptr -ircd::weak_from(T &t) +ircd::util::weak_from(T &t) { return shared_from(t); }; template std::weak_ptr -ircd::weak_from(const T &t) +ircd::util::weak_from(const T &t) { return shared_from(t); }; template std::shared_ptr -ircd::shared_from(T &t) +ircd::util::shared_from(T &t) { return dynamic_pointer_cast(t.shared_from_this()); }; template std::shared_ptr -ircd::shared_from(const T &t) +ircd::util::shared_from(const T &t) { return dynamic_pointer_cast(t.shared_from_this()); }; diff --git a/include/ircd/timer.h b/include/ircd/util/timer.h similarity index 63% rename from include/ircd/timer.h rename to include/ircd/util/timer.h index 47fdc80f2..ab5eaf1db 100644 --- a/include/ircd/timer.h +++ b/include/ircd/util/timer.h @@ -1,24 +1,21 @@ -/* - * Copyright (C) 2016 Charybdis Development Team - * Copyright (C) 2016 Jason Volk - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. #pragma once #define HAVE_IRCD_UTIL_TIMER_H diff --git a/include/ircd/tuple.h b/include/ircd/util/tuple.h similarity index 88% rename from include/ircd/tuple.h rename to include/ircd/util/tuple.h index 9814c0c51..1878611ad 100644 --- a/include/ircd/tuple.h +++ b/include/ircd/util/tuple.h @@ -1,37 +1,31 @@ -/* - * charybdis: 21st Century IRC++d - * util.h: Miscellaneous utilities - * - * Copyright (C) 2016 Charybdis Development Team - * Copyright (C) 2016 Jason Volk - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice is present in all copies. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - */ +// Copyright (C) Matrix Construct Developers, Authors & Contributors +// Copyright (C) 2016-2018 Jason Volk +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. +// +// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +// IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. #pragma once -#define HAVE_IRCD_TUPLE_H +#define HAVE_IRCD_UTIL_TUPLE_H // // Utilities for std::tuple // -namespace ircd::util -{ +namespace ircd { +namespace util { template constexpr bool @@ -431,4 +425,5 @@ tuple_offset(const tuple &t) }; } -} // namespace ircd::util +} // namespace util +} // namespace ircd diff --git a/include/ircd/util/typography.h b/include/ircd/util/typography.h index a86cfcf4e..e92b98b25 100644 --- a/include/ircd/util/typography.h +++ b/include/ircd/util/typography.h @@ -45,7 +45,6 @@ namespace util { #define IRCD_USING_OVERLOAD(ALIAS, ORIGIN) \ static constexpr const auto &ALIAS{ORIGIN} - // // Typedef macros // @@ -82,9 +81,8 @@ struct NAME \ #define IRCD_STRONG_T(TYPE) \ IRCD_STRONG_TYPEDEF(TYPE, IRCD_UNIQUE(strong_t)) - // -// Debug size of structure at compile time. +// Debug sizeof structure at compile time // /// Internal use only @@ -100,7 +98,6 @@ struct _TEST_SIZEOF_; #define IRCD_TEST_SIZEOF(name) \ ircd::util::_TEST_SIZEOF_ _test_; - // // Test if type is forward declared or complete // @@ -116,7 +113,6 @@ struct is_complete :std::true_type {}; - // // Test if type is a specialization of a template // @@ -135,6 +131,26 @@ struct is_specialization_of, T> :std::true_type {}; +// +// Test if type is shared_from_this +// + +/// Tests if type inherits from std::enable_shared_from_this<> +template +constexpr typename std::enable_if::value, bool>::type +is_shared_from_this() +{ + return std::is_base_of, T>(); +} + +/// Unconditional failure for fwd-declared incomplete types, which +/// obviously don't inherit from std::enable_shared_from_this<> +template +constexpr typename std::enable_if::value, bool>::type +is_shared_from_this() +{ + return false; +} // // Misc type testing boilerplates @@ -171,7 +187,6 @@ is_integer() return is_number() && !is_floating(); } - // // Convenience constexprs for iterators // @@ -197,6 +212,19 @@ is_input_iterator() return std::is_base_of::iterator_category>::value; } +/// Convenience loop to test std::is* on a character sequence +template +ssize_t +ctype(const char *begin, + const char *const &end) +{ + size_t i(0); + for(; begin != end; ++begin, ++i) + if(!test(static_cast(*begin))) + return i; + + return -1; +} /// Zero testing functor (work in progress) /// @@ -244,20 +272,5 @@ struct is_zero } }; - -/// Convenience loop to test std::is* on a character sequence -template -ssize_t -ctype(const char *begin, - const char *const &end) -{ - size_t i(0); - for(; begin != end; ++begin, ++i) - if(!test(static_cast(*begin))) - return i; - - return -1; -} - -} // namespace ircd } // namespace util +} // namespace ircd diff --git a/include/ircd/util/util.h b/include/ircd/util/util.h index 7d7421e13..e885b3299 100644 --- a/include/ircd/util/util.h +++ b/include/ircd/util/util.h @@ -49,6 +49,9 @@ namespace ircd #include "unique_iterator.h" #include "instance_list.h" #include "bswap.h" +#include "tuple.h" +#include "timer.h" +#include "life_guard.h" // Unsorted section namespace ircd {