Explicit template instantiation for rexy::string and rexy::binary
This commit is contained in:
parent
8ae27c1ba3
commit
c83d2ce686
@ -14,7 +14,7 @@ option(ENABLE_SHARED "Build shared library" ON)
|
||||
option(ENABLE_PROFILING "Enable asan" OFF)
|
||||
mark_as_advanced(ENABLE_PROFILING)
|
||||
|
||||
set(SOURCE_LIST "src/filerd.cpp")
|
||||
set(SOURCE_LIST "src/filerd.cpp" "src/string.cpp" "src/binary.cpp")
|
||||
add_library(ensure OBJECT "src/ensure.cpp")
|
||||
target_compile_options(ensure PRIVATE -Wall -Wextra -pedantic -std=c++17)
|
||||
if(ENABLE_SHARED)
|
||||
@ -29,7 +29,7 @@ if(ENABLE_PROFILING)
|
||||
target_link_options(rexy PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls)
|
||||
endif()
|
||||
|
||||
set(LIBREXY_PUBLIC_HEADERS "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/binary.hpp" "include/rexy/expression.hpp" "include/rexy/binary.tpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/filerd.hpp" "include/rexy/string_base.tpp")
|
||||
set(LIBREXY_PUBLIC_HEADERS "include/rexy/traits.hpp" "include/rexy/steal.hpp" "include/rexy/binary.hpp" "include/rexy/expression.hpp" "include/rexy/binary_base.hpp" "include/rexy/binary_base.tpp" "include/rexy/string_base.hpp" "include/rexy/string.hpp" "include/rexy/filerd.hpp" "include/rexy/string_base.tpp")
|
||||
target_compile_options(rexy PRIVATE -Wall -Wextra -pedantic -std=c++17)
|
||||
|
||||
install(TARGETS rexy
|
||||
|
||||
@ -19,193 +19,15 @@
|
||||
#ifndef REXY_BINARY_HPP
|
||||
#define REXY_BINARY_HPP
|
||||
|
||||
#include <cstdlib> //size_t
|
||||
#include <utility> //move
|
||||
#include <cstring> //memcpy
|
||||
#include <type_traits>
|
||||
#include "cx/utility.hpp" //max
|
||||
#include "binary_base.hpp"
|
||||
#include "detail/default_allocator.hpp"
|
||||
#include "steal.hpp"
|
||||
#include "expression.hpp"
|
||||
#include "traits.hpp"
|
||||
#include "detail/string_appender.hpp"
|
||||
|
||||
namespace rexy{
|
||||
|
||||
class binary_base
|
||||
{
|
||||
protected:
|
||||
char* m_data = nullptr;
|
||||
size_t m_size = 0;
|
||||
size_t m_cap = 0;
|
||||
public:
|
||||
protected:
|
||||
constexpr binary_base(void)noexcept = default;
|
||||
constexpr binary_base(size_t len)noexcept;
|
||||
constexpr binary_base(char* data, size_t size)noexcept;
|
||||
constexpr binary_base(char* data, size_t size, size_t cap)noexcept;
|
||||
constexpr binary_base(const binary_base& b)noexcept;
|
||||
~binary_base(void)noexcept = default;
|
||||
using binary = binary_data<detail::default_allocator<>>;
|
||||
|
||||
public:
|
||||
constexpr char* release(void)noexcept;
|
||||
extern template class binary_data<detail::default_allocator<>>;
|
||||
|
||||
constexpr size_t size(void)const;
|
||||
constexpr size_t capacity(void)const;
|
||||
constexpr char* get(void);
|
||||
constexpr const char* get(void)const;
|
||||
constexpr operator bool(void)const;
|
||||
|
||||
constexpr char& operator[](size_t i)noexcept;
|
||||
constexpr const char& operator[](size_t i)const noexcept;
|
||||
|
||||
};
|
||||
template<class Allocator = detail::default_allocator<>>
|
||||
class binary_data : public binary_base
|
||||
{
|
||||
public:
|
||||
using allocator_type = Allocator;
|
||||
public:
|
||||
constexpr binary_data(void)noexcept;
|
||||
constexpr binary_data(rexy::steal<char*> data, size_t size)noexcept;
|
||||
constexpr binary_data(rexy::steal<char*> data, size_t cap, size_t size)noexcept;
|
||||
constexpr binary_data(rexy::steal<char*> data)noexcept;
|
||||
binary_data(const char* data, size_t size)noexcept(noexcept(Allocator::copy(data, size)));
|
||||
binary_data(const char* data)noexcept(noexcept(Allocator::copy(data, 0)));
|
||||
binary_data(const char* data, size_t size, size_t cap)noexcept(noexcept(Allocator::copy(data, size)));
|
||||
explicit binary_data(size_t size)noexcept(noexcept(Allocator::allocate(size)));
|
||||
binary_data(size_t size, size_t cap)noexcept(noexcept(Allocator::allocate(size)));
|
||||
|
||||
binary_data(const binary_data& b)noexcept(noexcept(Allocator::copy(b.m_data, b.m_cap)));
|
||||
constexpr binary_data(binary_data&& b)noexcept;
|
||||
binary_data(const binary_base& b)noexcept(noexcept(Allocator::copy(b.get(),b.size())));
|
||||
|
||||
~binary_data(void)noexcept(noexcept(Allocator::free(m_data)));
|
||||
|
||||
binary_data& operator=(const binary_data& b)noexcept(noexcept(Allocator::copy(b.m_data, b.m_size)));
|
||||
constexpr binary_data& operator=(binary_data&& b)noexcept;
|
||||
binary_data& operator=(const char* c)noexcept(noexcept(Allocator::copy(c, 0)));
|
||||
binary_data& operator=(const binary_base& b)noexcept(noexcept(Allocator::copy(b.get(), b.size())));
|
||||
|
||||
void reset(void)
|
||||
noexcept(noexcept(Allocator::free(m_data)));
|
||||
void reset(char* val, size_t cap, size_t size = 0)
|
||||
noexcept(noexcept(Allocator::free(m_data)));
|
||||
bool resize(size_t newsize)
|
||||
noexcept(noexcept(Allocator::allocate(0)) &&
|
||||
noexcept(Allocator::free(nullptr)));
|
||||
void append(const char* data, size_t len)
|
||||
noexcept(noexcept(Allocator::allocate(0)) &&
|
||||
noexcept(Allocator::free(nullptr)));
|
||||
private:
|
||||
binary_data& _copy_data(const char* data, size_t len)
|
||||
noexcept(noexcept(Allocator::copy(nullptr,0)) &&
|
||||
noexcept(Allocator::free(nullptr)));
|
||||
};
|
||||
using binary = binary_data<>;
|
||||
|
||||
template<class Left, class Right>
|
||||
class binary_cat_expr : public rexy::binary_expression<Left,Right>
|
||||
{
|
||||
public:
|
||||
using binary_expression<Left,Right>::binary_expression;
|
||||
|
||||
constexpr binary_cat_expr(const binary_cat_expr&) = default;
|
||||
constexpr binary_cat_expr(binary_cat_expr&&) = default;
|
||||
|
||||
constexpr size_t size(void)const noexcept;
|
||||
|
||||
template<class Alloc>
|
||||
operator binary_data<Alloc>(void)
|
||||
noexcept(std::is_nothrow_constructible<binary_data<Alloc>, size_t>::value &&
|
||||
std::is_nothrow_invocable<detail::string_appender<binary_data<Alloc>>,decltype(*this)>::value);
|
||||
};
|
||||
|
||||
class static_binary : public binary_base
|
||||
{
|
||||
public:
|
||||
constexpr static_binary(void)noexcept = default;
|
||||
constexpr static_binary(const char* str, size_t len)noexcept;
|
||||
constexpr static_binary(const char* str)noexcept;
|
||||
constexpr static_binary(const static_binary&)noexcept;
|
||||
constexpr static_binary(static_binary&&)noexcept;
|
||||
~static_binary(void)noexcept = default;
|
||||
|
||||
constexpr static_binary& operator=(const char* str)noexcept;
|
||||
constexpr static_binary& operator=(const static_binary& str)noexcept;
|
||||
constexpr static_binary& operator=(static_binary&& str)noexcept;
|
||||
};
|
||||
|
||||
template<class Left, class Right>
|
||||
binary_cat_expr(Left&&, Right&&) -> binary_cat_expr<Left&&,Right&&>;
|
||||
|
||||
template<class T>
|
||||
struct is_binary{
|
||||
static constexpr bool value = rexy::is_type<T,binary_base>::value || rexy::is_template_type<T,binary_cat_expr>::value;
|
||||
};
|
||||
template<class T>
|
||||
struct is_concrete_binary{
|
||||
static constexpr bool value = rexy::is_type<T,binary_base>::value;
|
||||
};
|
||||
namespace detail{
|
||||
template<class... Ts>
|
||||
using enable_if_binary = std::enable_if_t<(is_binary<Ts>::value && ...),int>;
|
||||
template<class... Ts>
|
||||
using enable_if_concrete_binary = std::enable_if_t<(is_concrete_binary<Ts>::value && ...),int>;
|
||||
|
||||
}
|
||||
|
||||
template<class Left, class Right, detail::enable_if_concrete_binary<Left,Right> = 0>
|
||||
bool operator==(Left&& l, Right&& r)noexcept{
|
||||
return l && r && l.size() == r.size() && l.capacity() == r.capacity() && !memcmp(l.get(), r.get(), l.size());
|
||||
}
|
||||
template<class Left, class Right, detail::enable_if_concrete_binary<Left,Right> = 0>
|
||||
bool operator!=(Left&& l, Right&& r)noexcept{
|
||||
return !(std::forward<Left>(l) == std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, class Right, detail::enable_if_binary<Left,Right> = 0>
|
||||
auto operator+(Left&& l, Right&& r)
|
||||
noexcept(noexcept(::new (nullptr) binary_cat_expr(std::forward<Left>(l), std::forward<Right>(r))))
|
||||
{
|
||||
return binary_cat_expr(std::forward<Left>(l), std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, detail::enable_if_binary<Left> = 0>
|
||||
auto operator+(Left&& l, const char* c)
|
||||
noexcept(noexcept(::new (nullptr) binary_cat_expr(std::forward<Left>(l), rexy::static_binary(c))))
|
||||
{
|
||||
return binary_cat_expr(std::forward<Left>(l), rexy::static_binary(c));
|
||||
}
|
||||
template<class Right, detail::enable_if_binary<Right> = 0>
|
||||
auto operator+(const char* c, Right&& r)
|
||||
noexcept(noexcept(::new (nullptr) binary_cat_expr(rexy::static_binary(c), std::forward<Right>(r))))
|
||||
{
|
||||
return binary_cat_expr(rexy::static_binary(c), std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, class Right, detail::enable_if_concrete_binary<Left> = 0, detail::enable_if_binary<Right> = 0>
|
||||
decltype(auto) operator+=(Left& l, Right&& r)
|
||||
noexcept(noexcept(l + std::forward<Right>(r)) && std::is_nothrow_assignable<Left,decltype(l + std::forward<Right>(r))>::value)
|
||||
{
|
||||
return l = (l + std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, detail::enable_if_concrete_binary<Left> = 0>
|
||||
decltype(auto) operator+=(Left& l, const char* c)
|
||||
noexcept(noexcept(l + c) && std::is_nothrow_assignable<Left, decltype(l + c)>::value)
|
||||
{
|
||||
return l = (l + c);
|
||||
}
|
||||
} //namespace rexy
|
||||
|
||||
#include "binary.tpp"
|
||||
|
||||
namespace{
|
||||
constexpr inline rexy::static_binary operator"" _sb(const char* str, size_t len)noexcept{
|
||||
return rexy::static_binary(str, len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef REXY_STRING_BASE_HPP
|
||||
#include "detail/binary_string_conv.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
209
include/rexy/binary_base.hpp
Normal file
209
include/rexy/binary_base.hpp
Normal file
@ -0,0 +1,209 @@
|
||||
/**
|
||||
This file is a part of rexy's general purpose library
|
||||
Copyright (C) 2020 rexy712
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef REXY_BINARY_BASE_HPP
|
||||
#define REXY_BINARY_BASE_HPP
|
||||
|
||||
#include <cstdlib> //size_t
|
||||
#include <utility> //move
|
||||
#include <cstring> //memcpy
|
||||
#include <type_traits>
|
||||
#include "cx/utility.hpp" //max
|
||||
#include "detail/default_allocator.hpp"
|
||||
#include "steal.hpp"
|
||||
#include "expression.hpp"
|
||||
#include "traits.hpp"
|
||||
#include "detail/string_appender.hpp"
|
||||
|
||||
namespace rexy{
|
||||
|
||||
class binary_base
|
||||
{
|
||||
protected:
|
||||
char* m_data = nullptr;
|
||||
size_t m_size = 0;
|
||||
size_t m_cap = 0;
|
||||
public:
|
||||
protected:
|
||||
constexpr binary_base(void)noexcept = default;
|
||||
constexpr binary_base(size_t len)noexcept;
|
||||
constexpr binary_base(char* data, size_t size)noexcept;
|
||||
constexpr binary_base(char* data, size_t size, size_t cap)noexcept;
|
||||
constexpr binary_base(const binary_base& b)noexcept;
|
||||
~binary_base(void)noexcept = default;
|
||||
|
||||
public:
|
||||
constexpr char* release(void)noexcept;
|
||||
|
||||
constexpr size_t size(void)const;
|
||||
constexpr size_t capacity(void)const;
|
||||
constexpr char* get(void);
|
||||
constexpr const char* get(void)const;
|
||||
constexpr operator bool(void)const;
|
||||
|
||||
constexpr char& operator[](size_t i)noexcept;
|
||||
constexpr const char& operator[](size_t i)const noexcept;
|
||||
|
||||
};
|
||||
template<class Allocator = detail::default_allocator<>>
|
||||
class binary_data : public binary_base
|
||||
{
|
||||
public:
|
||||
using allocator_type = Allocator;
|
||||
public:
|
||||
constexpr binary_data(void)noexcept;
|
||||
constexpr binary_data(rexy::steal<char*> data, size_t size)noexcept;
|
||||
constexpr binary_data(rexy::steal<char*> data, size_t cap, size_t size)noexcept;
|
||||
constexpr binary_data(rexy::steal<char*> data)noexcept;
|
||||
binary_data(const char* data, size_t size)noexcept(noexcept(Allocator::copy(data, size)));
|
||||
binary_data(const char* data)noexcept(noexcept(Allocator::copy(data, 0)));
|
||||
binary_data(const char* data, size_t size, size_t cap)noexcept(noexcept(Allocator::copy(data, size)));
|
||||
explicit binary_data(size_t size)noexcept(noexcept(Allocator::allocate(size)));
|
||||
binary_data(size_t size, size_t cap)noexcept(noexcept(Allocator::allocate(size)));
|
||||
|
||||
binary_data(const binary_data& b)noexcept(noexcept(Allocator::copy(b.m_data, b.m_cap)));
|
||||
constexpr binary_data(binary_data&& b)noexcept;
|
||||
binary_data(const binary_base& b)noexcept(noexcept(Allocator::copy(b.get(),b.size())));
|
||||
|
||||
~binary_data(void)noexcept(noexcept(Allocator::free(m_data)));
|
||||
|
||||
binary_data& operator=(const binary_data& b)noexcept(noexcept(Allocator::copy(b.m_data, b.m_size)));
|
||||
constexpr binary_data& operator=(binary_data&& b)noexcept;
|
||||
binary_data& operator=(const char* c)noexcept(noexcept(Allocator::copy(c, 0)));
|
||||
binary_data& operator=(const binary_base& b)noexcept(noexcept(Allocator::copy(b.get(), b.size())));
|
||||
|
||||
void reset(void)
|
||||
noexcept(noexcept(Allocator::free(m_data)));
|
||||
void reset(char* val, size_t cap, size_t size = 0)
|
||||
noexcept(noexcept(Allocator::free(m_data)));
|
||||
bool resize(size_t newsize)
|
||||
noexcept(noexcept(Allocator::allocate(0)) &&
|
||||
noexcept(Allocator::free(nullptr)));
|
||||
void append(const char* data, size_t len)
|
||||
noexcept(noexcept(Allocator::allocate(0)) &&
|
||||
noexcept(Allocator::free(nullptr)));
|
||||
private:
|
||||
binary_data& _copy_data(const char* data, size_t len)
|
||||
noexcept(noexcept(Allocator::copy(nullptr,0)) &&
|
||||
noexcept(Allocator::free(nullptr)));
|
||||
};
|
||||
|
||||
template<class Left, class Right>
|
||||
class binary_cat_expr : public rexy::binary_expression<Left,Right>
|
||||
{
|
||||
public:
|
||||
using binary_expression<Left,Right>::binary_expression;
|
||||
|
||||
constexpr binary_cat_expr(const binary_cat_expr&) = default;
|
||||
constexpr binary_cat_expr(binary_cat_expr&&) = default;
|
||||
|
||||
constexpr size_t size(void)const noexcept;
|
||||
|
||||
template<class Alloc>
|
||||
operator binary_data<Alloc>(void)
|
||||
noexcept(std::is_nothrow_constructible<binary_data<Alloc>, size_t>::value &&
|
||||
std::is_nothrow_invocable<detail::string_appender<binary_data<Alloc>>,decltype(*this)>::value);
|
||||
};
|
||||
|
||||
class static_binary : public binary_base
|
||||
{
|
||||
public:
|
||||
constexpr static_binary(void)noexcept = default;
|
||||
constexpr static_binary(const char* str, size_t len)noexcept;
|
||||
constexpr static_binary(const char* str)noexcept;
|
||||
constexpr static_binary(const static_binary&)noexcept;
|
||||
constexpr static_binary(static_binary&&)noexcept;
|
||||
~static_binary(void)noexcept = default;
|
||||
|
||||
constexpr static_binary& operator=(const char* str)noexcept;
|
||||
constexpr static_binary& operator=(const static_binary& str)noexcept;
|
||||
constexpr static_binary& operator=(static_binary&& str)noexcept;
|
||||
};
|
||||
|
||||
template<class Left, class Right>
|
||||
binary_cat_expr(Left&&, Right&&) -> binary_cat_expr<Left&&,Right&&>;
|
||||
|
||||
template<class T>
|
||||
struct is_binary{
|
||||
static constexpr bool value = rexy::is_type<T,binary_base>::value || rexy::is_template_type<T,binary_cat_expr>::value;
|
||||
};
|
||||
template<class T>
|
||||
struct is_concrete_binary{
|
||||
static constexpr bool value = rexy::is_type<T,binary_base>::value;
|
||||
};
|
||||
namespace detail{
|
||||
template<class... Ts>
|
||||
using enable_if_binary = std::enable_if_t<(is_binary<Ts>::value && ...),int>;
|
||||
template<class... Ts>
|
||||
using enable_if_concrete_binary = std::enable_if_t<(is_concrete_binary<Ts>::value && ...),int>;
|
||||
|
||||
}
|
||||
|
||||
template<class Left, class Right, detail::enable_if_concrete_binary<Left,Right> = 0>
|
||||
bool operator==(Left&& l, Right&& r)noexcept{
|
||||
return l && r && l.size() == r.size() && l.capacity() == r.capacity() && !memcmp(l.get(), r.get(), l.size());
|
||||
}
|
||||
template<class Left, class Right, detail::enable_if_concrete_binary<Left,Right> = 0>
|
||||
bool operator!=(Left&& l, Right&& r)noexcept{
|
||||
return !(std::forward<Left>(l) == std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, class Right, detail::enable_if_binary<Left,Right> = 0>
|
||||
auto operator+(Left&& l, Right&& r)
|
||||
noexcept(noexcept(::new (nullptr) binary_cat_expr(std::forward<Left>(l), std::forward<Right>(r))))
|
||||
{
|
||||
return binary_cat_expr(std::forward<Left>(l), std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, detail::enable_if_binary<Left> = 0>
|
||||
auto operator+(Left&& l, const char* c)
|
||||
noexcept(noexcept(::new (nullptr) binary_cat_expr(std::forward<Left>(l), rexy::static_binary(c))))
|
||||
{
|
||||
return binary_cat_expr(std::forward<Left>(l), rexy::static_binary(c));
|
||||
}
|
||||
template<class Right, detail::enable_if_binary<Right> = 0>
|
||||
auto operator+(const char* c, Right&& r)
|
||||
noexcept(noexcept(::new (nullptr) binary_cat_expr(rexy::static_binary(c), std::forward<Right>(r))))
|
||||
{
|
||||
return binary_cat_expr(rexy::static_binary(c), std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, class Right, detail::enable_if_concrete_binary<Left> = 0, detail::enable_if_binary<Right> = 0>
|
||||
decltype(auto) operator+=(Left& l, Right&& r)
|
||||
noexcept(noexcept(l + std::forward<Right>(r)) && std::is_nothrow_assignable<Left,decltype(l + std::forward<Right>(r))>::value)
|
||||
{
|
||||
return l = (l + std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, detail::enable_if_concrete_binary<Left> = 0>
|
||||
decltype(auto) operator+=(Left& l, const char* c)
|
||||
noexcept(noexcept(l + c) && std::is_nothrow_assignable<Left, decltype(l + c)>::value)
|
||||
{
|
||||
return l = (l + c);
|
||||
}
|
||||
} //namespace rexy
|
||||
|
||||
#include "binary_base.tpp"
|
||||
|
||||
namespace{
|
||||
constexpr inline rexy::static_binary operator"" _sb(const char* str, size_t len)noexcept{
|
||||
return rexy::static_binary(str, len);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef REXY_STRING_HPP
|
||||
#include "detail/binary_string_conv.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -16,8 +16,8 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef REXY_BINARY_TPP
|
||||
#define REXY_BINARY_TPP
|
||||
#ifndef REXY_BINARY_BASE_TPP
|
||||
#define REXY_BINARY_BASE_TPP
|
||||
|
||||
#include <cstdlib> //size_t
|
||||
#include <utility> //move
|
||||
@ -19,24 +19,24 @@
|
||||
#ifndef REXY_BINARY_STRING_CONV_HPP
|
||||
#define REXY_BINARY_STRING_CONV_HPP
|
||||
|
||||
#include "rexy/string.hpp"
|
||||
#include "rexy/binary.hpp"
|
||||
#include "rexy/string_base.hpp"
|
||||
#include "rexy/binary_base.hpp"
|
||||
#include <cstring> //memcpy
|
||||
|
||||
namespace rexy{
|
||||
template<class Al, class Str = rexy::string, detail::enable_if_concrete_string<Str> = 0>
|
||||
auto binary_to_string(const binary_data<Al>& b)
|
||||
template<class Str, detail::enable_if_concrete_string<Str> = 0>
|
||||
auto binary_to_string(const binary_base& b)
|
||||
noexcept(std::is_nothrow_constructible<Str, decltype(b.size())>::value)
|
||||
{
|
||||
Str s(b.size()+1);
|
||||
s.append(b.get(), b.size());
|
||||
return s;
|
||||
}
|
||||
template<class Al, class Str = rexy::string, detail::enable_if_concrete_string<Str> = 0, std::enable_if_t<std::is_same<std::decay_t<Al>,typename Str::allocator_type>::value,int> = 0>
|
||||
template<class Al, class Str, detail::enable_if_concrete_string<Str> = 0, std::enable_if_t<std::is_same<std::decay_t<Al>,typename Str::allocator_type>::value,int> = 0>
|
||||
auto binary_to_string(binary_data<Al>&& b)noexcept{
|
||||
return Str(rexy::steal(b.release()), b.size());
|
||||
}
|
||||
template<class Bin = rexy::binary, detail::enable_if_binary<Bin> = 0>
|
||||
template<class Bin, detail::enable_if_binary<Bin> = 0>
|
||||
auto string_to_binary(const string_base& s)
|
||||
noexcept(std::is_nothrow_constructible<Bin, decltype(s.length())>::value &&
|
||||
noexcept(std::decay_t<Bin>::allocator_type::allocate(0)))
|
||||
@ -45,34 +45,11 @@ namespace rexy{
|
||||
b.append(s.get(), s.length()+1);
|
||||
return b;
|
||||
}
|
||||
template<class Al, class Bin = rexy::binary, detail::enable_if_binary<Bin> = 0, std::enable_if_t<std::is_same<std::decay_t<Al>,typename Bin::allocator_type>::value,int> = 0>
|
||||
template<class Al, class Bin, detail::enable_if_binary<Bin> = 0, std::enable_if_t<std::is_same<std::decay_t<Al>,typename Bin::allocator_type>::value,int> = 0>
|
||||
auto string_to_binary(string_intermediary<Al>&& s)noexcept{
|
||||
return Bin(rexy::steal(s.release()), s.length());
|
||||
}
|
||||
template<class L, class R, detail::enable_if_binary<L> = 0, detail::enable_if_concrete_string<R> = 0>
|
||||
decltype(auto) operator+=(L& l, R&& r)
|
||||
noexcept(noexcept(std::decay_t<L>::allocator_type::allocate(0)) &&
|
||||
noexcept(std::decay_t<L>::allocator_type::free(nullptr)))
|
||||
{
|
||||
l.append(r.get(), r.length()+1);
|
||||
return l;
|
||||
}
|
||||
template<class L, class R, detail::enable_if_binary<L> = 0, detail::enable_if_string<R> = 0, std::enable_if_t<!is_concrete_string<R>::value,int> = 0>
|
||||
decltype(auto) operator+=(L& l, R&& r)
|
||||
noexcept(std::is_nothrow_constructible<rexy::string,R&&>::value &&
|
||||
(noexcept(std::decay_t<L>::allocator_type::allocate(0))))
|
||||
{
|
||||
rexy::string concrete = r;
|
||||
return (l += concrete);
|
||||
}
|
||||
template<class L, class R, detail::enable_if_concrete_string<L> = 0, detail::enable_if_binary<R> = 0>
|
||||
decltype(auto) operator+=(L& l, R&& r)
|
||||
noexcept(noexcept(std::decay_t<L>::allocator_type::allocate(0)) &&
|
||||
noexcept(std::decay_t<L>::allocator_type::free(nullptr)))
|
||||
{
|
||||
l.append(r.get(), r.size());
|
||||
return l;
|
||||
}
|
||||
|
||||
} //namespace rexy
|
||||
|
||||
#endif
|
||||
|
||||
@ -27,11 +27,10 @@ namespace rexy{
|
||||
//new allocated string
|
||||
using string = string_intermediary<detail::default_allocator<>>;
|
||||
|
||||
extern template class string_intermediary<detail::default_allocator<>>;
|
||||
|
||||
}
|
||||
|
||||
#ifdef REXY_BINARY_HPP
|
||||
#include "detail/binary_string_conv.hpp"
|
||||
#endif
|
||||
#ifdef REXY_CX_HASH_HPP
|
||||
#include "cx/basic_string_hash.hpp"
|
||||
#endif
|
||||
|
||||
@ -245,6 +245,9 @@ namespace{
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef REXY_BINARY_BASE_HPP
|
||||
#include "detail/binary_string_conv.hpp"
|
||||
#endif
|
||||
#ifdef REXY_CX_HASH_HPP
|
||||
#include "cx/static_string_hash.hpp"
|
||||
#endif
|
||||
|
||||
26
src/binary.cpp
Normal file
26
src/binary.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
This file is a part of rexy's general purpose library
|
||||
Copyright (C) 2020 rexy712
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rexy/binary.hpp"
|
||||
#include "rexy/detail/default_allocator.hpp"
|
||||
|
||||
namespace rexy{
|
||||
|
||||
template class binary_data<detail::default_allocator<>>;
|
||||
|
||||
}
|
||||
@ -1,7 +1,8 @@
|
||||
//Never actually used in the project. This just ensures that all syntax is correct during builds.
|
||||
|
||||
#include "rexy/binary.hpp"
|
||||
#include "rexy/binary.tpp"
|
||||
#include "rexy/binary_base.hpp"
|
||||
#include "rexy/binary_base.tpp"
|
||||
#include "rexy/expression.hpp"
|
||||
#include "rexy/filerd.hpp"
|
||||
#include "rexy/steal.hpp"
|
||||
|
||||
26
src/string.cpp
Normal file
26
src/string.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
This file is a part of rexy's general purpose library
|
||||
Copyright (C) 2020 rexy712
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rexy/string.hpp"
|
||||
#include "rexy/detail/default_allocator.hpp"
|
||||
|
||||
namespace rexy{
|
||||
|
||||
template class string_intermediary<detail::default_allocator<>>;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user