utils to c++17

This commit is contained in:
2019-05-30 14:13:08 +07:00
parent 6703988d21
commit 970f87792d
52 changed files with 226 additions and 257 deletions

View File

@@ -226,7 +226,7 @@ namespace e2d
}
}
namespace e2d { namespace math
namespace e2d::math
{
//
// approximately
@@ -279,4 +279,4 @@ namespace e2d { namespace math
bool contains_nan(const unit<T, Tag>& u) noexcept {
return !math::is_finite(u.value);
}
}}
}

View File

@@ -23,6 +23,7 @@
#include "path.hpp"
#include "shape.hpp"
#include "streams.hpp"
#include "streams.inl"
#include "strfmts.hpp"
#include "strings.hpp"
#include "strings.inl"

View File

@@ -15,6 +15,8 @@ namespace e2d
class buffer_view;
class color;
class color32;
class read_file;
class write_file;
class image;
class mesh;
class shape;

View File

@@ -38,7 +38,7 @@ namespace e2d
const f32* data() const noexcept;
f32& operator[](std::size_t index) noexcept;
f32 operator[](std::size_t index) const noexcept;
f32 operator[](std::size_t index) const noexcept;
color& operator+=(f32 v) noexcept;
color& operator-=(f32 v) noexcept;
@@ -74,7 +74,7 @@ namespace e2d
color operator/(color l, const color& r) noexcept;
}
namespace e2d { namespace math
namespace e2d::math
{
bool approximately(const color& l, const color& r) noexcept;
bool approximately(const color& l, const color& r, f32 precision) noexcept;
@@ -88,10 +88,10 @@ namespace e2d { namespace math
color saturated(const color& c) noexcept;
bool contains_nan(const color& c) noexcept;
}}
}
namespace e2d { namespace colors
namespace e2d::colors
{
u32 pack_color(const color& c) noexcept;
color unpack_color(u32 argb) noexcept;
}}
}

View File

@@ -38,7 +38,7 @@ namespace e2d
const u8* data() const noexcept;
u8& operator[](std::size_t index) noexcept;
u8 operator[](std::size_t index) const noexcept;
u8 operator[](std::size_t index) const noexcept;
color32& operator+=(u8 v) noexcept;
color32& operator-=(u8 v) noexcept;
@@ -74,7 +74,7 @@ namespace e2d
color32 operator/(color32 l, const color32& r) noexcept;
}
namespace e2d { namespace math
namespace e2d::math
{
bool approximately(const color32& l, const color32& r) noexcept;
bool approximately(const color32& l, const color32& r, u8 precision) noexcept;
@@ -85,10 +85,10 @@ namespace e2d { namespace math
color32 minimized(const color32& c, const color32& cmin) noexcept;
color32 maximized(const color32& c, const color32& cmax) noexcept;
color32 clamped(const color32& c, const color32& cmin, const color32& cmax) noexcept;
}}
}
namespace e2d { namespace colors
namespace e2d::colors
{
u32 pack_color32(const color32& c) noexcept;
color32 unpack_color32(u32 argb) noexcept;
}}
}

View File

@@ -4,8 +4,6 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#ifndef E2D_INCLUDE_GUARD_B13171AF5FD34D6284271BD2F4B1F6DD
#define E2D_INCLUDE_GUARD_B13171AF5FD34D6284271BD2F4B1F6DD
#pragma once
#include "_utils.hpp"
@@ -13,17 +11,21 @@
namespace e2d
{
class read_file;
using read_file_uptr = std::unique_ptr<read_file>;
class read_file : public input_stream {
public:
virtual const str& path() const noexcept = 0;
};
using read_file_uptr = std::unique_ptr<read_file>;
class write_file;
using write_file_uptr = std::unique_ptr<write_file>;
class write_file : public output_stream {
public:
virtual const str& path() const noexcept = 0;
};
using write_file_uptr = std::unique_ptr<write_file>;
}
namespace e2d
@@ -32,7 +34,7 @@ namespace e2d
write_file_uptr make_write_file(str_view path, bool append) noexcept;
}
namespace e2d { namespace filesystem
namespace e2d::filesystem
{
bool remove(str_view path);
bool exists(str_view path);
@@ -86,7 +88,6 @@ namespace e2d { namespace filesystem
};
bool extract_predef_path(str& dst, predef_path path_type);
}}
}
#include "filesystem.inl"
#endif

View File

@@ -4,14 +4,12 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#ifndef E2D_INCLUDE_GUARD_ADA6066FA64F4B30BE65FE6AFB3D887F
#define E2D_INCLUDE_GUARD_ADA6066FA64F4B30BE65FE6AFB3D887F
#pragma once
#include "_utils.hpp"
#include "filesystem.hpp"
namespace e2d { namespace filesystem
namespace e2d::filesystem
{
template < typename Iter >
bool extract_directory(str_view path, Iter result_iter) {
@@ -28,6 +26,4 @@ namespace e2d { namespace filesystem
return true;
});
}
}}
#endif
}

View File

