Skip to content

Commit

Permalink
WIP 3Hren#190: Fixed VS2017 compile issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maturin committed Nov 30, 2018
1 parent 7af8b7c commit 9346ccd
Show file tree
Hide file tree
Showing 52 changed files with 457 additions and 133 deletions.
37 changes: 31 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@ set(LIBRARY_NAME blackhole)
project(${LIBRARY_NAME})

find_package(Boost 1.46 REQUIRED COMPONENTS
system
thread)
system)

include_directories(BEFORE SYSTEM
${PROJECT_SOURCE_DIR}/foreign/libcds
${PROJECT_SOURCE_DIR}/foreign/rapidjson/include)

if (MSVC)
set(BLACKHOLE_SYSLOG_FILES "")
set(BLACKHOLE_SYSLOG_TEST_FILES "")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
# Windows 7, otherwise boost creates some warning, becuase _WIN32_WINNT is unset
add_definitions(/D _WIN32_WINNT=0x0601)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
else (MSVC)
set(BLACKHOLE_SYSLOG_FILES
src/sink/syslog.cpp
src/sink/syslog.hpp
include/blackhole/sink/syslog.hpp)
set(BLACKHOLE_SYSLOG_TEST_FILES
tests/src/unit/sink/syslog.cpp)
endif (MSVC)

include_directories(${PROJECT_SOURCE_DIR}/include)

