view: remove ipp file in preference of inline code

This commit is contained in:
Danny Robson 2017-08-01 14:16:55 +10:00
parent 523c7c7e38
commit eabf93bc2a
7 changed files with 113 additions and 285 deletions

View File

@ -417,7 +417,6 @@ list (
version.cpp
version.hpp
view.cpp
view.ipp
view.hpp
)

View File

@ -14,11 +14,12 @@
* You should have received a copy of the GNU General Public License
* along with libgim. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2010-2015 Danny Robson <danny@nerdcruft.net>
* Copyright 2010-2017 Danny Robson <danny@nerdcruft.net>
*/
#include "json/flat.hpp"
#include "debug.hpp"
#include "json/except.hpp"
#include "preprocessor.hpp"

View File

@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
* Copyright 2015-2017 Danny Robson <danny@nerdcruft.net>
*/
#include "./schema.hpp"
@ -19,6 +19,7 @@
#include "./tree.hpp"
#include "./except.hpp"
#include "../debug.hpp"
#include "../io.hpp"
#include "../maths.hpp"

View File

@ -11,11 +11,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2011-2016 Danny Robson <danny@nerdcruft.net>
* Copyright 2011-2017 Danny Robson <danny@nerdcruft.net>
*/
#include "./string.hpp"
#include "./debug.hpp"
#include <cstring>
#include <codecvt>
#include <locale>

View File

@ -16,6 +16,7 @@
#include "./view.hpp"
#include <algorithm>
#include <iterator>

130
view.hpp
View File