@@ -93,7 +93,7 @@ namespace e2d
bool operator!=(const image& l, const image& r) noexcept;
}
namespace e2d { namespace images
namespace e2d::images
{
bool try_load_image(
image& dst,
@@ -112,4 +112,4 @@ namespace e2d { namespace images
const image& src,
image_file_format format,
const output_stream_uptr& dst) noexcept;
}}
}

View File

@@ -97,7 +97,7 @@ namespace e2d
bool operator!=(const mesh& l, const mesh& r) noexcept;
}
namespace e2d { namespace meshes
namespace e2d::meshes
{
bool try_load_mesh(
mesh& dst,
@@ -106,4 +106,4 @@ namespace e2d { namespace meshes
bool try_load_mesh(
mesh& dst,
const input_stream_uptr& src) noexcept;
}}
}

View File

@@ -72,7 +72,7 @@ namespace e2d
std::unique_ptr<BaseT> module<BaseT>::instance_;
}
namespace e2d { namespace modules
namespace e2d::modules
{
template < typename ImplT, typename... Args >
ImplT& initialize(Args&&... args) {
@@ -97,4 +97,4 @@ namespace e2d { namespace modules
using BaseT = typename ImplT::base_type;
return static_cast<ImplT&>(module<BaseT>::instance());
}
}}
}

View File

@@ -8,7 +8,7 @@
#include "_utils.hpp"
namespace e2d { namespace path
namespace e2d::path
{
str combine(str_view lhs, str_view rhs);
@@ -25,4 +25,4 @@ namespace e2d { namespace path
bool is_absolute(str_view path) noexcept;
bool is_relative(str_view path) noexcept;
}}
}

View File

@@ -77,7 +77,7 @@ namespace e2d
bool operator!=(const shape& l, const shape& r) noexcept;
}
namespace e2d { namespace shapes
namespace e2d::shapes
{
bool try_load_shape(
shape& dst,
@@ -86,4 +86,4 @@ namespace e2d { namespace shapes
bool try_load_shape(
shape& dst,
const input_stream_uptr& src) noexcept;
}}
}

View File

@@ -4,8 +4,6 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#ifndef E2D_INCLUDE_GUARD_271E0872955E4A59980866CBF737BDC1
#define E2D_INCLUDE_GUARD_271E0872955E4A59980866CBF737BDC1
#pragma once
#include "_utils.hpp"
@@ -19,6 +17,9 @@ namespace e2d
}
};
class input_stream;
using input_stream_uptr = std::unique_ptr<input_stream>;
class input_stream : private noncopyable {
public:
virtual ~input_stream() noexcept = default;
@@ -27,7 +28,9 @@ namespace e2d
virtual std::size_t tell() const = 0;
virtual std::size_t length() const noexcept = 0;
};
using input_stream_uptr = std::unique_ptr<input_stream>;
class output_stream;
using output_stream_uptr = std::unique_ptr<output_stream>;
class output_stream : private noncopyable {
public:
@@ -37,7 +40,6 @@ namespace e2d
virtual std::size_t tell() const = 0;
virtual void flush() const = 0;
};
using output_stream_uptr = std::unique_ptr<output_stream>;
}
namespace e2d
@@ -99,7 +101,7 @@ namespace e2d
input_stream_uptr make_memory_stream(buffer data) noexcept;
}
namespace e2d { namespace streams
namespace e2d::streams
{
bool try_read_tail(
str& dst,
@@ -116,7 +118,6 @@ namespace e2d { namespace streams
bool try_write_tail(
const buffer& src,
const output_stream_uptr& stream) noexcept;
}}
}
#include "streams.inl"
#endif

View File

@@ -4,8 +4,6 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#ifndef E2D_INCLUDE_GUARD_8B0A2CAB69114FA69A716D2CC7F64DD4
#define E2D_INCLUDE_GUARD_8B0A2CAB69114FA69A716D2CC7F64DD4
#pragma once
#include "_utils.hpp"
@@ -41,5 +39,3 @@ namespace e2d
: *this;
}
}
#endif

View File

