Browse Source

Member prefix ('m_') removed from all member variables (fixes #136).

main
offa 6 years ago
parent
commit
b354a77b6c
7 changed files with 79 additions and 79 deletions
  1. +11
    -11
      include/detail/scope_guard_base.h
  2. +13
    -13
      include/detail/wrapper.h
  3. +2
    -2
      include/scope_fail.h
  4. +2
    -2
      include/scope_success.h
  5. +29
    -29
      include/unique_resource.h
  6. +20
    -20
      test/CallMocks.h
  7. +2
    -2
      test/UniqueResourceTest.cpp

+ 11
- 11
include/detail/scope_guard_base.h View File

@@ -70,8 +70,8 @@ namespace sr::detail
>
explicit scope_guard_base(EFP&& exitFunction) noexcept(std::is_nothrow_constructible_v<EF, EFP>
|| std::is_nothrow_constructible_v<EF, EFP&>)
: m_exitfunction(std::forward<EFP>(exitFunction)),
m_execute_on_destruction(true)
: exitfunction(std::forward<EFP>(exitFunction)),
execute_on_destruction(true)
{
}

@@ -79,8 +79,8 @@ namespace sr::detail
std::enable_if_t<std::is_constructible_v<EF, EFP>, int> = 0,
std::enable_if_t<std::is_lvalue_reference_v<EFP>, int> = 0
>
explicit scope_guard_base(EFP&& exitFunction) try : m_exitfunction(exitFunction),
m_execute_on_destruction(true)
explicit scope_guard_base(EFP&& exitFunction) try : exitfunction(exitFunction),
execute_on_destruction(true)
{
}
catch( ... )
@@ -95,8 +95,8 @@ namespace sr::detail
scope_guard_base(scope_guard_base&& other) noexcept(std::is_nothrow_move_constructible_v<EF>
|| std::is_nothrow_copy_constructible_v<EF>)
: Strategy(other),
m_exitfunction(forward_if_nothrow_move_constructible(other.m_exitfunction)),
m_execute_on_destruction(other.m_execute_on_destruction)
exitfunction(forward_if_nothrow_move_constructible(other.exitfunction)),
execute_on_destruction(other.execute_on_destruction)
{
other.release();
}
@@ -106,16 +106,16 @@ namespace sr::detail

~scope_guard_base() noexcept(is_noexcept_dtor_v<EF, Strategy>)
{
if( (m_execute_on_destruction == true) && (this->should_execute() == true) )
if( (execute_on_destruction == true) && (this->should_execute() == true) )
{
m_exitfunction();
exitfunction();
}
}


void release() noexcept
{
m_execute_on_destruction = false;
execute_on_destruction = false;
}


@@ -125,8 +125,8 @@ namespace sr::detail

private:

EF m_exitfunction;
bool m_execute_on_destruction;
EF exitfunction;
bool execute_on_destruction;
};

}

+ 13
- 13
include/detail/wrapper.h View File

@@ -34,7 +34,7 @@ namespace sr::detail
public:

template<class TT, class G, std::enable_if_t<std::is_constructible_v<T, TT>, int> = 0>
Wrapper(TT&& value, G&& g) noexcept(std::is_nothrow_constructible_v<T, TT>) : m_value(std::forward<TT>(value))
Wrapper(TT&& v, G&& g) noexcept(std::is_nothrow_constructible_v<T, TT>) : value(std::forward<TT>(v))
{
g.release();
}
@@ -42,27 +42,27 @@ namespace sr::detail

T& get() noexcept
{
return m_value;
return value;
}

const T& get() const noexcept
{
return m_value;
return value;
}

void reset(Wrapper<T>&& other) noexcept
{
m_value = std::move(other.m_value);
value = std::move(other.value);
}

void reset(T&& newValue) noexcept(std::is_nothrow_assignable_v<T, decltype(std::move_if_noexcept(newValue))>)
{
m_value = std::forward<T>(newValue);
value = std::forward<T>(newValue);
}

void reset(const T& newValue) noexcept(std::is_nothrow_assignable_v<T, const T&>)
{
m_value = newValue;
value = newValue;
}


@@ -71,7 +71,7 @@ namespace sr::detail

private:

T m_value;
T value;
};


@@ -81,7 +81,7 @@ namespace sr::detail
public:

template<class TT, class G, std::enable_if_t<std::is_convertible_v<TT, T&>, int> = 0>
Wrapper(TT&& value, G&& g) noexcept(std::is_nothrow_constructible_v<TT, T&>) : m_value(static_cast<T&>(value))
Wrapper(TT&& v, G&& g) noexcept(std::is_nothrow_constructible_v<TT, T&>) : value(static_cast<T&>(v))
{
g.release();
}
@@ -89,22 +89,22 @@ namespace sr::detail

T& get() noexcept
{
return m_value.get();
return value.get();
}

const T& get() const noexcept
{
return m_value.get();
return value.get();
}

