Browse Source

Project initialized.

main
offa 7 years ago
parent
commit
c0a475b10c
8 changed files with 11826 additions and 0 deletions
  1. +1
    -0
      .gitignore
  2. +30
    -0
      CMakeLists.txt
  3. +21
    -0
      README.md
  4. +44
    -0
      include/scope_guard.h
  5. +21
    -0
      test/CMakeLists.txt
  6. +17
    -0
      test/ScopeGuardTest.cpp
  7. +3
    -0
      test/TestMain.cpp
  8. +11689
    -0
      test/catch/catch.hpp

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
build/*

+ 30
- 0
CMakeLists.txt View File

@@ -0,0 +1,30 @@
cmake_minimum_required(VERSION 3.2)

project(scoped-ressource VERSION 0.0.1)
message(STATUS "~~~ ${PROJECT_NAME} v${PROJECT_VERSION} ~~~")

option(UNITTEST "Build Unit Tests" ON)


add_compile_options(-Wall
-Wextra
-pedantic
-Werror
-Wshadow
-Wold-style-cast
)


set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


include_directories("include")


if( UNITTEST )
enable_testing()
add_subdirectory("test")
endif()


+ 21
- 0
README.md View File

@@ -0,0 +1,21 @@
# Scope Guard


## License

**GNU General Public License (GPL)**

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.



+ 44
- 0
include/scope_guard.h View File

@@ -0,0 +1,44 @@

#pragma once

#include <utility>

namespace guards
{

template<class Deleter>
class scope_guard_t
{
public:

explicit scope_guard_t(Deleter&& deleter) noexcept : m_deleter(std::move(deleter))
{
}

scope_guard_t(scope_guard_t&&)= default;
scope_guard_t(const scope_guard_t&) = delete;

~scope_guard_t()
{
m_deleter();
}


scope_guard_t& operator=(const scope_guard_t&) = delete;
scope_guard_t& operator=(scope_guard_t&&) = delete;


private:

Deleter m_deleter;
};


template<class Deleter>
scope_guard_t<Deleter> scope_guard(Deleter&& deleter) noexcept
{
return scope_guard_t<Deleter>(std::move(deleter));
}

}


+ 21
- 0
test/CMakeLists.txt View File

@@ -0,0 +1,21 @@

add_library(testmain TestMain.cpp)
target_include_directories(testmain SYSTEM PUBLIC "catch/")

function(add_test_suite name)
add_executable(${name} ${name}.cpp)
target_link_libraries(${name} testmain)
add_test(NAME ${name} COMMAND ${name})
endfunction()

add_test_suite(ScopeGuardTest)




add_custom_target(unittest ScopeGuardTest
COMMENT "Running unittests\n\n"
VERBATIM
)



+ 17
- 0
test/ScopeGuardTest.cpp View File

@@ -0,0 +1,17 @@

#include "scope_guard.h"
#include <catch.hpp>


TEST_CASE("deleter called on destruction", "[ScopeGuard]")
{
bool executed = false;

{
auto guard = scope_guard([&executed] { executed = true; });
static_cast<void>(guard);
}

REQUIRE(executed == true);
}


+ 3
- 0
test/TestMain.cpp View File

@@ -0,0 +1,3 @@

#define CATCH_CONFIG_MAIN
#include <catch.hpp>

+ 11689
- 0
test/catch/catch.hpp
File diff suppressed because it is too large
View File


Loading…
Cancel
Save