Skip to content

Commit

Permalink
Merge pull request #264 from ursfassler/more-std-c++
Browse files Browse the repository at this point in the history
Using C++ standard library where possible instead of boost
  • Loading branch information
mattwynne authored Nov 29, 2023
2 parents c7ad59e + d4b943f commit 57faadb
Show file tree
Hide file tree
Showing 35 changed files with 227 additions and 299 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ BreakBeforeBinaryOperators: All
BreakBeforeBraces: Attach
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ForEachMacros: [ BOOST_FOREACH ]
IncludeCategories:
# The autodetect header should always be included last
- Regex: '^<cucumber-cpp/autodetect\.hpp>$'
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/run-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ jobs:
g++ \
gcovr \
git \
libboost-date-time-dev \
libboost-filesystem-dev \
libboost-program-options-dev \
libboost-regex-dev \
libboost-system-dev \
libboost-test-dev \
libboost-thread-dev \
make \
ninja-build \
qtbase5-dev \
Expand Down
30 changes: 4 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ set(GMOCK_SRC_DIR "" CACHE STRING "Google Mock framework sources path (otherwise
set(GMOCK_VER "1.11.0" CACHE STRING "Google Mock framework version to be used")

if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
elseif(CMAKE_CXX_STANDARD LESS 14)
message(FATAL_ERROR "C++14 (above) is required")
elseif(CMAKE_CXX_STANDARD LESS 17)
message(FATAL_ERROR "C++17 (above) is required")
endif()

if(CUKE_CODE_COVERAGE)
Expand Down Expand Up @@ -122,7 +122,7 @@ else()
endif()

set(Boost_USE_STATIC_RUNTIME OFF)
set(CUKE_CORE_BOOST_LIBS thread system regex date_time program_options filesystem)
set(CUKE_CORE_BOOST_LIBS system regex program_options)
if(CUKE_ENABLE_BOOST_TEST)
# "An external test runner utility is required to link with dynamic library" (Boost User's Guide)
set(Boost_USE_STATIC_LIBS OFF)
Expand Down Expand Up @@ -151,14 +151,6 @@ if(Boost_INCLUDE_DIRS AND NOT TARGET Boost::boost)
set_target_properties(Boost::boost PROPERTIES
"INTERFACE_INCLUDE_DIRECTORIES" "${Boost_INCLUDE_DIRS}")
endif()
if(Boost_THREAD_LIBRARY AND NOT TARGET Boost::thread)
find_package(Threads REQUIRED)
add_library(Boost::thread ${LIBRARY_TYPE} IMPORTED)
set_target_properties(Boost::thread PROPERTIES
"IMPORTED_LOCATION" "${Boost_THREAD_LIBRARY}"
"INTERFACE_LINK_LIBRARIES" "Threads::Threads;Boost::boost"
)
endif()
if(Boost_SYSTEM_LIBRARY AND NOT TARGET Boost::system)
add_library(Boost::system ${LIBRARY_TYPE} IMPORTED)
set_target_properties(Boost::system PROPERTIES
Expand All @@ -171,27 +163,13 @@ if(Boost_SYSTEM_LIBRARY AND NOT TARGET Boost::system)
)
endif()
endif()
if(Boost_FILESYSTEM_LIBRARY AND NOT TARGET Boost::filesystem)
add_library(Boost::filesystem ${LIBRARY_TYPE} IMPORTED)
set_target_properties(Boost::filesystem PROPERTIES
"IMPORTED_LOCATION" "${Boost_FILESYSTEM_LIBRARY}"
"INTERFACE_LINK_LIBRARIES" "Boost::system;Boost::boost"
)
endif()
if(Boost_REGEX_LIBRARY AND NOT TARGET Boost::regex)
add_library(Boost::regex ${LIBRARY_TYPE} IMPORTED)
set_target_properties(Boost::regex PROPERTIES
"IMPORTED_LOCATION" "${Boost_REGEX_LIBRARY}"
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
)
endif()
if(Boost_DATE_TIME_LIBRARY AND NOT TARGET Boost::date_time)
add_library(Boost::date_time ${LIBRARY_TYPE} IMPORTED)
set_target_properties(Boost::date_time PROPERTIES
"IMPORTED_LOCATION" "${Boost_DATE_TIME_LIBRARY}"
"INTERFACE_LINK_LIBRARIES" "Boost::boost"
)
endif()
if(Boost_PROGRAM_OPTIONS_LIBRARY AND NOT TARGET Boost::program_options)
add_library(Boost::program_options ${LIBRARY_TYPE} IMPORTED)
set_target_properties(Boost::program_options PROPERTIES
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ It relies on a few executables:
It relies on a few libraries:

* [Boost](http://www.boost.org/) 1.46 or later (1.51+ on Windows).
Required libraries: *thread*, *system*, *regex*, *date_time* and *program_options*.
Required libraries: *system*, *regex* and *program_options*.
Optional library for Boost Test driver: *test*.
* [GTest](http://code.google.com/p/googletest/) 1.6 or later.
Optional for the GTest driver. By default downloaded and built by CMake.
Expand Down
20 changes: 9 additions & 11 deletions include/cucumber-cpp/internal/ContextManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@

#include <vector>

#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <memory>

namespace cucumber {

namespace internal {

typedef std::vector<boost::shared_ptr<void> > contexts_type;
typedef std::vector<std::shared_ptr<void> > contexts_type;

class CUCUMBER_CPP_EXPORT ContextManager {
public:
void purgeContexts();
template<class T> boost::weak_ptr<T> addContext();
template<class T> std::weak_ptr<T> addContext();

protected:
static contexts_type contexts;
};

template<class T>
boost::weak_ptr<T> ContextManager::addContext() {
boost::shared_ptr<T> shared(boost::make_shared<T>());
std::weak_ptr<T> ContextManager::addContext() {
std::shared_ptr<T> shared(std::make_shared<T>());
contexts.push_back(shared);
return boost::weak_ptr<T> (shared);
return std::weak_ptr<T> (shared);
}

}
Expand All @@ -44,12 +42,12 @@ class ScenarioScope {

private:
internal::ContextManager contextManager;
boost::shared_ptr<T> context;
static boost::weak_ptr<T> contextReference;
std::shared_ptr<T> context;
static std::weak_ptr<T> contextReference;
};

template<class T>
boost::weak_ptr<T> ScenarioScope<T>::contextReference;
std::weak_ptr<T> ScenarioScope<T>::contextReference;

template<class T>
ScenarioScope<T>::ScenarioScope() {
Expand Down
6 changes: 2 additions & 4 deletions include/cucumber-cpp/internal/CukeCommands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
#include <string>
#include <sstream>

#include <boost/shared_ptr.hpp>
#include <memory>

namespace cucumber {
namespace internal {

using boost::shared_ptr;

/**
* Legacy class to be removed when feature #31 is complete, substituted by CukeEngineImpl.
*/
Expand All @@ -41,7 +39,7 @@ class CUCUMBER_CPP_EXPORT CukeCommands {
bool hasStarted;

private:
static shared_ptr<Scenario> currentScenario;
static std::shared_ptr<Scenario> currentScenario;
};

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "ProtocolHandler.hpp"
#include "../../CukeEngine.hpp"

#include <boost/shared_ptr.hpp>
#include <memory>

namespace cucumber {
namespace internal {
Expand Down Expand Up @@ -102,7 +102,7 @@ class CUCUMBER_CPP_EXPORT WireCommand {
*
* @return The command response (ownership passed to the caller)
*/
virtual boost::shared_ptr<WireResponse> run(CukeEngine& engine) const = 0;
virtual std::shared_ptr<WireResponse> run(CukeEngine& engine) const = 0;

virtual ~WireCommand() {};
};
Expand Down Expand Up @@ -136,7 +136,7 @@ class CUCUMBER_CPP_EXPORT WireMessageCodec {
*
* @throws WireMessageCodecException
*/
virtual boost::shared_ptr<WireCommand> decode(const std::string &request) const = 0;
virtual std::shared_ptr<WireCommand> decode(const std::string &request) const = 0;

/**
* Encodes a response to wire format.
Expand All @@ -156,7 +156,7 @@ class CUCUMBER_CPP_EXPORT WireMessageCodec {
class CUCUMBER_CPP_EXPORT JsonSpiritWireMessageCodec : public WireMessageCodec {
public:
JsonSpiritWireMessageCodec();
boost::shared_ptr<WireCommand> decode(const std::string &request) const;
std::shared_ptr<WireCommand> decode(const std::string &request) const;
const std::string encode(const WireResponse& response) const;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CUKE_WIREPROTOCOL_COMMANDS_HPP_

#include "WireProtocol.hpp"
#include <boost/shared_ptr.hpp>
#include <memory>

namespace cucumber {
namespace internal {
Expand All @@ -19,15 +19,15 @@ class BeginScenarioCommand : public ScenarioCommand {
public:
BeginScenarioCommand(const CukeEngine::tags_type& tags);

boost::shared_ptr<WireResponse> run(CukeEngine& engine) const;
std::shared_ptr<WireResponse> run(CukeEngine& engine) const;
};


class EndScenarioCommand : public ScenarioCommand {
public:
EndScenarioCommand(const CukeEngine::tags_type& tags);

boost::shared_ptr<WireResponse> run(CukeEngine& engine) const;
std::shared_ptr<WireResponse> run(CukeEngine& engine) const;
};


Expand All @@ -38,7 +38,7 @@ class StepMatchesCommand : public WireCommand {
public:
StepMatchesCommand(const std::string & stepName);

boost::shared_ptr<WireResponse> run(CukeEngine& engine) const;
std::shared_ptr<WireResponse> run(CukeEngine& engine) const;
};


Expand All @@ -53,7 +53,7 @@ class InvokeCommand : public WireCommand {
const CukeEngine::invoke_args_type& args,
const CukeEngine::invoke_table_type& tableArg);

boost::shared_ptr<WireResponse> run(CukeEngine& engine) const;
std::shared_ptr<WireResponse> run(CukeEngine& engine) const;
};


Expand All @@ -66,13 +66,13 @@ class SnippetTextCommand : public WireCommand {
const std::string & name,
const std::string & multilineArgClass);

boost::shared_ptr<WireResponse> run(CukeEngine& engine) const;
std::shared_ptr<WireResponse> run(CukeEngine& engine) const;
};


class FailingCommand : public WireCommand {
public:
boost::shared_ptr<WireResponse> run(CukeEngine& engine) const;
std::shared_ptr<WireResponse> run(CukeEngine& engine) const;
};

}
Expand Down
31 changes: 15 additions & 16 deletions include/cucumber-cpp/internal/hook/HookRegistrar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
#include "../step/StepManager.hpp"

#include <boost/config.hpp>
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <memory>

#include <list>

Expand Down Expand Up @@ -64,25 +63,25 @@ class CUCUMBER_CPP_EXPORT AfterAllHook : public UnconditionalHook {};

class CUCUMBER_CPP_EXPORT HookRegistrar {
public:
typedef std::list< boost::shared_ptr<Hook> > hook_list_type;
typedef std::list< boost::shared_ptr<AroundStepHook> > aroundhook_list_type;
typedef std::list< std::shared_ptr<Hook> > hook_list_type;
typedef std::list< std::shared_ptr<AroundStepHook> > aroundhook_list_type;

static void addBeforeHook(boost::shared_ptr<BeforeHook> afterHook);
static void addBeforeHook(std::shared_ptr<BeforeHook> afterHook);
static void execBeforeHooks(Scenario *scenario);

static void addAroundStepHook(boost::shared_ptr<AroundStepHook> aroundStepHook);
static void addAroundStepHook(std::shared_ptr<AroundStepHook> aroundStepHook);
static InvokeResult execStepChain(Scenario *scenario, const StepInfo* stepInfo, const InvokeArgs *pArgs);

static void addAfterStepHook(boost::shared_ptr<AfterStepHook> afterStepHook);
static void addAfterStepHook(std::shared_ptr<AfterStepHook> afterStepHook);
static void execAfterStepHooks(Scenario *scenario);

static void addAfterHook(boost::shared_ptr<AfterHook> afterHook);
static void addAfterHook(std::shared_ptr<AfterHook> afterHook);
static void execAfterHooks(Scenario *scenario);

static void addBeforeAllHook(boost::shared_ptr<BeforeAllHook> beforeAllHook);
static void addBeforeAllHook(std::shared_ptr<BeforeAllHook> beforeAllHook);
static void execBeforeAllHooks();

static void addAfterAllHook(boost::shared_ptr<AfterAllHook> afterAllHook);
static void addAfterAllHook(std::shared_ptr<AfterAllHook> afterAllHook);
static void execAfterAllHooks();

private:
Expand Down Expand Up @@ -133,45 +132,45 @@ class CUCUMBER_CPP_EXPORT CallableStepChain : public CallableStep {

template<class T>
static int registerBeforeHook(const std::string &csvTagNotation) {
boost::shared_ptr<T> hook(boost::make_shared<T>());
std::shared_ptr<T> hook(std::make_shared<T>());
hook->setTags(csvTagNotation);
HookRegistrar::addBeforeHook(hook);
return 0; // We are not interested in the ID at this time
}

template<class T>
static int registerAroundStepHook(const std::string &csvTagNotation) {
boost::shared_ptr<T> hook(boost::make_shared<T>());
std::shared_ptr<T> hook(std::make_shared<T>());
hook->setTags(csvTagNotation);
HookRegistrar::addAroundStepHook(hook);
return 0;
}

template<class T>
static int registerAfterStepHook(const std::string &csvTagNotation) {
boost::shared_ptr<T> hook(boost::make_shared<T>());
std::shared_ptr<T> hook(std::make_shared<T>());
hook->setTags(csvTagNotation);
HookRegistrar::addAfterStepHook(hook);
return 0;
}

template<class T>
static int registerAfterHook(const std::string &csvTagNotation) {
boost::shared_ptr<T> hook(boost::make_shared<T>());
std::shared_ptr<T> hook(std::make_shared<T>());
hook->setTags(csvTagNotation);
HookRegistrar::addAfterHook(hook);
return 0;
}

template<class T>
static int registerBeforeAllHook() {
HookRegistrar::addBeforeAllHook(boost::make_shared<T>());
HookRegistrar::addBeforeAllHook(std::make_shared<T>());
return 0;
}

template<class T>
static int registerAfterAllHook() {
HookRegistrar::addAfterAllHook(boost::make_shared<T>());
HookRegistrar::addAfterAllHook(std::make_shared<T>());
return 0;
}

Expand Down
Loading

0 comments on commit 57faadb

Please sign in to comment.