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