@@ -13,14 +13,14 @@
#include "color32.hpp"
#include "strings.hpp"
namespace e2d { namespace strings
namespace e2d::strings
{
//
// vec2
//
template < typename T >
class format_arg<vec2<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<vec2<T>, std::enable_if_t<std::is_integral_v<T>>> {
vec2<T> value_;
u8 width_;
public:
@@ -37,7 +37,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<vec2<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<vec2<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
vec2<T> value_;
u8 width_;
u8 precision_;
@@ -59,7 +59,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<vec3<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<vec3<T>, std::enable_if_t<std::is_integral_v<T>>> {
vec3<T> value_;
u8 width_;
public:
@@ -77,7 +77,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<vec3<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<vec3<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
vec3<T> value_;
u8 width_;
u8 precision_;
@@ -100,7 +100,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<vec4<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<vec4<T>, std::enable_if_t<std::is_integral_v<T>>> {
vec4<T> value_;
u8 width_;
public:
@@ -119,7 +119,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<vec4<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<vec4<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
vec4<T> value_;
u8 width_;
u8 precision_;
@@ -143,7 +143,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<quat<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<quat<T>, std::enable_if_t<std::is_integral_v<T>>> {
quat<T> value_;
u8 width_;
public:
@@ -162,7 +162,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<quat<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<quat<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
quat<T> value_;
u8 width_;
u8 precision_;
@@ -186,7 +186,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<rect<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<rect<T>, std::enable_if_t<std::is_integral_v<T>>> {
rect<T> value_;
u8 width_;
public:
@@ -205,7 +205,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<rect<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<rect<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
rect<T> value_;
u8 width_;
u8 precision_;
@@ -229,7 +229,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<aabb<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<aabb<T>, std::enable_if_t<std::is_integral_v<T>>> {
aabb<T> value_;
u8 width_;
public:
@@ -250,7 +250,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<aabb<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<aabb<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
aabb<T> value_;
u8 width_;
u8 precision_;
@@ -276,7 +276,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<mat2<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<mat2<T>, std::enable_if_t<std::is_integral_v<T>>> {
mat2<T> value_;
u8 width_;
public:
@@ -293,7 +293,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<mat2<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<mat2<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
mat2<T> value_;
u8 width_;
u8 precision_;
@@ -315,7 +315,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<mat3<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<mat3<T>, std::enable_if_t<std::is_integral_v<T>>> {
mat3<T> value_;
u8 width_;
public:
@@ -333,7 +333,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<mat3<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<mat3<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
mat3<T> value_;
u8 width_;
u8 precision_;
@@ -356,7 +356,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<mat4<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<mat4<T>, std::enable_if_t<std::is_integral_v<T>>> {
mat4<T> value_;
u8 width_;
public:
@@ -375,7 +375,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<mat4<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<mat4<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
mat4<T> value_;
u8 width_;
u8 precision_;
@@ -399,7 +399,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<rad<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<rad<T>, std::enable_if_t<std::is_integral_v<T>>> {
rad<T> value_;
u8 width_;
public:
@@ -415,7 +415,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<rad<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<rad<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
rad<T> value_;
u8 width_;
u8 precision_;
@@ -436,7 +436,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<deg<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<deg<T>, std::enable_if_t<std::is_integral_v<T>>> {
deg<T> value_;
u8 width_;
public:
@@ -452,7 +452,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<deg<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<deg<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
deg<T> value_;
u8 width_;
u8 precision_;
@@ -478,7 +478,7 @@ namespace e2d { namespace strings
public:
template < typename U >
explicit format_arg(U&& value)
noexcept(noexcept(std::is_nothrow_constructible<url, U>::value))
noexcept(noexcept(std::is_nothrow_constructible_v<url, U>))
: value_(std::forward<U>(value)) {}
std::ptrdiff_t write(char* dst, size_t size) const {
@@ -499,7 +499,7 @@ namespace e2d { namespace strings
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0)
noexcept(noexcept(std::is_nothrow_constructible<str, U>::value))
noexcept(noexcept(std::is_nothrow_constructible_v<str, U>))
: value_(std::forward<U>(value)), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const {
@@ -527,7 +527,7 @@ namespace e2d { namespace strings
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0)
noexcept(noexcept(std::is_nothrow_constructible<wstr, U>::value))
noexcept(noexcept(std::is_nothrow_constructible_v<wstr, U>))
: value_(std::forward<U>(value)), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const {
@@ -555,7 +555,7 @@ namespace e2d { namespace strings
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0)
noexcept(noexcept(std::is_nothrow_constructible<str16, U>::value))
noexcept(noexcept(std::is_nothrow_constructible_v<str16, U>))
: value_(std::forward<U>(value)), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const {
@@ -583,7 +583,7 @@ namespace e2d { namespace strings
public:
template < typename U >
explicit format_arg(U&& value, u8 width = 0)
noexcept(noexcept(std::is_nothrow_constructible<str32, U>::value))
noexcept(noexcept(std::is_nothrow_constructible_v<str32, U>))
: value_(std::forward<U>(value)), width_(width) {}
std::ptrdiff_t write(char* dst, size_t size) const {
@@ -652,7 +652,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<seconds<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<seconds<T>, std::enable_if_t<std::is_integral_v<T>>> {
seconds<T> value_;
u8 width_;
public:
@@ -668,7 +668,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<seconds<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<seconds<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
seconds<T> value_;
u8 width_;
u8 precision_;
@@ -689,7 +689,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<milliseconds<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<milliseconds<T>, std::enable_if_t<std::is_integral_v<T>>> {
milliseconds<T> value_;
u8 width_;
public:
@@ -705,7 +705,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<milliseconds<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<milliseconds<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
milliseconds<T> value_;
u8 width_;
u8 precision_;
@@ -726,7 +726,7 @@ namespace e2d { namespace strings
//
template < typename T >
class format_arg<microseconds<T>, std::enable_if_t<std::is_integral<T>::value>> {
class format_arg<microseconds<T>, std::enable_if_t<std::is_integral_v<T>>> {
microseconds<T> value_;
u8 width_;
public:
@@ -742,7 +742,7 @@ namespace e2d { namespace strings
};
template < typename T >
class format_arg<microseconds<T>, std::enable_if_t<std::is_floating_point<T>::value>> {
class format_arg<microseconds<T>, std::enable_if_t<std::is_floating_point_v<T>>> {
microseconds<T> value_;
u8 width_;
u8 precision_;
@@ -757,4 +757,4 @@ namespace e2d { namespace strings
make_format_arg(value_.value, width_, precision_)));
}
};
}}
}

View File

@@ -4,8 +4,6 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#ifndef E2D_INCLUDE_GUARD_4540A3A22AD942D8A6B0C77A3346E73A
#define E2D_INCLUDE_GUARD_4540A3A22AD942D8A6B0C77A3346E73A
#pragma once
#include "_utils.hpp"
@@ -15,8 +13,8 @@ namespace e2d
template < typename Char >
class basic_string_hash final {
public:
basic_string_hash() noexcept;
~basic_string_hash() noexcept;
basic_string_hash() noexcept = default;
~basic_string_hash() noexcept = default;
basic_string_hash(basic_string_hash&& other) noexcept;
basic_string_hash& operator=(basic_string_hash&& other) noexcept;
@@ -84,45 +82,44 @@ namespace e2d
wstr_hash make_hash(wstr_view src) noexcept;
str16_hash make_hash(str16_view src) noexcept;
str32_hash make_hash(str32_view src) noexcept;
}
namespace strings
{
class format_error;
class bad_format;
class bad_format_buffer;
class bad_format_argument;
namespace e2d::strings
{
class format_error;
class bad_format;
class bad_format_buffer;
class bad_format_argument;
template < typename T, typename = void >
class format_arg;
template < typename T, typename = void >
class format_arg;
template < typename T, typename... Args >
format_arg<std::decay_t<T>> make_format_arg(T&& v, Args&&... args);
template < typename T, typename... Args >
format_arg<std::decay_t<T>> make_format_arg(T&& v, Args&&... args);
template < typename... Args >
std::size_t format(
char* dst, std::size_t size,
str_view fmt, Args&&... args);
template < typename... Args >
std::size_t format(
char* dst, std::size_t size,
str_view fmt, Args&&... args);
template < typename... Args >
bool format_nothrow(
char* dst, std::size_t dst_size, std::size_t* length,
str_view fmt, Args&&... args) noexcept;
template < typename... Args >
bool format_nothrow(
char* dst, std::size_t dst_size, std::size_t* length,
str_view fmt, Args&&... args) noexcept;
template < typename... Args >
str rformat(
str_view fmt, Args&&... args);
template < typename... Args >
str rformat(
str_view fmt, Args&&... args);
template < typename... Args >
bool rformat_nothrow(
str& dst,
str_view fmt, Args&&... args) noexcept;
template < typename... Args >
bool rformat_nothrow(
str& dst,
str_view fmt, Args&&... args) noexcept;
bool wildcard_match(str_view string, str_view pattern);
bool wildcard_match(str_view string, str_view pattern);
bool starts_with(str_view input, str_view test) noexcept;
bool ends_with(str_view input, str_view test) noexcept;
}
bool starts_with(str_view input, str_view test) noexcept;
bool ends_with(str_view input, str_view test) noexcept;
}
#include "strings.inl"
#endif

View File

@@ -4,8 +4,6 @@
* Copyright (C) 2018-2019, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#ifndef E2D_INCLUDE_GUARD_5BC5A803A3694674845E9953209E8CBE
#define E2D_INCLUDE_GUARD_5BC5A803A3694674845E9953209E8CBE
#pragma once
#include "_utils.hpp"
@@ -13,12 +11,6 @@
namespace e2d
{
template < typename Char >
basic_string_hash<Char>::basic_string_hash() noexcept = default;
template < typename Char >
basic_string_hash<Char>::~basic_string_hash() noexcept = default;
template < typename Char >
basic_string_hash<Char>::basic_string_hash(
basic_string_hash&& other) noexcept
@@ -189,7 +181,7 @@ namespace std
};
}
namespace e2d { namespace strings
namespace e2d::strings
{
//
// exceptions
@@ -268,7 +260,7 @@ namespace e2d { namespace strings
template < typename T >
class format_arg<T, std::enable_if_t<
std::is_integral<T>::value && std::is_signed<T>::value>>
std::is_integral_v<T> && std::is_signed_v<T>>>
{
T value_;
u8 width_;
@@ -292,7 +284,7 @@ namespace e2d { namespace strings
template < typename T >
class format_arg<T, std::enable_if_t<
std::is_integral<T>::value && std::is_unsigned<T>::value>>
std::is_integral_v<T> && std::is_unsigned_v<T>>>
{
T value_;
u8 width_;
@@ -316,7 +308,7 @@ namespace e2d { namespace strings
template < typename T >
class format_arg<T, std::enable_if_t<
std::is_floating_point<T>::value>>
std::is_floating_point_v<T>>>
{
T value_;
u8 width_;
@@ -404,20 +396,28 @@ namespace e2d { namespace strings
namespace impl
{
template < typename T >
struct is_arg_impl : std::false_type {};
template < typename U >
struct is_arg_impl<format_arg<U>> : std::true_type {};
template < typename T >
struct is_arg : is_arg_impl<std::remove_cv_t<T>> {};
struct is_arg_impl
: std::false_type {};
template < typename T >
std::enable_if_t<is_arg<std::decay_t<T>>::value, T>
struct is_arg_impl<format_arg<T>>
: std::true_type {};
template < typename T >
struct is_arg
: is_arg_impl<std::remove_cv_t<T>> {};
template < typename T >
inline constexpr bool is_arg_v = is_arg<T>::value;
template < typename T >
std::enable_if_t<is_arg_v<std::decay_t<T>>, T>
wrap_arg(T&& arg) {
return std::forward<T>(arg);
}
template < typename T >
std::enable_if_t<!is_arg<std::decay_t<T>>::value, format_arg<std::decay_t<T>>>
std::enable_if_t<!is_arg_v<std::decay_t<T>>, format_arg<std::decay_t<T>>>
wrap_arg(T&& value) {
return make_format_arg(std::forward<T>(value));
}
@@ -602,6 +602,4 @@ namespace e2d { namespace strings
return false;
}
}
}}
#endif
}

View File

@@ -86,7 +86,7 @@ namespace e2d
};
}
namespace e2d { namespace time
namespace e2d::time
{
template < typename T >
std::chrono::duration<T, std::ratio<1ll, 1ll>>
@@ -120,9 +120,9 @@ namespace e2d { namespace time
microseconds<T> to_microseconds(const unit<T, Tag>& u) noexcept {
return u.template convert_to<microseconds_tag>();
}
}}
}
namespace e2d { namespace time
namespace e2d::time
{
template < typename T >
const seconds<T>& second() noexcept {
@@ -177,9 +177,9 @@ namespace e2d { namespace time
static microseconds<T> hour_us = to_microseconds(hour<T>());
return hour_us;
}
}}
}
namespace e2d { namespace time
namespace e2d::time
{
template < typename TimeTag, typename T = i64 >
unit<T, TimeTag> now() noexcept {
@@ -196,7 +196,7 @@ namespace e2d { namespace time
}
template < typename T = i64 >
inline unit<T, milliseconds_tag> now_ms() noexcept {
unit<T, milliseconds_tag> now_ms() noexcept {
return now<milliseconds_tag, T>();
}
@@ -204,4 +204,4 @@ namespace e2d { namespace time
unit<T, microseconds_tag> now_us() noexcept {
return now<microseconds_tag, T>();
}
}}
}

View File

@@ -21,19 +21,13 @@ namespace e2d
url& operator=(const url& other);
explicit url(str_view schemepath);
url(str_view scheme, str_view path) noexcept;
template < typename T, typename U >
url(T&& scheme, U&& path) noexcept;
url(str scheme, str path) noexcept;
url& assign(url&& other) noexcept;
url& assign(const url& other);
url& assign(str_view schemepath);
url& assign(str_view scheme, str_view path) noexcept;
template < typename T, typename U >
url& assign(T&& scheme, U&& path) noexcept;
url& assign(str scheme, str path) noexcept;
url& concat(str_view path);
url& append(str_view path);
@@ -53,21 +47,6 @@ namespace e2d
};
}
namespace e2d
{
template < typename T, typename U >
url::url(T&& scheme, U&& path) noexcept {
assign(std::forward<T>(scheme), std::forward<U>(path));
}
template < typename T, typename U >
url& url::assign(T&& scheme, U&& path) noexcept {
scheme_ = std::forward<T>(scheme);
path_ = std::forward<U>(path);
return *this;
}
}
namespace e2d
{
void swap(url& l, url& r) noexcept;

View File

@@ -10,6 +10,6 @@
#include <3rdparty/pugixml/pugixml.hpp>
namespace e2d { namespace xml_utils
namespace e2d::xml_utils
{
}}
}

View File

@@ -238,7 +238,7 @@ namespace e2d
}
}
namespace e2d { namespace math
namespace e2d::math
{
//
// approximately
@@ -312,9 +312,9 @@ namespace e2d { namespace math
|| !math::is_finite(c.b)
|| !math::is_finite(c.a);
}
}}
}
namespace e2d { namespace colors
namespace e2d::colors
{
u32 pack_color(const color& c) noexcept {
return
@@ -331,4 +331,4 @@ namespace e2d { namespace colors
math::numeric_cast<u8>((argb >> 0) & 0xFF) / 255.f,
math::numeric_cast<u8>((argb >> 24) & 0xFF) / 255.f);
}
}}
}

View File

@@ -238,7 +238,7 @@ namespace e2d
}
}
namespace e2d { namespace math
namespace e2d::math
{
//
// approximately
@@ -297,9 +297,9 @@ namespace e2d { namespace math
math::clamp(c.b, cmin.b, cmax.b),
math::clamp(c.a, cmin.a, cmax.a));
}
}}
}
namespace e2d { namespace colors
namespace e2d::colors
{
u32 pack_color32(const color32& c) noexcept {
return
@@ -316,4 +316,4 @@ namespace e2d { namespace colors
math::numeric_cast<u8>((argb >> 0) & 0xFF),
math::numeric_cast<u8>((argb >> 24) & 0xFF));
}
}}
}

View File

@@ -18,7 +18,7 @@ namespace e2d
}
}
namespace e2d { namespace filesystem
namespace e2d::filesystem
{
bool remove(str_view path) {
return remove_file(path)
@@ -118,4 +118,4 @@ namespace e2d { namespace filesystem
bool extract_predef_path(str& dst, predef_path path_type) {
return impl::extract_predef_path(dst, path_type);
}
}}
}

View File

@@ -29,8 +29,8 @@
# error E2D_FILES_MODE not detected
#endif
namespace e2d { namespace impl
namespace e2d::impl
{
read_file_uptr make_read_file(str_view path) noexcept;
write_file_uptr make_write_file(str_view path, bool append) noexcept;
}}
}

View File

@@ -183,7 +183,7 @@ namespace
};
}
namespace e2d { namespace impl
namespace e2d::impl
{
read_file_uptr make_read_file(str_view path) noexcept {
try {
@@ -200,6 +200,6 @@ namespace e2d { namespace impl
return nullptr;
}
}
}}
}
#endif

View File

@@ -222,7 +222,7 @@ namespace
};
}
namespace e2d { namespace impl
namespace e2d::impl
{
read_file_uptr make_read_file(str_view path) noexcept {
try {
@@ -239,6 +239,6 @@ namespace e2d { namespace impl
return nullptr;
}
}
}}
}
#endif

View File

@@ -10,7 +10,7 @@
#include <enduro2d/utils/strings.hpp>
#include <enduro2d/utils/filesystem.hpp>
namespace e2d { namespace filesystem { namespace impl
namespace e2d::filesystem::impl
{
bool remove_file(str_view path);
bool remove_directory(str_view path);
@@ -23,4 +23,4 @@ namespace e2d { namespace filesystem { namespace impl
bool trace_directory(str_view path, const trace_func& func);
bool extract_predef_path(str& dst, predef_path path_type);
}}}
}

View File

@@ -88,7 +88,7 @@ namespace
}
}
namespace e2d { namespace filesystem { namespace impl
namespace e2d::filesystem::impl
{
bool remove_file(str_view path) {
return 0 == ::unlink(make_utf8(path).c_str())
@@ -155,6 +155,6 @@ namespace e2d { namespace filesystem { namespace impl
return false;
}
}
}}}
}
#endif

View File

@@ -78,7 +78,7 @@ namespace
}
}
namespace e2d { namespace filesystem { namespace impl
namespace e2d::filesystem::impl
{
bool remove_file(str_view path) {
return 0 == ::unlink(make_utf8(path).c_str())
@@ -145,6 +145,6 @@ namespace e2d { namespace filesystem { namespace impl
return false;
}
}
}}}
}
#endif

View File

@@ -88,7 +88,7 @@ namespace
}
}
namespace e2d { namespace filesystem { namespace impl
namespace e2d::filesystem::impl
{
bool remove_file(str_view path) {
return 0 == ::unlink(make_utf8(path).c_str())
@@ -155,6 +155,6 @@ namespace e2d { namespace filesystem { namespace impl
return false;
}
}
}}}
}
#endif

View File

@@ -92,7 +92,7 @@ namespace
}
}
namespace e2d { namespace filesystem { namespace impl
namespace e2d::filesystem::impl
{
bool remove_file(str_view path) {
const wstr wide_path = make_wide(path);
@@ -169,6 +169,6 @@ namespace e2d { namespace filesystem { namespace impl
return false;
}
}
}}}
}
#endif

View File

@@ -207,7 +207,7 @@ namespace e2d
}
}
namespace e2d { namespace images
namespace e2d::images
{
bool try_load_image(
image& dst,
@@ -258,4 +258,4 @@ namespace e2d { namespace images
return try_save_image(src, format, file_data)
&& streams::try_write_tail(file_data, dst);
}
}}
}