@ -23,6 +23,7 @@
#include <cstdlib>
#include <ostream>
#include <string>
#include <cstring>
namespace util {
template <typename T>
@ -31,32 +32,80 @@ namespace util {
using value_type = typename std::iterator_traits<remove_restrict_t<T>>::value_type;
constexpr
view (T first, T last) noexcept;
view (T first, T last) noexcept:
m_begin (first),
m_end (last)
{ ; }
template <typename K> constexpr explicit view ( K &klass);
template <typename K> constexpr explicit view (const K &klass);
template <typename K>
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 <typename K>
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 <typename T, size_t N>
auto
make_view (const T (&)[N]);
make_view (const T (&arr)[N])
{
return util::view<const T*> (arr + 0, arr + N);
}
template <typename T>
auto
make_view (T&);
make_view (T &t)
{
return util::view<decltype(std::begin (t))> { std::begin (t), std::end (t) };
}
template <typename T>
auto
make_view (const T&);
make_view (const T &t)
{
return util::view<decltype(std::cbegin (t))> { std::cbegin (t), std::cend (t) };
}
template <typename T>
auto
@ -81,7 +139,10 @@ namespace util {
template <typename T>
auto
make_cview (const T&);
make_cview (const T &t)
{
return util::view<decltype(std::cbegin (t))> { std::cbegin (t), std::cend (t) };
}
template <typename T>
auto
@ -98,16 +159,37 @@ namespace util {
}
// string conversions
view<const char*> make_view (const char *str);
view<char*> make_view (char *str);
inline
view<const char*> make_view (const char *str)
{
return { str, str + strlen (str) };
}
inline
view<char*> make_view (char *str)
{
return { str, str + strlen (str) };
}
template <typename CharT, typename TraitsT, typename AllocT>
view<const CharT*>
make_view (const std::basic_string<CharT,TraitsT,AllocT>&);
make_view (const std::basic_string<CharT,TraitsT,AllocT> &str)
{
return {
std::data (str),
std::data (str) + std::size (str)
};
}
template <typename CharT, typename TraitsT, typename AllocT>
view<CharT*>
make_view (std::basic_string<CharT,TraitsT,AllocT>&);
make_view (std::basic_string<CharT,TraitsT,AllocT> &str)
{
return {
std::data (str),
std::data (str) + std::size (str)
};
}
template <typename CharT, typename TraitsT, typename AllocT>
view<const CharT*>
@ -136,6 +218,4 @@ namespace util {
operator<< (std::ostream&, view<T>);
}
#include "./view.ipp"
#endif

256
view.ipp
View File

@ -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 <danny@nerdcruft.net>
*/
#ifdef __UTIL_VIEW_IPP
#error
#endif
#define __UTIL_VIEW_IPP
#include "./debug.hpp"
#include "./iterator.hpp"
///////////////////////////////////////////////////////////////////////////////
template <typename T>
constexpr
util::view<T>::view (T _begin, T _end) noexcept:
m_begin (_begin),
m_end (_end)
{ ; }
//-----------------------------------------------------------------------------
template <typename T>
template <typename K>
constexpr
util::view<T>::view (K &data):
m_begin (std::begin (data)),
m_end (std::end (data))
{ ; }
//-----------------------------------------------------------------------------
template <typename T>
template <typename K>
constexpr
util::view<T>::view (const K &data):
m_begin (std::begin (data)),
m_end (std::end (data))
{ ; }
///////////////////////////////////////////////////////////////////////////////
template <typename T>
constexpr T&
util::view<T>::begin (void) noexcept
{
return m_begin;
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr T&
util::view<T>::end (void) noexcept
{
return m_end;
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr const T&
util::view<T>::begin (void) const noexcept
{
return cbegin ();
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr const T&
util::view<T>::end (void) const noexcept
{
return cend ();
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr const T&
util::view<T>::cbegin (void) const noexcept
{
return m_begin;
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr const T&
util::view<T>::cend (void) const noexcept
{
return m_end;
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
constexpr T
util::view<T>::find (const value_type &v) const noexcept
{
for (T i = cbegin (); i != cend (); ++i)
if (*i == v)
return i;
return cend ();
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
constexpr
bool
util::view<T>::empty (void) const noexcept
{
return m_begin == m_end;
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr
size_t
util::view<T>::size (void) const noexcept
{
return m_end - m_begin;
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
constexpr
const typename util::view<T>::value_type&
util::view<T>::operator[] (size_t idx) const noexcept
{
return m_begin[idx];
}
//-----------------------------------------------------------------------------
template <typename T>
constexpr
typename util::view<T>::value_type&
util::view<T>::operator[] (size_t idx) noexcept
{
return m_begin[idx];
}
///////////////////////////////////////////////////////////////////////////////
template <typename T>
bool
util::view<T>::operator== (const view<T> rhs) const noexcept
{
return rhs.m_begin == m_begin &&
rhs.m_end == m_end;
}
//-----------------------------------------------------------------------------
template <typename T>
bool
util::operator!= (const view<T> a, const view<T> b)
{
return !(a == b);
}
///////////////////////////////////////////////////////////////////////////////
template <typename T, size_t N>
auto
util::make_view (const T (&arr)[N])
{
return util::view<const T*> (arr + 0, arr + N);
}
//-----------------------------------------------------------------------------
template <typename T>
auto
util::make_view (T &t)
{
return util::view<decltype(std::begin (t))> { std::begin (t), std::end (t) };
}
//-----------------------------------------------------------------------------
template <typename T>
auto
util::make_view (const T &t)
{
return util::view<decltype(std::cbegin (t))> { std::cbegin (t), std::cend (t) };
}
//-----------------------------------------------------------------------------
template <typename T>
auto
util::make_cview (const T &t)
{
return util::view<decltype(std::cbegin (t))> { std::cbegin (t), std::cend (t) };
}
///////////////////////////////////////////////////////////////////////////////
inline
util::view<const char*>
util::make_view (const char *str)
{
return { str, str + strlen (str) };
}
//-----------------------------------------------------------------------------
inline
util::view<char*>
util::make_view (char *str)
{
return { str, str + strlen (str) };
}
//-----------------------------------------------------------------------------
template <typename CharT, typename TraitsT, typename AllocT>
util::view<const CharT*>
util::make_view (const std::basic_string<CharT,TraitsT,AllocT> &str)
{
return {
std::data (str),
std::data (str) + std::size (str)
};
}
//-----------------------------------------------------------------------------
template <typename CharT, typename TraitsT, typename AllocT>
util::view<CharT*>
util::make_view (std::basic_string<CharT,TraitsT,AllocT> &str)
{
return {
std::data (str),
std::data (str) + std::size (str)
};
}