void reset(Wrapper<T>&& other) noexcept
{
m_value = std::move(other.m_value);
value = std::move(other.value);
}

void reset(T& newValue) noexcept
{
m_value = std::ref(newValue);
value = std::ref(newValue);
}


@@ -113,7 +113,7 @@ namespace sr::detail

private:

type m_value;
type value;
};

}

+ 2
- 2
include/scope_fail.h View File

@@ -34,11 +34,11 @@ namespace sr
{
bool should_execute() const noexcept
{
return std::uncaught_exceptions() > m_uncaught_on_creation;
return std::uncaught_exceptions() > uncaught_on_creation;
}


int m_uncaught_on_creation = std::uncaught_exceptions();
int uncaught_on_creation = std::uncaught_exceptions();
};

}

+ 2
- 2
include/scope_success.h View File

@@ -34,11 +34,11 @@ namespace sr
{
bool should_execute() const noexcept
{
return std::uncaught_exceptions() <= m_uncaught_on_creation;
return std::uncaught_exceptions() <= uncaught_on_creation;
}


int m_uncaught_on_creation = std::uncaught_exceptions();
int uncaught_on_creation = std::uncaught_exceptions();
};



+ 29
- 29
include/unique_resource.h View File

@@ -53,19 +53,19 @@ namespace sr
>
explicit unique_resource(RR&& r, DD&& d) noexcept((std::is_nothrow_constructible_v<R, RR> || std::is_nothrow_constructible_v<R, RR&>)
&& (std::is_nothrow_constructible_v<D, DD> || std::is_nothrow_constructible_v<D, DD&>))
: m_resource(detail::forward_if_nothrow_constructible<R, RR>(std::forward<RR>(r)), scope_exit{[&r, &d] { d(r); }}),
m_deleter(detail::forward_if_nothrow_constructible<D, DD>(std::forward<DD>(d)), scope_exit{[this, &d] { d(get()); }}),
m_execute_on_destruction(true)
: resource(detail::forward_if_nothrow_constructible<R, RR>(std::forward<RR>(r)), scope_exit{[&r, &d] { d(r); }}),
deleter(detail::forward_if_nothrow_constructible<D, DD>(std::forward<DD>(d)), scope_exit{[this, &d] { d(get()); }}),
execute_on_destruction(true)
{
}

unique_resource(unique_resource&& other) noexcept(std::is_nothrow_move_constructible_v<R>
&& std::is_nothrow_move_constructible_v<D>)
: m_resource(std::move_if_noexcept(other.m_resource.get()), scope_exit{[] { }}),
m_deleter(std::move_if_noexcept(other.m_deleter.get()), scope_exit{[&other] {
other.get_deleter()(other.m_resource.get());
: resource(std::move_if_noexcept(other.resource.get()), scope_exit{[] { }}),
deleter(std::move_if_noexcept(other.deleter.get()), scope_exit{[&other] {
other.get_deleter()(other.resource.get());
other.release(); }}),
m_execute_on_destruction(std::exchange(other.m_execute_on_destruction, false))
execute_on_destruction(std::exchange(other.execute_on_destruction, false))
{
}

@@ -79,10 +79,10 @@ namespace sr

void reset() noexcept
{
if( m_execute_on_destruction == true )
if( execute_on_destruction == true )
{
m_execute_on_destruction = false;
get_deleter()(m_resource.get());
execute_on_destruction = false;
get_deleter()(resource.get());
}
}

@@ -96,31 +96,31 @@ namespace sr

if constexpr( std::is_nothrow_assignable_v<R1&, RR> == true )
{
m_resource.reset(std::forward<RR>(r));
resource.reset(std::forward<RR>(r));
}
else
{
m_resource.reset(std::as_const(r));
resource.reset(std::as_const(r));
}

m_execute_on_destruction = true;
execute_on_destruction = true;
se.release();
}

void release() noexcept
{
m_execute_on_destruction = false;
execute_on_destruction = false;
}

const R& get() const noexcept
{
return m_resource.get();
return resource.get();
}

template<class RR = R, std::enable_if_t<std::is_pointer_v<RR>, int> = 0>
RR operator->() const noexcept
{
return m_resource.get();
return resource.get();
}

template<class RR = R,
@@ -133,7 +133,7 @@ namespace sr

const D& get_deleter() const noexcept
{
return m_deleter.get();
return deleter.get();
}


@@ -154,30 +154,30 @@ namespace sr
{
if constexpr( std::is_nothrow_move_assignable_v<DD> == true )
{
m_resource.reset(std::move(other.m_resource));
m_deleter.reset(std::move(other.m_deleter));
resource.reset(std::move(other.resource));
deleter.reset(std::move(other.deleter));
}
else
{
m_deleter.reset(other.m_deleter);
m_resource.reset(std::move(other.m_resource));
deleter.reset(other.deleter);
resource.reset(std::move(other.resource));
}
}
else
{
if constexpr( std::is_nothrow_move_assignable_v<DD> == true )
{
m_resource.reset(other.m_resource);
m_deleter.reset(std::move(other.m_deleter));
resource.reset(other.resource);
deleter.reset(std::move(other.deleter));
}
else
{
m_resource.reset(other.m_resource);
m_deleter.reset(other.m_deleter);
resource.reset(other.resource);
deleter.reset(other.deleter);
}
}

m_execute_on_destruction = std::exchange(other.m_execute_on_destruction, false);
execute_on_destruction = std::exchange(other.execute_on_destruction, false);
}
return *this;
}
@@ -187,9 +187,9 @@ namespace sr

