Browse Source

* moved sources files to subdirectory

* added nlohmann json
* added cancellation token
* added options.cmake
master
bergmann 5 years ago
parent
commit
be8d3b2b72
12 changed files with 14513 additions and 2 deletions
  1. +1
    -0
      cmake/options.cmake
  2. +88
    -0
      include/cpputils/misc/cancellation_token.h
  3. +1
    -0
      include/cpputils/misc/flags.h
  4. +14419
    -0
      include/nlohmann/json.hpp
  5. +2
    -2
      src/CMakeLists.txt
  6. +0
    -0
      src/cpputils/logging/consumer/consumer.cpp
  7. +0
    -0
      src/cpputils/logging/consumer/consumer_stream.cpp
  8. +0
    -0
      src/cpputils/logging/global.cpp
  9. +0
    -0
      src/cpputils/logging/logger.cpp
  10. +0
    -0
      src/cpputils/logging/logger_impl.cpp
  11. +0
    -0
      src/cpputils/logging/matcher.cpp
  12. +2
    -0
      test/CMakeLists.txt

+ 1
- 0
cmake/options.cmake View File

@@ -0,0 +1 @@
Option ( CPPUTILS_BUILD_SHARED "Build cpputils shared library" OFF )

+ 88
- 0
include/cpputils/misc/cancellation_token.h View File

@@ -0,0 +1,88 @@
#pragma once

#include <atomic>
#include <exception>

namespace utl
{

struct cancellation_exception
: public std::exception
{
const char* what() const throw() override
{ return "task was canceled!"; }
};

template<class T>
struct data_cancellation_exception
: public cancellation_exception
{
T data;

data_cancellation_exception(const T& d)
: data(d)
{ }
};

struct cancellation_token
{
private:
std::atomic<bool> _is_cancellation_requested;

public:
virtual void throw_if_cancellation_requested() const = 0;

inline bool is_cancellation_requested() const
{ return _is_cancellation_requested; }

inline void cancel()
{ _is_cancellation_requested = true; }

inline cancellation_token()
: _is_cancellation_requested(false)
{ }

virtual ~cancellation_token()
{ }

private:
cancellation_token(cancellation_token&&) = delete;
cancellation_token(const cancellation_token&) = delete;
};


template<class T>
struct cancellation_source
: public cancellation_token
{
T value;

void throw_if_cancellation_requested() const override
{
if (is_cancellation_requested())
throw data_cancellation_exception<T>(value);
}

void cancel(const T& p_value)
{
cancellation_token::cancel();
value = p_value;
}
};

template<>
struct cancellation_source<void>
: public cancellation_token
{
public:
void throw_if_cancellation_requested() const override
{
if (is_cancellation_requested())
throw cancellation_exception();
}

inline void cancel()
{ cancellation_token::cancel(); }
};

}

+ 1
- 0
include/cpputils/misc/flags.h View File

@@ -1,5 +1,6 @@
#pragma once

#include <stdio.h>
#include <limits>
#include <cassert>
#include <type_traits>


+ 14419
- 0
include/nlohmann/json.hpp
File diff suppressed because it is too large
View File


+ 2
- 2
src/CMakeLists.txt View File

@@ -4,9 +4,9 @@ Include ( cotire OPTIONAL )
Include ( pedantic OPTIONAL )
Include ( strip_symbols OPTIONAL )

Option ( BUILD_SHARED_CPPUTILS "Build cpputils shared library" OFF )
Include ( ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/options.cmake )

Set ( BUILD_SHARED_LIBS ${BUILD_SHARED_CPPUTILS} )
Set ( BUILD_SHARED_LIBS ${CPPUTILS_BUILD_SHARED} )
Set ( CMAKE_CXX_STANDARD 17 )
Set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PEDANTIC_C_FLAGS}" )
Set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PEDANTIC_CXX_FLAGS}" )


src/logging/consumer/consumer.cpp → src/cpputils/logging/consumer/consumer.cpp View File


src/logging/consumer/consumer_stream.cpp → src/cpputils/logging/consumer/consumer_stream.cpp View File


src/logging/global.cpp → src/cpputils/logging/global.cpp View File


src/logging/logger.cpp → src/cpputils/logging/logger.cpp View File


src/logging/logger_impl.cpp → src/cpputils/logging/logger_impl.cpp View File


src/logging/matcher.cpp → src/cpputils/logging/matcher.cpp View File


+ 2
- 0
test/CMakeLists.txt View File

@@ -4,6 +4,8 @@ Include ( cotire OPTIONAL )
Include ( pedantic OPTIONAL )
Include ( cmake_tests OPTIONAL )

Include ( ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/options.cmake )

Set ( CMAKE_CXX_STANDARD 17 )
Set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PEDANTIC_C_FLAGS}" )
Set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PEDANTIC_CXX_FLAGS}" )


Loading…
Cancel
Save