View File

@@ -9,7 +9,7 @@
#include <enduro2d/utils/image.hpp>
#include <enduro2d/utils/buffer.hpp>
namespace e2d { namespace images { namespace impl
namespace e2d::images::impl
{
bool try_load_image_dds(image& dst, const buffer& src) noexcept;
bool try_load_image_pvr(image& dst, const buffer& src) noexcept;
@@ -20,4 +20,4 @@ namespace e2d { namespace images { namespace impl
bool try_save_image_png(const image& src, buffer& dst) noexcept;
bool try_save_image_pvr(const image& src, buffer& dst) noexcept;
bool try_save_image_tga(const image& src, buffer& dst) noexcept;
}}}
}

View File

@@ -6,11 +6,11 @@
#include "image_impl.hpp"
namespace e2d { namespace images { namespace impl
namespace e2d::images::impl
{
bool try_load_image_dds(image& dst, const buffer& src) noexcept {
//TODO(BlackMat): implme
E2D_UNUSED(dst, src);
return false;
}
}}}
}

View File

@@ -6,11 +6,11 @@
#include "image_impl.hpp"
namespace e2d { namespace images { namespace impl
namespace e2d::images::impl
{
bool try_load_image_pvr(image& dst, const buffer& src) noexcept {
//TODO(BlackMat): implme
E2D_UNUSED(dst, src);
return false;
}
}}}
}