add_library(${LIBRARY_NAME} SHARED
Expand Down Expand Up @@ -62,9 +78,9 @@ add_library(${LIBRARY_NAME} SHARED
src/sink/null.cpp
src/sink/socket/tcp.cpp
src/sink/socket/udp.cpp
src/sink/syslog.cpp
src/termcolor.cpp
src/wrapper.cpp
${BLACKHOLE_SYSLOG_FILES}
)

# Set the Standard version.
Expand All @@ -86,7 +102,7 @@ endif ()

# Set maximum warnings level depending on compiler.
# TODO: target_maximum_warnings(${LIBRARY_NAME})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
target_compile_options(${LIBRARY_NAME} PRIVATE
-Weverything
-Wno-c++98-compat
Expand All @@ -96,6 +112,9 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
-Wno-weak-vtables
-pedantic
-pedantic-errors)
elseif (MSVC)
#target_compile_options(${LIBRARY_NAME} PRIVATE /W4)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else ()
set_target_properties(${LIBRARY_NAME} PROPERTIES
COMPILE_FLAGS "-Wall"
Expand Down Expand Up @@ -236,15 +255,21 @@ if (ENABLE_TESTING)
tests/src/unit/sink/file/flusher/repeat.cpp
tests/src/unit/sink/file/stream.cpp
tests/src/unit/sink/null
tests/src/unit/sink/syslog
tests/src/unit/sink/tcp
tests/src/unit/sink/udp.cpp
tests/src/unit/stdext/string_view
tests/src/unit/termcolor.cpp
tests/src/unit/time.cpp
tests/wrapper
${BLACKHOLE_SYSLOG_TEST_FILES}
)

if (MSVC)
#include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
endif(MSVC)


add_dependencies(${LIBRARY_NAME}-tests googlemock)

target_link_libraries(${LIBRARY_NAME}-tests
Expand Down Expand Up @@ -290,7 +315,7 @@ if (ENABLE_BENCHMARKING)
endif (ENABLE_BENCHMARKING)

function(enable_all_warnings TARGET)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
target_compile_options(${TARGET} PRIVATE
-Weverything
-Wno-c++98-compat
Expand Down
18 changes: 12 additions & 6 deletions include/blackhole/builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ struct handler_tag;
struct formatter_tag;

template<typename T, typename Parent = void>
class __attribute__((deprecated("`partial_builder` has no future, use `blackhole::builder` instead"))) partial_builder;
[[deprecated("`partial_builder` has no future, use `blackhole::builder` instead")]]
class partial_builder;

template<>
class __attribute__((deprecated("`partial_builder` has no future, use `blackhole::builder` instead"))) partial_builder<root_logger_t> {
[[deprecated("`partial_builder` has no future, use `blackhole::builder` instead")]]
class partial_builder<root_logger_t> {
public:
typedef partial_builder<root_logger_t> this_type;

Expand All @@ -58,7 +60,8 @@ class __attribute__((deprecated("`partial_builder` has no future, use `blackhole
};

template<typename Parent>
class __attribute__((deprecated("`partial_builder` has no future, use `blackhole::builder` instead"))) partial_builder<blackhole::handler::blocking_t, Parent> {
[[deprecated("`partial_builder` has no future, use `blackhole::builder` instead")]]
class partial_builder<blackhole::handler::blocking_t, Parent> {
public:
typedef partial_builder<blackhole::handler::blocking_t, Parent> this_type;

Expand Down Expand Up @@ -90,7 +93,8 @@ class __attribute__((deprecated("`partial_builder` has no future, use `blackhole
};

template<typename Parent>
class __attribute__((deprecated("`partial_builder` has no future, use `blackhole::builder` instead"))) partial_builder<experimental::handler::dev_t, Parent> {
[[deprecated("`partial_builder` has no future, use `blackhole::builder` instead")]]
class partial_builder<experimental::handler::dev_t, Parent> {
public:
typedef partial_builder<experimental::handler::dev_t, Parent> this_type;

Expand All @@ -112,7 +116,8 @@ class __attribute__((deprecated("`partial_builder` has no future, use `blackhole
};

template<typename Parent>
class __attribute__((deprecated("`partial_builder` has no future, use `blackhole::builder` instead"))) partial_builder<formatter::string_t, Parent> {
[[deprecated("`partial_builder` has no future, use `blackhole::builder` instead")]]
class partial_builder<formatter::string_t, Parent> {
public:
typedef Parent parent_type;
typedef formatter::string_t internal_type;
Expand Down Expand Up @@ -140,7 +145,8 @@ class __attribute__((deprecated("`partial_builder` has no future, use `blackhole
};

template<typename Parent>
class __attribute__((deprecated("`partial_builder` has no future, use `blackhole::builder` instead"))) partial_builder<sink::console_t, Parent> {
[[deprecated("`partial_builder` has no future, use `blackhole::builder` instead")]]
class partial_builder<sink::console_t, Parent> {
public:
typedef Parent parent_type;
typedef sink::console_t internal_type;
Expand Down
2 changes: 1 addition & 1 deletion include/blackhole/config/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class node_t;
class factory_t {
public:
/// Destroys the factory with freeing all its associated resources.
virtual ~factory_t() = 0;
virtual ~factory_t();

/// Returns a const lvalue reference to the root configuration.
virtual auto config() const -> const node_t& = 0;
Expand Down
4 changes: 4 additions & 0 deletions include/blackhole/extensions/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
# include <sstream>
#endif

#if _MSC_VER < 1900
#ifdef _SECURE_SCL
# define FMT_SECURE_SCL _SECURE_SCL
#else
Expand Down Expand Up @@ -94,6 +95,9 @@ inline uint32_t clzll(uint64_t x) {
}
}
#endif
#else
# define FMT_SECURE_SCL 0
#endif

#ifdef __GNUC__
# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
Expand Down
3 changes: 2 additions & 1 deletion include/blackhole/formatter/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ class json_t;
template<>
class builder<formatter::json_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> d;
std::unique_ptr<inner_t> d;

public:
builder();
~builder();

/// Configures attribute routing for all not mentioned attributes.
auto route(std::string route) & -> builder&;
Expand Down
3 changes: 2 additions & 1 deletion include/blackhole/formatter/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,11 @@ class string_t;
template<>
class builder<formatter::string_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> p;
std::unique_ptr<inner_t> p;

public:
explicit builder(std::string pattern);
~builder();

auto mapping(formatter::severity_map sevmap) & -> builder&;
auto mapping(formatter::severity_map sevmap) && -> builder&&;
Expand Down
5 changes: 4 additions & 1 deletion include/blackhole/formatter/tskv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "../factory.hpp"

#include <string>

namespace blackhole {
inline namespace v1 {
namespace formatter {
Expand All @@ -13,10 +15,11 @@ class tskv_t;
template<>
class builder<formatter::tskv_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> p;
std::unique_ptr<inner_t> p;

public:
explicit builder();
~builder();

auto create(const std::string& name, const std::string& value) & -> builder&;
auto create(const std::string& name, const std::string& value) && -> builder&&;
Expand Down
3 changes: 2 additions & 1 deletion include/blackhole/handler/blocking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ class blocking_t;
template<>
class builder<handler::blocking_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> d;
std::unique_ptr<inner_t> d;

public:
builder();
~builder();

auto set(std::unique_ptr<formatter_t> formatter) & -> builder&;
auto set(std::unique_ptr<formatter_t> formatter) && -> builder&&;
Expand Down
3 changes: 2 additions & 1 deletion include/blackhole/handler/dev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class dev_t;
template<>
class builder<experimental::handler::dev_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> d;
std::unique_ptr<inner_t> d;

public:
builder();
~builder();

auto build() && -> std::unique_ptr<handler_t>;
};
Expand Down
5 changes: 5 additions & 0 deletions include/blackhole/record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ class record_t {

auto pid() const noexcept -> std::uint64_t;
auto lwp() const noexcept -> std::uint64_t;

#ifdef _MSC_VER
auto tid() const noexcept -> std::thread::id;

This comment has been minimized.

Copy link
@Maturin

Maturin Dec 1, 2018

Author Owner

@3Hren Was there a particular reason, why you used the native handle instead of the std::thread::id?

#else
auto tid() const noexcept -> std::thread::native_handle_type;
#endif

auto formatted() const noexcept -> const string_view&;
auto attributes() const noexcept -> const attribute_pack&;
Expand Down
6 changes: 5 additions & 1 deletion include/blackhole/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ inline namespace v1 {

class builder_t {
const registry_t& registry;
std::unique_ptr<config::factory_t, deleter_t> factory;
std::unique_ptr<config::factory_t> factory;

public:
builder_t(const registry_t& registry, std::unique_ptr<config::factory_t> factory);

builder_t(builder_t&& );

~builder_t();

auto configurator() noexcept -> config::factory_t&;

auto build(const std::string& name) -> root_logger_t;
Expand Down
5 changes: 3 additions & 2 deletions include/blackhole/root.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ class builder<root_logger_t> {
typedef root_logger_t result_type;

private:
class inner_t;
std::unique_ptr<inner_t, deleter_t> d;
class inner_t;
std::unique_ptr<inner_t> d;

public:
builder();
~builder();

auto add(std::unique_ptr<handler_t> handler) & -> builder&;
auto add(std::unique_ptr<handler_t> handler) && -> builder&&;
Expand Down
4 changes: 3 additions & 1 deletion include/blackhole/sink/asynchronous.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class asynchronous_t;
template<>
class builder<sink::asynchronous_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> d;
std::unique_ptr<inner_t> d;

public:
/// Constructs a sink builder from some other sink.
Expand All @@ -44,6 +44,8 @@ class builder<sink::asynchronous_t> {
///
/// \param wrapped The target sink (usually the blocking one) that is need to make asynchronous.
explicit builder(std::unique_ptr<sink_t> wrapped);

~builder();

/// Sets the queue size factor.
auto factor(std::size_t value) & -> builder&;
Expand Down
17 changes: 11 additions & 6 deletions include/blackhole/sink/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,27 @@ class console_t;
template<>
class builder<sink::console_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> d;
std::unique_ptr<inner_t> d;

public:
/// Constructs a defaultly configured console sink builder.
/// Constructs a default configured console sink builder.
///
/// By default the generated sink will write all incoming events to the standard output with no
/// coloring.
builder();

~builder();

// MSVC: stdout and stderr are already defined in corecrt_wstdio.h

/// Sets the destination stream to the standard output pipe.
auto stdout() & -> builder&;
auto stdout() && -> builder&&;

auto std_out() &->builder&;
auto std_out() && ->builder&&;

/// Sets the destination stream to the standard error pipe.
auto stderr() & -> builder&;
auto stderr() && -> builder&&;
auto std_err() &->builder&;
auto std_err() && ->builder&&;

/// Sets terminal color mapping for a given severity making all log events to be colored with
/// specified color.
Expand Down
5 changes: 4 additions & 1 deletion include/blackhole/sink/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <memory>
#include <ratio>
#include <string>

#include "blackhole/factory.hpp"

Expand Down Expand Up @@ -84,14 +85,16 @@ typedef binary_unit<std::uintmax_t, std::ratio<1024 * 1024 * 1024>> gibibytes_t;
template<>
class builder<sink::file_t> {
class inner_t;
std::unique_ptr<inner_t, deleter_t> p;
std::unique_ptr<inner_t> p;

public:
/// Constructs a file sink builder with the given file path pattern.
///
/// By default this builder will produce file sinks with automatic flush policy, which can be
/// changed using threshold methods.
explicit builder(const std::string& path);

~builder();

/// Specifies flush threshold in terms of bytes written.
///
Expand Down
4 changes: 0 additions & 4 deletions src/config/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "blackhole/forward.hpp"

#include "../util/deleter.hpp"

namespace blackhole {
inline namespace v1 {
namespace config {
Expand All @@ -12,7 +10,5 @@ factory_t::~factory_t() = default;

} // namespace config

template auto deleter_t::operator()(config::factory_t* value) -> void;

} // namespace v1
} // namespace blackhole
2 changes: 1 addition & 1 deletion src/config/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class json_t : public node_t {
return cursor + "/" + key;
}

__attribute((noreturn)) auto type_mismatch(const std::string& expected) const -> void {
[[noreturn]] auto type_mismatch(const std::string& expected) const -> void {
throw config::type_mismatch(cursor.empty() ? "/" : cursor, expected, type());
}

Expand Down
Loading

0 comments on commit 9346ccd

Please sign in to comment.