From eabf93bc2af6535d860f8ddeb93bc94fad3fc150 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 1 Aug 2017 14:16:55 +1000 Subject: [PATCH] view: remove ipp file in preference of inline code --- CMakeLists.txt | 1 - json/flat.cpp.rl | 3 +- json/schema.cpp | 3 +- string.cpp | 4 +- view.cpp | 1 + view.hpp | 130 +++++++++++++++++++----- view.ipp | 256 ----------------------------------------------- 7 files changed, 113 insertions(+), 285 deletions(-) delete mode 100644 view.ipp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e565610..fbee8d3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -417,7 +417,6 @@ list ( version.cpp version.hpp view.cpp - view.ipp view.hpp ) diff --git a/json/flat.cpp.rl b/json/flat.cpp.rl index bf577c3d..0ca04ba3 100644 --- a/json/flat.cpp.rl +++ b/json/flat.cpp.rl @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with libgim. If not, see . * - * Copyright 2010-2015 Danny Robson + * Copyright 2010-2017 Danny Robson */ #include "json/flat.hpp" +#include "debug.hpp" #include "json/except.hpp" #include "preprocessor.hpp" diff --git a/json/schema.cpp b/json/schema.cpp index 172c1de6..d135ebb6 100644 --- a/json/schema.cpp +++ b/json/schema.cpp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2015 Danny Robson + * Copyright 2015-2017 Danny Robson */ #include "./schema.hpp" @@ -19,6 +19,7 @@ #include "./tree.hpp" #include "./except.hpp" +#include "../debug.hpp" #include "../io.hpp" #include "../maths.hpp" diff --git a/string.cpp b/string.cpp index 34423493..55ce664d 100644 --- a/string.cpp +++ b/string.cpp @@ -11,11 +11,13 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2011-2016 Danny Robson + * Copyright 2011-2017 Danny Robson */ #include "./string.hpp" +#include "./debug.hpp" + #include #include #include diff --git a/view.cpp b/view.cpp index 40d011dd..11d60ed0 100644 --- a/view.cpp +++ b/view.cpp @@ -16,6 +16,7 @@ #include "./view.hpp" +#include #include diff --git a/view.hpp b/view.hpp index 00fa5b83..3b893c1e 100644 --- a/view.hpp +++ b/view.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace util { template @@ -31,32 +32,80 @@ namespace util { using value_type = typename std::iterator_traits>::value_type; constexpr - view (T first, T last) noexcept; + view (T first, T last) noexcept: + m_begin (first), + m_end (last) + { ; } - template constexpr explicit view ( K &klass); - template constexpr explicit view (const K &klass); + template + constexpr explicit + view (K &klass): + m_begin (std::begin (klass)), + m_end (std::end (klass)) + { ; } - constexpr T& begin (void) noexcept; - constexpr T& end (void) noexcept; + template + constexpr explicit + view (const K &klass): + m_begin (std::begin (klass)), + m_end (std::end (klass)) + { ; } - constexpr const T& begin (void) const noexcept; - constexpr const T& end (void) const noexcept; + constexpr T& begin (void) noexcept { return m_begin; } + constexpr T& end (void) noexcept { return m_end; } - constexpr const T& cbegin (void) const noexcept; - constexpr const T& cend (void) const noexcept; + constexpr const T& begin (void) const noexcept { return cbegin (); } + constexpr const T& end (void) const noexcept { return cend (); } + + constexpr const T& cbegin (void) const noexcept { return m_begin; } + constexpr const T& cend (void) const noexcept { return m_end; } auto data (void) { return begin (); } auto data (void) const { return begin (); } - constexpr T find (const value_type&) const noexcept; + constexpr T + find (const value_type &v) const noexcept + { + for (T i = cbegin (); i != cend (); ++i) + if (*i == v) + return i; + return cend (); + } - constexpr bool empty (void) const noexcept; - constexpr size_t size (void) const noexcept; + constexpr bool + empty (void) const noexcept + { + return m_begin == m_end; + } - constexpr value_type& operator[] (size_t) noexcept; - constexpr const value_type& operator[] (size_t) const noexcept; + constexpr auto + size (void) const noexcept + { + return std::distance (m_begin, m_end); + } - bool operator== (view) const noexcept; + constexpr value_type& + operator[] (size_t idx) noexcept + { + auto it = begin (); + std::advance (it, idx); + return *it; + } + + constexpr const value_type& + operator[] (size_t idx) const noexcept + { + auto it = begin (); + std::advance (it, idx); + return *it; + } + + bool + operator== (const view &rhs) const noexcept + { + return rhs.m_begin == m_begin && + rhs.m_end == m_end; + } private: T m_begin; @@ -65,15 +114,24 @@ namespace util { template auto - make_view (const T (&)[N]); + make_view (const T (&arr)[N]) + { + return util::view (arr + 0, arr + N); + } template auto - make_view (T&); + make_view (T &t) + { + return util::view { std::begin (t), std::end (t) }; + } template auto - make_view (const T&); + make_view (const T &t) + { + return util::view { std::cbegin (t), std::cend (t) }; + } template auto @@ -81,7 +139,10 @@ namespace util { template auto - make_cview (const T&); + make_cview (const T &t) + { + return util::view { std::cbegin (t), std::cend (t) }; + } template auto @@ -98,16 +159,37 @@ namespace util { } // string conversions - view make_view (const char *str); - view make_view (char *str); + inline + view make_view (const char *str) + { + return { str, str + strlen (str) }; + } + + inline + view make_view (char *str) + { + return { str, str + strlen (str) }; + } template view - make_view (const std::basic_string&); + make_view (const std::basic_string &str) + { + return { + std::data (str), + std::data (str) + std::size (str) + }; + } template view - make_view (std::basic_string&); + make_view (std::basic_string &str) + { + return { + std::data (str), + std::data (str) + std::size (str) + }; + } template view @@ -136,6 +218,4 @@ namespace util { operator<< (std::ostream&, view); } -#include "./view.ipp" - #endif diff --git a/view.ipp b/view.ipp deleted file mode 100644 index dc42b71b..00000000 --- a/view.ipp +++ /dev/null @@ -1,256 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * Copyright 2015 Danny Robson - */ - - -#ifdef __UTIL_VIEW_IPP -#error -#endif -#define __UTIL_VIEW_IPP - - -#include "./debug.hpp" -#include "./iterator.hpp" - - -/////////////////////////////////////////////////////////////////////////////// -template -constexpr -util::view::view (T _begin, T _end) noexcept: - m_begin (_begin), - m_end (_end) -{ ; } - - -//----------------------------------------------------------------------------- -template -template -constexpr -util::view::view (K &data): - m_begin (std::begin (data)), - m_end (std::end (data)) -{ ; } - - -//----------------------------------------------------------------------------- -template -template -constexpr -util::view::view (const K &data): - m_begin (std::begin (data)), - m_end (std::end (data)) -{ ; } - - -/////////////////////////////////////////////////////////////////////////////// -template -constexpr T& -util::view::begin (void) noexcept -{ - return m_begin; -} - - -//----------------------------------------------------------------------------- -template -constexpr T& -util::view::end (void) noexcept -{ - return m_end; -} - - -//----------------------------------------------------------------------------- -template -constexpr const T& -util::view::begin (void) const noexcept -{ - return cbegin (); -} - - -//----------------------------------------------------------------------------- -template -constexpr const T& -util::view::end (void) const noexcept -{ - return cend (); -} - - -//----------------------------------------------------------------------------- -template -constexpr const T& -util::view::cbegin (void) const noexcept -{ - return m_begin; -} - - -//----------------------------------------------------------------------------- -template -constexpr const T& -util::view::cend (void) const noexcept -{ - return m_end; -} - - -/////////////////////////////////////////////////////////////////////////////// -template -constexpr T -util::view::find (const value_type &v) const noexcept -{ - for (T i = cbegin (); i != cend (); ++i) - if (*i == v) - return i; - return cend (); -} - - -/////////////////////////////////////////////////////////////////////////////// -template -constexpr -bool -util::view::empty (void) const noexcept -{ - return m_begin == m_end; -} - - -//----------------------------------------------------------------------------- -template -constexpr -size_t -util::view::size (void) const noexcept -{ - return m_end - m_begin; -} - - -/////////////////////////////////////////////////////////////////////////////// -template -constexpr -const typename util::view::value_type& -util::view::operator[] (size_t idx) const noexcept -{ - return m_begin[idx]; -} - - -//----------------------------------------------------------------------------- -template -constexpr -typename util::view::value_type& -util::view::operator[] (size_t idx) noexcept -{ - return m_begin[idx]; -} - - -/////////////////////////////////////////////////////////////////////////////// -template -bool -util::view::operator== (const view rhs) const noexcept -{ - return rhs.m_begin == m_begin && - rhs.m_end == m_end; -} - - -//----------------------------------------------------------------------------- -template -bool -util::operator!= (const view a, const view b) -{ - return !(a == b); -} - - -/////////////////////////////////////////////////////////////////////////////// -template -auto -util::make_view (const T (&arr)[N]) -{ - return util::view (arr + 0, arr + N); -} - - -//----------------------------------------------------------------------------- -template -auto -util::make_view (T &t) -{ - return util::view { std::begin (t), std::end (t) }; -} - - -//----------------------------------------------------------------------------- -template -auto -util::make_view (const T &t) -{ - return util::view { std::cbegin (t), std::cend (t) }; -} - - -//----------------------------------------------------------------------------- -template -auto -util::make_cview (const T &t) -{ - return util::view { std::cbegin (t), std::cend (t) }; -} - - -/////////////////////////////////////////////////////////////////////////////// -inline -util::view -util::make_view (const char *str) -{ - return { str, str + strlen (str) }; -} - -//----------------------------------------------------------------------------- -inline -util::view -util::make_view (char *str) -{ - return { str, str + strlen (str) }; -} - - -//----------------------------------------------------------------------------- -template -util::view -util::make_view (const std::basic_string &str) -{ - return { - std::data (str), - std::data (str) + std::size (str) - }; -} - - -//----------------------------------------------------------------------------- -template -util::view -util::make_view (std::basic_string &str) -{ - return { - std::data (str), - std::data (str) + std::size (str) - }; -}