View File

@@ -16,11 +16,11 @@
#define STBI_ONLY_TGA
#define STBI_ONLY_JPEG
#define STBI_FREE(ptr) std::free(ptr)
#define STBI_MALLOC(size) std::malloc(size)
#define STBI_FREE(ptr) std::free(ptr)
#define STBI_MALLOC(size) std::malloc(size)
#define STBI_REALLOC(ptr,nsize) std::realloc(ptr, nsize)
#define STBI_ASSERT(expr) E2D_ASSERT(expr)
#define STBI_ASSERT(expr) E2D_ASSERT(expr)
#define STB_IMAGE_IMPLEMENTATION
#include <3rdparty/stb/stb_image.h>
@@ -77,7 +77,7 @@ namespace
}
}
namespace e2d { namespace images { namespace impl
namespace e2d::images::impl
{
bool try_load_image_stb(image& dst, const buffer& src) noexcept {
v2u img_size;
@@ -86,4 +86,4 @@ namespace e2d { namespace images { namespace impl
return img_ptr
&& image_from_stb_description(dst, img_ptr, img_size, img_channels);
}
}}}
}

View File

@@ -27,7 +27,7 @@ namespace
}
}
namespace e2d { namespace images { namespace impl
namespace e2d::images::impl
{
bool try_save_image_dds(const image& src, buffer& dst) noexcept {
E2D_UNUSED(src, dst);
@@ -37,4 +37,4 @@ namespace e2d { namespace images { namespace impl
}
return false;
}
}}}
}

