@@ -1,8 +1,8 @@ | |||||
#pragma once | #pragma once | ||||
#include <memory> | #include <memory> | ||||
#include "MetaProgramming.h" | |||||
#include "exception.h" | |||||
#include <cpputils/misc/exception.h> | |||||
#include <cpputils/mp/core.h> | |||||
namespace utl | namespace utl | ||||
{ | { | ||||
@@ -12,26 +12,26 @@ namespace utl | |||||
{ | { | ||||
private: | private: | ||||
template<class Tt_base, class Tt_derived> | template<class Tt_base, class Tt_derived> | ||||
using cop_is_base_of = std::is_base_of<utl::mp_clean_type<Tt_base>, utl::mp_clean_type<Tt_derived>>; | |||||
using cop_is_base_of = std::is_base_of<mp::clean_type<Tt_base>, mp::clean_type<Tt_derived>>; | |||||
template<class X, class Enable = void> | template<class X, class Enable = void> | ||||
struct __impl_cop_is_value : | struct __impl_cop_is_value : | ||||
public utl::mp_true { }; | |||||
public mp::c_true { }; | |||||
template<class X> | template<class X> | ||||
struct __impl_cop_is_value<X*, void> : | struct __impl_cop_is_value<X*, void> : | ||||
public utl::mp_false { }; | |||||
public mp::c_false { }; | |||||
template<template<class> class F, class X> | template<template<class> class F, class X> | ||||
struct __impl_cop_is_value<F<X>, utl::mp_enable_if<cop_is_base_of<smart_ptr<X>, F<X>>>> : | |||||
public utl::mp_false { }; | |||||
struct __impl_cop_is_value<F<X>, mp::enable_if<cop_is_base_of<smart_ptr<X>, F<X>>>> : | |||||
public mp::c_false { }; | |||||
template<class X> | template<class X> | ||||
struct __impl_cop_is_value<std::reference_wrapper<X>, void> : | struct __impl_cop_is_value<std::reference_wrapper<X>, void> : | ||||
public utl::mp_false { }; | |||||
public mp::c_false { }; | |||||
template<class X> | template<class X> | ||||
using cop_is_value = __impl_cop_is_value<utl::mp_clean_type<X>>; | |||||
using cop_is_value = __impl_cop_is_value<mp::clean_type<X>>; | |||||
struct op_deleter_noop | struct op_deleter_noop | ||||
{ inline void operator()(T*) { } }; | { inline void operator()(T*) { } }; | ||||
@@ -78,35 +78,35 @@ namespace utl | |||||
return *this; | return *this; | ||||
} | } | ||||
template<class X = T, utl::mp_enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
inline smart_ptr& reset(X& x) | inline smart_ptr& reset(X& x) | ||||
{ | { | ||||
_value.reset(new X(x)); | _value.reset(new X(x)); | ||||
return *this; | return *this; | ||||
} | } | ||||
template<class X = T, utl::mp_enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
inline smart_ptr& reset(X&& x) | inline smart_ptr& reset(X&& x) | ||||
{ | { | ||||
_value.reset(new X(std::move(x))); | _value.reset(new X(std::move(x))); | ||||
return *this; | return *this; | ||||
} | } | ||||
template<class X = T, utl::mp_enable_if_c<cop_is_base_of<T, X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<cop_is_base_of<T, X>::value, int> = 0> | |||||
inline smart_ptr& reset(const smart_ptr<X>& other) | inline smart_ptr& reset(const smart_ptr<X>& other) | ||||
{ | { | ||||
_value = other._value; | _value = other._value; | ||||
return *this; | return *this; | ||||
} | } | ||||
template<class X = T, utl::mp_enable_if_c<cop_is_base_of<T, X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<cop_is_base_of<T, X>::value, int> = 0> | |||||
inline smart_ptr& reset(smart_ptr<X>&& other) | inline smart_ptr& reset(smart_ptr<X>&& other) | ||||
{ | { | ||||
_value = std::move(other._value); | _value = std::move(other._value); | ||||
return *this; | return *this; | ||||
} | } | ||||
template<class X = T, utl::mp_enable_if_c<cop_is_base_of<T, X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<cop_is_base_of<T, X>::value, int> = 0> | |||||
inline smart_ptr& reset(std::reference_wrapper<X>&& ref) | inline smart_ptr& reset(std::reference_wrapper<X>&& ref) | ||||
{ | { | ||||
_value.reset(&ref.get(), op_deleter_noop()); | _value.reset(&ref.get(), op_deleter_noop()); | ||||
@@ -127,32 +127,32 @@ namespace utl | |||||
smart_ptr() | smart_ptr() | ||||
{ } | { } | ||||
template<class X = T, utl::mp_enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
smart_ptr(X& x) : | smart_ptr(X& x) : | ||||
_value(new X(x)) | _value(new X(x)) | ||||
{ } | { } | ||||
template<class X = T, utl::mp_enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<cop_is_value<X>::value, int> = 0> | |||||
smart_ptr(X&& x) : | smart_ptr(X&& x) : | ||||
_value(new X(std::move(x))) | _value(new X(std::move(x))) | ||||
{ } | { } | ||||
template<class X = T, utl::mp_enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
smart_ptr(X* x) : | smart_ptr(X* x) : | ||||
_value(x) | _value(x) | ||||
{ } | { } | ||||
template<class X = T, utl::mp_enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
smart_ptr(const smart_ptr<X>& other) : | smart_ptr(const smart_ptr<X>& other) : | ||||
_value(other._value) | _value(other._value) | ||||
{ } | { } | ||||
template<class X = T, utl::mp_enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
smart_ptr(smart_ptr<X>&& other) : | smart_ptr(smart_ptr<X>&& other) : | ||||
_value(std::move(other._value)) | _value(std::move(other._value)) | ||||
{ } | { } | ||||
template<class X = T, utl::mp_enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
template<class X = T, mp::enable_if_c<std::is_base_of<T, X>::value, int> = 0> | |||||
smart_ptr(std::reference_wrapper<X>&& ref) : | smart_ptr(std::reference_wrapper<X>&& ref) : | ||||
_value(&ref.get(), op_deleter_noop()) | _value(&ref.get(), op_deleter_noop()) | ||||
{ } | { } | ||||
@@ -8,7 +8,7 @@ | |||||
// (LogLevel: debug|info|warn|error), [T_sender], [Message, [Arguments]] | // (LogLevel: debug|info|warn|error), [T_sender], [Message, [Arguments]] | ||||
#define log_global_message(level, ...) \ | #define log_global_message(level, ...) \ | ||||
if (::utl::logging::is_enabled(::utl::logging::log_level::level)) \ | if (::utl::logging::is_enabled(::utl::logging::log_level::level)) \ | ||||
::utl::logging::make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::log_message() | |||||
::utl::logging::make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::message() | |||||
namespace utl { | namespace utl { | ||||
namespace logging { | namespace logging { | ||||
@@ -2,14 +2,14 @@ | |||||
#include <cpputils/misc/exception.h> | #include <cpputils/misc/exception.h> | ||||
#include <cpputils/logging/types.h> | #include <cpputils/logging/types.h> | ||||
#include <cpputils/logging/log_message.h> | |||||
#include <cpputils/logging/message.h> | |||||
// () mandatory | // () mandatory | ||||
// [] optional | // [] optional | ||||
// (logger), (LogLevel: debug|info|warn|error), [Sender], [Message, [Arguments]] | // (logger), (LogLevel: debug|info|warn|error), [Sender], [Message, [Arguments]] | ||||
#define log_message(logger, level, ...) \ | #define log_message(logger, level, ...) \ | ||||
if (logger.is_enabled(::utl::logging::log_level::level)) \ | if (logger.is_enabled(::utl::logging::log_level::level)) \ | ||||
logger.make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::log_message() | |||||
logger.make_log_helper(::utl::logging::log_level::level, __FILE__, __LINE__, ## __VA_ARGS__ ) = ::utl::logging::message() | |||||
namespace utl { | namespace utl { | ||||
namespace logging { | namespace logging { | ||||
@@ -24,7 +24,7 @@ namespace logging { | |||||
data_ptr_s _data; | data_ptr_s _data; | ||||
public: | public: | ||||
inline void operator=(const log_message& msg) | |||||
inline void operator=(const message& msg) | |||||
{ _data->message += msg.str(); } | { _data->message += msg.str(); } | ||||
inline helper(logger& logger, data_ptr_s data) : | inline helper(logger& logger, data_ptr_s data) : | ||||
@@ -3,7 +3,7 @@ | |||||
namespace utl { | namespace utl { | ||||
namespace logging { | namespace logging { | ||||
struct log_message | |||||
struct message | |||||
{ | { | ||||
private: | private: | ||||
std::ostringstream _msg; | std::ostringstream _msg; | ||||
@@ -13,29 +13,29 @@ namespace logging { | |||||
{ return _msg.str(); } | { return _msg.str(); } | ||||
template <typename T> | template <typename T> | ||||
inline log_message& operator <<(const T& value) | |||||
inline message& operator <<(const T& value) | |||||
{ | { | ||||
_msg << value; | _msg << value; | ||||
return *this; | return *this; | ||||
} | } | ||||
inline log_message& operator <<(std::ostream& (*callback)(std::ostream&)) | |||||
inline message& operator <<(std::ostream& (*callback)(std::ostream&)) | |||||
{ | { | ||||
callback(_msg); | callback(_msg); | ||||
return *this; | return *this; | ||||
} | } | ||||
log_message() : | |||||
message() : | |||||
_msg() | _msg() | ||||
{ } | { } | ||||
log_message(const std::string& msg) : | |||||
message(const std::string& msg) : | |||||
_msg(msg) | _msg(msg) | ||||
{ } | { } | ||||
private: | private: | ||||
log_message(log_message&&) = delete; | |||||
log_message(const log_message&) = delete; | |||||
message(message&&) = delete; | |||||
message(const message&) = delete; | |||||
}; | }; | ||||
} | } |
@@ -150,22 +150,21 @@ namespace linq { | |||||
struct lookup_range : public tag_range | struct lookup_range : public tag_range | ||||
{ | { | ||||
using value_type = lookup::value_type; | using value_type = lookup::value_type; | ||||
enum class State | |||||
using state_type = enum class state | |||||
{ | { | ||||
Initialize, | |||||
Iterating, | |||||
Finished, | |||||
initialize, | |||||
iterating, | |||||
finished, | |||||
}; | }; | ||||
values_type& values; | |||||
size_t current; | |||||
size_t end; | |||||
State state; | |||||
values_type& values; | |||||
size_t current; | |||||
size_t end; | |||||
state_type state; | |||||
inline value_type& front() | inline value_type& front() | ||||
{ | { | ||||
assert(state == State::Iterating); | |||||
assert(state == state_type::iterating); | |||||
assert(current < end); | assert(current < end); | ||||
return *values[current]; | return *values[current]; | ||||
} | } | ||||
@@ -174,15 +173,15 @@ namespace linq { | |||||
{ | { | ||||
switch (state) | switch (state) | ||||
{ | { | ||||
case State::Iterating: | |||||
case state_type::iterating: | |||||
{ | { | ||||
++current; | ++current; | ||||
} | } | ||||
case State::Initialize: | |||||
case state_type::initialize: | |||||
{ | { | ||||
auto hasElements = (current < end); | auto hasElements = (current < end); | ||||
state = (hasElements ? State::Iterating : State::Finished); | |||||
state = (hasElements ? state_type::iterating : state_type::finished); | |||||
return hasElements; | return hasElements; | ||||
} | } | ||||
@@ -197,7 +196,7 @@ namespace linq { | |||||
values (v), | values (v), | ||||
current (c), | current (c), | ||||
end (e), | end (e), | ||||
state (State::Initialize) | |||||
state (state_type::initialize) | |||||
{ LINQ_CTOR(); } | { LINQ_CTOR(); } | ||||
inline lookup_range(const lookup_range& other) : | inline lookup_range(const lookup_range& other) : | ||||
@@ -889,23 +888,22 @@ namespace linq { | |||||
using value_type = T; | using value_type = T; | ||||
using range_type = TRange; | using range_type = TRange; | ||||
using this_type = default_if_empty_range<range_type, value_type>; | using this_type = default_if_empty_range<range_type, value_type>; | ||||
enum class State | |||||
using state_type = enum class state | |||||
{ | { | ||||
Init, | |||||
Iterate, | |||||
Empty, | |||||
Finish | |||||
init, | |||||
iterate, | |||||
empty, | |||||
finish, | |||||
}; | }; | ||||
range_type range; | range_type range; | ||||
value_type value; | value_type value; | ||||
State state; | |||||
state_type state; | |||||
inline value_type& front() | inline value_type& front() | ||||
{ | { | ||||
assert(state != State::Init && state != State::Finish); | |||||
return (state == State::Empty | |||||
assert(state != state_type::init && state != state_type::finish); | |||||
return (state == state_type::empty | |||||
? value | ? value | ||||
: range.front()); | : range.front()); | ||||
} | } | ||||
@@ -914,23 +912,23 @@ namespace linq { | |||||
{ | { | ||||
switch(state) | switch(state) | ||||
{ | { | ||||
case State::Init: | |||||
case state_type::init: | |||||
state = range.next() | state = range.next() | ||||
? State::Iterate | |||||
: State::Empty; | |||||
? state_type::iterate | |||||
: state_type::empty; | |||||
return true; | return true; | ||||
case State::Iterate: | |||||
case state_type::iterate: | |||||
if (!range.next()) | if (!range.next()) | ||||
{ | { | ||||
state = State::Finish; | |||||
state = state_type::finish; | |||||
return false; | return false; | ||||
} | } | ||||
return true; | return true; | ||||
case State::Empty: | |||||
state = State::Finish; | |||||
case state_type::empty: | |||||
state = state_type::finish; | |||||
/* fall through */ | /* fall through */ | ||||
default: | default: | ||||
@@ -942,7 +940,7 @@ namespace linq { | |||||
inline default_if_empty_range(R&& r, X&& t) : | inline default_if_empty_range(R&& r, X&& t) : | ||||
range(std::forward<R>(r)), | range(std::forward<R>(r)), | ||||
value(t), | value(t), | ||||
state(State::Init) | |||||
state(state_type::init) | |||||
{ LINQ_CTOR(); } | { LINQ_CTOR(); } | ||||
inline default_if_empty_range(const default_if_empty_range& other) : | inline default_if_empty_range(const default_if_empty_range& other) : | ||||
@@ -6,5 +6,12 @@ namespace mp { | |||||
template<typename...> | template<typename...> | ||||
using void_t = void; | using void_t = void; | ||||
template<typename...> | |||||
struct list { }; | |||||
template<typename... T> | |||||
struct inherit : T... | |||||
{ }; | |||||
} | } | ||||
} | } |
@@ -1,15 +1,15 @@ | |||||
#include <gtest/gtest.h> | #include <gtest/gtest.h> | ||||
#include <cpputils/container/nullable.h> | #include <cpputils/container/nullable.h> | ||||
struct TestData | |||||
struct test_data | |||||
{ | { | ||||
static int ctorCount; | static int ctorCount; | ||||
static int dtorCount; | static int dtorCount; | ||||
TestData() | |||||
test_data() | |||||
{ ++ctorCount; } | { ++ctorCount; } | ||||
~TestData() | |||||
~test_data() | |||||
{ ++dtorCount; } | { ++dtorCount; } | ||||
}; | }; | ||||
@@ -31,11 +31,11 @@ struct NonCopyableTestData | |||||
using NullableInt = utl::nullable<int>; | using NullableInt = utl::nullable<int>; | ||||
using NullableIntRef = utl::nullable<int&>; | using NullableIntRef = utl::nullable<int&>; | ||||
using NullableString = utl::nullable<std::string>; | using NullableString = utl::nullable<std::string>; | ||||
using NullableTestData = utl::nullable<TestData>; | |||||
using NullableTestData = utl::nullable<test_data>; | |||||
using NullableNonCopyableTestData = utl::nullable<NonCopyableTestData>; | using NullableNonCopyableTestData = utl::nullable<NonCopyableTestData>; | ||||
int TestData::ctorCount = 0; | |||||
int TestData::dtorCount = 0; | |||||
int test_data::ctorCount = 0; | |||||
int test_data::dtorCount = 0; | |||||
using namespace ::utl; | using namespace ::utl; | ||||
using namespace ::testing; | using namespace ::testing; | ||||
@@ -111,12 +111,12 @@ TEST(NullableTest, hasValue_operatorBool) | |||||
TEST(NullableTest, reset) | TEST(NullableTest, reset) | ||||
{ | { | ||||
NullableTestData n(TestData{}); | |||||
NullableTestData n(test_data{}); | |||||
EXPECT_TRUE (n.has_value()); | EXPECT_TRUE (n.has_value()); | ||||
int tmp = TestData::dtorCount; | |||||
int tmp = test_data::dtorCount; | |||||
n.reset(); | n.reset(); | ||||
EXPECT_FALSE(n.has_value()); | EXPECT_FALSE(n.has_value()); | ||||
EXPECT_EQ (tmp + 1, TestData::dtorCount); | |||||
EXPECT_EQ (tmp + 1, test_data::dtorCount); | |||||
} | } | ||||
TEST(NullableTest, value_functor) | TEST(NullableTest, value_functor) | ||||
@@ -4,15 +4,15 @@ | |||||
namespace linq_tests | namespace linq_tests | ||||
{ | { | ||||
struct TestData | |||||
struct test_data | |||||
{ | { | ||||
int value; | int value; | ||||
TestData() : | |||||
test_data() : | |||||
value(0) | value(0) | ||||
{ } | { } | ||||
TestData(int v) : | |||||
test_data(int v) : | |||||
value(v) | value(v) | ||||
{ } | { } | ||||
}; | }; | ||||
@@ -187,9 +187,9 @@ TEST(LinqTest, where) | |||||
TEST(LinqTest, select) | TEST(LinqTest, select) | ||||
{ | { | ||||
std::vector<TestData> data({ TestData(1), TestData(2), TestData(3) }); | |||||
std::vector<test_data> data({ test_data(1), test_data(2), test_data(3) }); | |||||
auto range = from_container(data) | auto range = from_container(data) | ||||
>> select([](TestData& td)->int& { | |||||
>> select([](test_data& td)->int& { | |||||
return td.value; | return td.value; | ||||
}); | }); | ||||
ASSERT_TRUE (range.next()); | ASSERT_TRUE (range.next()); | ||||
@@ -256,9 +256,9 @@ TEST(LinqTest, order_by) | |||||
TEST(LinqTest, distinct) | TEST(LinqTest, distinct) | ||||
{ | { | ||||
std::vector<TestData> data({ TestData(1), TestData(2), TestData(3), TestData(1), TestData(2), TestData(4) }); | |||||
std::vector<test_data> data({ test_data(1), test_data(2), test_data(3), test_data(1), test_data(2), test_data(4) }); | |||||
auto range = from_container(data) | auto range = from_container(data) | ||||
>> distinct([](TestData& l, TestData& r){ | |||||
>> distinct([](test_data& l, test_data& r){ | |||||
return l.value < r.value; | return l.value < r.value; | ||||
}); | }); | ||||
ASSERT_TRUE (range.next()); | ASSERT_TRUE (range.next()); | ||||
@@ -866,11 +866,11 @@ TEST(LinqTest, moveable_objects) | |||||
TEST(LinqTest, const_objects) | TEST(LinqTest, const_objects) | ||||
{ | { | ||||
const TestData data[] = { TestData(1) }; | |||||
const test_data data[] = { test_data(1) }; | |||||
{ | { | ||||
auto v = from_array(data) | auto v = from_array(data) | ||||
>> select([](const TestData& d) { | |||||
>> select([](const test_data& d) { | |||||
return d; | return d; | ||||
}) | }) | ||||
>> first(); | >> first(); | ||||
@@ -879,7 +879,7 @@ TEST(LinqTest, const_objects) | |||||
{ | { | ||||
auto v = from_array(data) | auto v = from_array(data) | ||||
>> select([](const TestData& d) { | |||||
>> select([](const test_data& d) { | |||||
return d; | return d; | ||||
}) | }) | ||||
>> first_or_default(); | >> first_or_default(); | ||||
@@ -888,7 +888,7 @@ TEST(LinqTest, const_objects) | |||||
{ | { | ||||
auto v = from_array(data) | auto v = from_array(data) | ||||
>> select([](const TestData& d) { | |||||
>> select([](const test_data& d) { | |||||
return std::move(d); | return std::move(d); | ||||
}) | }) | ||||
>> last(); | >> last(); | ||||
@@ -897,7 +897,7 @@ TEST(LinqTest, const_objects) | |||||
{ | { | ||||
auto v = from_array(data) | auto v = from_array(data) | ||||
>> select([](const TestData& d) { | |||||
>> select([](const test_data& d) { | |||||
return d; | return d; | ||||
}) | }) | ||||
>> last_or_default(); | >> last_or_default(); | ||||
@@ -906,7 +906,7 @@ TEST(LinqTest, const_objects) | |||||
{ | { | ||||
auto v = from_array(data) | auto v = from_array(data) | ||||
>> select([](const TestData& d) { | |||||
>> select([](const test_data& d) { | |||||
return d; | return d; | ||||
}) | }) | ||||
>> single(); | >> single(); | ||||
@@ -915,7 +915,7 @@ TEST(LinqTest, const_objects) | |||||
{ | { | ||||
auto v = from_array(data) | auto v = from_array(data) | ||||
>> select([](const TestData& d) { | |||||
>> select([](const test_data& d) { | |||||
return d; | return d; | ||||
}) | }) | ||||
>> single_or_default(); | >> single_or_default(); | ||||
@@ -924,7 +924,7 @@ TEST(LinqTest, const_objects) | |||||
{ | { | ||||
auto v = from_array(data) | auto v = from_array(data) | ||||
>> select([](const TestData& d) { | |||||
>> select([](const test_data& d) { | |||||
return d; | return d; | ||||
}) | }) | ||||
>> to_list(); | >> to_list(); | ||||