private:

detail::Wrapper<R> m_resource;
detail::Wrapper<D> m_deleter;
bool m_execute_on_destruction;
detail::Wrapper<R> resource;
detail::Wrapper<D> deleter;
bool execute_on_destruction;
};



+ 20
- 20
test/CallMocks.h View File

@@ -65,22 +65,22 @@ namespace mock

struct NotNothrowMoveMock
{
explicit NotNothrowMoveMock(CallMock* m) : m_mock(m)
explicit NotNothrowMoveMock(CallMock* m) : mock(m)
{
}

NotNothrowMoveMock(const NotNothrowMoveMock& other) : m_mock(other.m_mock)
NotNothrowMoveMock(const NotNothrowMoveMock& other) : mock(other.mock)
{
}

NotNothrowMoveMock(NotNothrowMoveMock&& other) noexcept(false) : m_mock(other.m_mock)
NotNothrowMoveMock(NotNothrowMoveMock&& other) noexcept(false) : mock(other.mock)
{
}


void operator()() const
{
m_mock->deleter();
mock->deleter();
}

NotNothrowMoveMock& operator=(const NotNothrowMoveMock&)
@@ -94,21 +94,21 @@ namespace mock
}


CallMock* m_mock;
CallMock* mock;
};


struct ConditialThrowOnCopyMock
{
explicit ConditialThrowOnCopyMock(Handle h, bool shouldThrow) : m_handle(h),
m_shouldThrow(shouldThrow)
explicit ConditialThrowOnCopyMock(Handle h, bool throwOnCopyMock) : handle(h),
shouldThrow(throwOnCopyMock)
{
}

ConditialThrowOnCopyMock(const ConditialThrowOnCopyMock& other) : m_handle(other.m_handle),
m_shouldThrow(other.m_shouldThrow)
ConditialThrowOnCopyMock(const ConditialThrowOnCopyMock& other) : handle(other.handle),
shouldThrow(other.shouldThrow)
{
if( m_shouldThrow == true )
if( shouldThrow == true )
{
throw std::exception{};
}
@@ -120,10 +120,10 @@ namespace mock
{
if( &other != this )
{
m_handle = other.m_handle;
m_shouldThrow = other.m_shouldThrow;
handle = other.handle;
shouldThrow = other.shouldThrow;

if( m_shouldThrow == true )
if( shouldThrow == true )
{
throw std::exception{};
}
@@ -135,31 +135,31 @@ namespace mock
ConditialThrowOnCopyMock& operator=(ConditialThrowOnCopyMock&&) = default;


Handle m_handle;
bool m_shouldThrow;
Handle handle;
bool shouldThrow;
};


struct NotNothrowAssignable
{
explicit NotNothrowAssignable(int value) : m_value(value) { }
explicit NotNothrowAssignable(int v) : value(v) { }
NotNothrowAssignable(const NotNothrowAssignable&) = default;

NotNothrowAssignable& operator=(const NotNothrowAssignable& other)
{
if( this != &other )
{
assignNotNoexcept(other.m_value);
assignNotNoexcept(other.value);
}
return *this;
}

void assignNotNoexcept(int value) noexcept(false)
void assignNotNoexcept(int v) noexcept(false)
{
m_value = value;
value = v;
}

int m_value;
int value;
};

struct CopyMock

+ 2
- 2
test/UniqueResourceTest.cpp View File

@@ -129,7 +129,7 @@ TEST_CASE("reset sets new lvalue and calls deleter on previous", "[UniqueResourc
{
REQUIRE_CALL(m, deleter(3));
REQUIRE_CALL(m, deleter(7));
auto d = [](const auto& v) { deleter(v.m_value); };
auto d = [](const auto& v) { deleter(v.value); };
auto guard = sr::unique_resource{NotNothrowAssignable{3}, d};
const NotNothrowAssignable h{7};
guard.reset(h);
@@ -139,7 +139,7 @@ TEST_CASE("reset handles exception on assignment", "[UniqueResource]")
{
REQUIRE_CALL(m, deleter(3));
REQUIRE_CALL(m, deleter(7));
auto d = [](const auto& v) { deleter(v.m_handle); };
auto d = [](const auto& v) { deleter(v.handle); };
auto guard = sr::unique_resource{ConditialThrowOnCopyMock{3, false}, d};
guard.reset(ConditialThrowOnCopyMock{7, true});
}

Loading…
Cancel
Save