View File

@@ -33,7 +33,7 @@ namespace
}
}
namespace e2d { namespace images { namespace impl
namespace e2d::images::impl
{
bool try_save_image_pvr(const image& src, buffer& dst) noexcept {
E2D_UNUSED(src, dst);
@@ -43,4 +43,4 @@ namespace e2d { namespace images { namespace impl
}
return false;
}
}}}
}

View File

@@ -8,11 +8,11 @@
#define STBI_WRITE_NO_STDIO
#define STBIW_FREE(ptr) std::free(ptr)
#define STBIW_MALLOC(size) std::malloc(size)
#define STBIW_FREE(ptr) std::free(ptr)
#define STBIW_MALLOC(size) std::malloc(size)
#define STBIW_REALLOC(ptr,nsize) std::realloc(ptr, nsize)
#define STBIW_ASSERT(expr) E2D_ASSERT(expr)
#define STBIW_ASSERT(expr) E2D_ASSERT(expr)
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include <3rdparty/stb/stb_image_write.h>
@@ -41,7 +41,7 @@ namespace
}
}
namespace e2d { namespace images { namespace impl
namespace e2d::images::impl
{
bool try_save_image_jpg(const image& src, buffer& dst) noexcept {
int img_w = math::numeric_cast<int>(src.size().x);
@@ -96,4 +96,4 @@ namespace e2d { namespace images { namespace impl
}
return false;
}
}}}
}

View File

@@ -638,7 +638,7 @@ namespace
}
}
namespace e2d { namespace json_utils
namespace e2d::json_utils
{
void add_common_schema_definitions(rapidjson::Document& schema) {
schema.AddMember(
@@ -648,9 +648,9 @@ namespace e2d { namespace json_utils
schema.GetAllocator()).Move(),
schema.GetAllocator());
}
}}
}
namespace e2d { namespace json_utils
namespace e2d::json_utils
{
bool try_parse_value(const rapidjson::Value& root, v2i& v) noexcept {
v2i tv;
@@ -868,10 +868,10 @@ namespace e2d { namespace json_utils
}
try {
s = make_utf8(root.GetString());
return true;
} catch (...) {
return false;
}
return true;
}
bool try_parse_value(const rapidjson::Value& root, wstr& s) noexcept {
@@ -880,10 +880,10 @@ namespace e2d { namespace json_utils
}
try {
s = make_wide(root.GetString());
return true;
} catch (...) {
return false;
}
return true;
}
bool try_parse_value(const rapidjson::Value& root, str16& s) noexcept {
@@ -892,10 +892,10 @@ namespace e2d { namespace json_utils
}
try {
s = make_utf16(root.GetString());
return true;
} catch (...) {
return false;
}
return true;
}
bool try_parse_value(const rapidjson::Value& root, str32& s) noexcept {
@@ -904,10 +904,10 @@ namespace e2d { namespace json_utils
}
try {
s = make_utf32(root.GetString());
return true;
} catch (...) {
return false;
}
return true;
}
bool try_parse_value(const rapidjson::Value& root, str_hash& s) noexcept {
@@ -916,9 +916,9 @@ namespace e2d { namespace json_utils
}
try {
s = make_hash(root.GetString());
return true;
} catch (...) {
return false;
}
return true;
}
}}
}

View File

@@ -295,7 +295,7 @@ namespace e2d
}
}
namespace e2d { namespace meshes
namespace e2d::meshes
{
bool try_load_mesh(
mesh& dst,
@@ -312,4 +312,4 @@ namespace e2d { namespace meshes
return streams::try_read_tail(file_data, src)
&& try_load_mesh(dst, file_data);
}
}}
}

View File

@@ -9,7 +9,7 @@
#include <enduro2d/utils/mesh.hpp>
#include <enduro2d/utils/buffer.hpp>
namespace e2d { namespace meshes { namespace impl
namespace e2d::meshes::impl
{
bool try_load_mesh_e2d(mesh& dst, const buffer& src) noexcept;
}}}
}

View File

@@ -112,7 +112,7 @@ namespace
}
}
namespace e2d { namespace meshes { namespace impl
namespace e2d::meshes::impl
{
bool try_load_mesh_e2d(mesh& dst, const buffer& src) noexcept {
try {
@@ -121,8 +121,7 @@ namespace e2d { namespace meshes { namespace impl
&& check_signature(stream)
&& load_mesh(dst, stream);
} catch (...) {
// nothing
return false;
}
return false;
}
}}}
}

View File

@@ -37,7 +37,7 @@ namespace
}
}
namespace e2d { namespace path
namespace e2d::path
{
str combine(str_view lhs, str_view rhs) {
if ( lhs.empty() || is_absolute(rhs) ) {
@@ -132,4 +132,4 @@ namespace e2d { namespace path
bool is_relative(str_view path) noexcept {
return !is_absolute(path);
}
}}
}

View File

@@ -220,7 +220,7 @@ namespace e2d
}
}
namespace e2d { namespace shapes
namespace e2d::shapes
{
bool try_load_shape(
shape& dst,
@@ -237,4 +237,4 @@ namespace e2d { namespace shapes
return streams::try_read_tail(file_data, src)
&& try_load_shape(dst, file_data);
}
}}
}

View File

@@ -9,7 +9,7 @@
#include <enduro2d/utils/shape.hpp>
#include <enduro2d/utils/buffer.hpp>
namespace e2d { namespace shapes { namespace impl
namespace e2d::shapes::impl
{
bool try_load_shape_e2d(shape& dst, const buffer& src) noexcept;
}}}
}

View File

@@ -94,7 +94,7 @@ namespace
}
}
namespace e2d { namespace shapes { namespace impl
namespace e2d::shapes::impl
{
bool try_load_shape_e2d(shape& dst, const buffer& src) noexcept {
try {
@@ -103,8 +103,7 @@ namespace e2d { namespace shapes { namespace impl
&& check_signature(stream)
&& load_shape(dst, stream);
} catch (...) {
// nothing
return false;
}
return false;
}
}}}
}

View File

@@ -211,7 +211,7 @@ namespace e2d
}
}
namespace e2d { namespace streams
namespace e2d::streams
{
bool try_read_tail(str& dst, const input_stream_uptr& stream) noexcept {
return stream
@@ -244,4 +244,4 @@ namespace e2d { namespace streams
.success()
: false;
}
}}
}

View File

@@ -260,7 +260,7 @@ namespace e2d
}
}
namespace e2d { namespace strings
namespace e2d::strings
{
namespace impl
{
@@ -337,4 +337,4 @@ namespace e2d { namespace strings
return input.length() >= test.length()
&& 0 == input.compare(input.length() - test.length(), test.length(), test);
}
}}
}

View File

@@ -72,8 +72,8 @@ namespace e2d
assign(schemepath);
}
url::url(str_view scheme, str_view path) noexcept {
assign(scheme, path);
url::url(str scheme, str path) noexcept {
assign(std::move(scheme), std::move(path));
}
url& url::assign(url&& other) noexcept {
@@ -96,9 +96,9 @@ namespace e2d
return assign(std::move(nscheme), std::move(npath));
}
url& url::assign(str_view scheme, str_view path) noexcept {
scheme_ = scheme;
path_ = path;
url& url::assign(str scheme, str path) noexcept {
scheme_ = std::move(scheme);
path_ = std::move(path);
return *this;
}

View File

@@ -11,6 +11,6 @@ namespace
using namespace e2d;
}
namespace e2d { namespace xml_utils
namespace e2d::xml_utils
{
}}
}

View File

@@ -8,8 +8,8 @@
using namespace e2d;
TEST_CASE("vfs"){
const str_view file_path = "vfs_file_name";
const str_view nofile_path = "vfs_file_name2";
const str file_path = "vfs_file_name";
const str nofile_path = "vfs_file_name2";
{
REQUIRE(filesystem::remove_file(nofile_path));
REQUIRE(filesystem::create_file(file_path));