diff --git a/CMakeLists.txt b/CMakeLists.txt index a3ec4164..069d046f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) if (UNIX) - add_definitions(-std=c++11) + add_definitions(-std=c++11 -Wno-unknown-warning-option) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin/${CMAKE_BUILD_TYPE}) else () set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) @@ -43,6 +43,15 @@ find_package(CLANG REQUIRED PATHS "${CMAKE_SOURCE_DIR}/cmake") add_definitions(${CLANG_DEFINITIONS}) +# Boost ------------------------------------------------------------------------ + +set(BOOST_ROOT $ENV{BOOST_155_DIR}) +set(Boost_USE_MULTITHREAD ON) +set(Boost_USE_STATIC_LIBS OFF) +set(Boost_USE_STATIC_RUNTIME OFF) +set(BOOST_LIBRARYDIR $ENV{BOOST_155_DIR}) +find_package( Boost 1.55 COMPONENTS system filesystem REQUIRED ) + # Lib -------------------------------------------------------------------------- @@ -71,12 +80,12 @@ set_property( "${CMAKE_SOURCE_DIR}/src/external" ${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} ) -link_directories(${LLVM_LIBRARY_DIRS} ${CLANG_LIBRARY_DIRS}) - -target_link_libraries(${LIB_PROJECT_NAME} ${CLANG_LIBRARIES} ${LLVM_AVAILABLE_LIBS}) +link_directories(${LLVM_LIBRARY_DIRS} ${CLANG_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS}) +target_link_libraries(${LIB_PROJECT_NAME} ${CLANG_LIBRARIES} ${LLVM_AVAILABLE_LIBS} ${Boost_LIBRARIES}) # App -------------------------------------------------------------------------- @@ -118,7 +127,6 @@ configure_file( set(CMAKE_AUTOMOC OFF) - # CxxTest ---------------------------------------------------------------------- add_subdirectory(src/test) diff --git a/README.md b/README.md index 588c4bc7..32d9e06a 100644 --- a/README.md +++ b/README.md @@ -8,12 +8,14 @@ * CxxTest 4.3 * Valgrind 3.9.0(linux, macOS) * Clang & LLVM (installation guide http://clang.llvm.org/docs/LibASTMatchersTutorial.html) +* Boost 1.55 () ##### Environment Variables * QT_DIR - ...\Qt\Qt5.2.1\5.2.1\\ * CXX_TEST_DIR - .../cxxtest-4.3/ * CLANG_DIR - .../clang-llvm/ +* BOOST_155_DIR - .../boost_1_55_0 For Win32: * VLD_DIR - .../Visual Leak Detector diff --git a/bin/data/src/Settings/player.h b/bin/data/src/Settings/player.h new file mode 100644 index 00000000..3d3a6acc --- /dev/null +++ b/bin/data/src/Settings/player.h @@ -0,0 +1,21 @@ +#ifndef _PLAYER_ +#define _PLAYER_ + +#include + +#include "field.h" + +class Player { +public: + Player( Field::Token token, const std::string& name ) + : token_( token ) + , name_( name ) { + } + + virtual Field::Move Turn( const Field& field ) const = 0; + + const Field::Token token_; + const std::string name_; +}; + +#endif // _PLAYER_ diff --git a/bin/data/src/Settings/sample.cpp b/bin/data/src/Settings/sample.cpp new file mode 100644 index 00000000..3da1b3ce --- /dev/null +++ b/bin/data/src/Settings/sample.cpp @@ -0,0 +1,33 @@ +class Player { +public: + void Do() {} +}; + +class Base {}; + +class Game : public Base { +public: + Game() { + Init(); + } + + void Init() {} + + void Run() { + player.Do(); + } + +private: + Player player; +}; + +Game* game; + +int main() { + game = new Game(); + + game->Run(); + + delete game; + return 0; +} diff --git a/bin/data/src/Sound.hpp b/bin/data/src/Sound.hpp new file mode 100644 index 00000000..e69de29b diff --git a/bin/data/src/main.cpp b/bin/data/src/main.cpp new file mode 100644 index 00000000..f4bb5ef9 --- /dev/null +++ b/bin/data/src/main.cpp @@ -0,0 +1,11 @@ +#include "tictactoe.h" + +int main() { + TicTacToe tictactoe; + + while ( tictactoe.Start() ) { + tictactoe.Run(); + } + + return 0; +} \ No newline at end of file diff --git a/bin/data/src/tictactoe.h b/bin/data/src/tictactoe.h new file mode 100644 index 00000000..c84071c3 --- /dev/null +++ b/bin/data/src/tictactoe.h @@ -0,0 +1,93 @@ +#ifndef _TIC_TAC_TOE_ +#define _TIC_TAC_TOE_ + +#include "computer.h" +#include "field.h" +#include "human.h" +#include "input.h" +#include "player.h" + +class TicTacToe { +public: + TicTacToe() { + players_[0] = NULL; + players_[1] = NULL; + } + + ~TicTacToe() { + Reset(); + } + + bool Start() { + Reset(); + std::cout << "Tic Tac Toe\n\n[1] Human\n[2] Computer\n[3] Quit\n\n"; + + players_[0] = SelectPlayer( Field::PlayerA, "PlayerA" ); + if ( !players_[0] ) { + return false; + } + + players_[1] = SelectPlayer( Field::PlayerB, "PlayerB" ); + if ( !players_[1] ) { + return false; + } + + std::cout << '\n'; + return true; + } + + void Run() { + field_.Show(); + + int playerIndex = 0; + + for ( int i = 0; i < 9; i++ ) { + Player& player = *players_[playerIndex]; + + field_.MakeMove( player.Turn( field_ ), player.token_ ); + field_.Show(); + + if ( field_.SameInRow( player.token_, 3 ) ) { + std::cout << player.name_ << " won!\n\n"; + return; + } + + playerIndex = ( playerIndex + 1 ) % 2; + } + + std::cout << "Game ends in draw!\n\n"; + } + +private: + void Reset() { + field_.Clear(); + + for ( int i = 0; i < 2; i++ ) { + if ( players_[i] ) { + delete players_[i]; + players_[i] = NULL; + } + } + } + + Player* SelectPlayer( Field::Token token, const std::string& name ) const { + int selection; + + while ( true ) { + std::cout << "Choose " << name << ": "; + input::number( &selection ); + + switch ( selection ) { + case 1 : return new HumanPlayer( token, name ); + case 2 : return new ArtificialPlayer( token, name ); + case 3 : return NULL; + default : std::cout << "Wrong input!\n"; + } + } + } + + Player* players_[2]; + Field field_; +}; + +#endif // _TIC_TAC_TOE_ \ No newline at end of file diff --git a/bin/data/test_ProjectSettings.xml b/bin/data/test_ProjectSettings.xml new file mode 100644 index 00000000..457d962f --- /dev/null +++ b/bin/data/test_ProjectSettings.xml @@ -0,0 +1,5 @@ + + + the/awesome/path/to/the/code + + diff --git a/script/valgrind_debug.sh b/script/valgrind_debug.sh index 3e8bbc2b..8477361c 100755 --- a/script/valgrind_debug.sh +++ b/script/valgrind_debug.sh @@ -6,4 +6,4 @@ MY_PATH=`dirname "$0"` cd $MY_PATH/.. # Build and run target -make -C build/Debug "$1" && cd bin && valgrind --tool=memcheck --leak-check=yes --log-file=../build/Debug/"$1".leaklog Debug/"$1" +ninja -C build/Debug "$1" && cd bin && valgrind --tool=memcheck --leak-check=yes --log-file=../build/Debug/"$1".leaklog Debug/"$1" diff --git a/script/valgrind_release.sh b/script/valgrind_release.sh index db9fadef..44eb763f 100755 --- a/script/valgrind_release.sh +++ b/script/valgrind_release.sh @@ -6,4 +6,4 @@ MY_PATH=`dirname "$0"` cd $MY_PATH/.. # Build and run target -make -C build/Release "$1" && cd bin && valgrind --tool=memcheck --leak-check=yes --log-file=../build/Release/"$1".leaklog Release/"$1" +ninja -C build/Release "$1" && cd bin && valgrind --tool=memcheck --leak-check=yes --log-file=../build/Release/"$1".leaklog Release/"$1" diff --git a/setup/dynamic_libraries/windows/Debug/boost_filesystem-vc110-mt-gd-1_55.dll b/setup/dynamic_libraries/windows/Debug/boost_filesystem-vc110-mt-gd-1_55.dll new file mode 100644 index 00000000..4a5fc426 Binary files /dev/null and b/setup/dynamic_libraries/windows/Debug/boost_filesystem-vc110-mt-gd-1_55.dll differ diff --git a/setup/dynamic_libraries/windows/Debug/boost_system-vc110-mt-gd-1_55.dll b/setup/dynamic_libraries/windows/Debug/boost_system-vc110-mt-gd-1_55.dll new file mode 100644 index 00000000..8320a9a1 Binary files /dev/null and b/setup/dynamic_libraries/windows/Debug/boost_system-vc110-mt-gd-1_55.dll differ diff --git a/setup/dynamic_libraries/windows/Release/boost_filesystem-vc110-mt-1_55.dll b/setup/dynamic_libraries/windows/Release/boost_filesystem-vc110-mt-1_55.dll new file mode 100644 index 00000000..13da5e64 Binary files /dev/null and b/setup/dynamic_libraries/windows/Release/boost_filesystem-vc110-mt-1_55.dll differ diff --git a/setup/dynamic_libraries/windows/Release/boost_system-vc110-mt-1_55.dll b/setup/dynamic_libraries/windows/Release/boost_system-vc110-mt-1_55.dll new file mode 100644 index 00000000..cab758b0 Binary files /dev/null and b/setup/dynamic_libraries/windows/Release/boost_system-vc110-mt-1_55.dll differ diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index d9b2dea5..38dc28b4 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -98,7 +98,7 @@ add_files( utility/logging/LogManagerImplementation.cpp utility/logging/LogManagerImplementation.h utility/logging/LogMessage.h - + utility/math/Color.h utility/math/Vector2.h utility/math/Vector4.h @@ -112,6 +112,8 @@ add_files( utility/ConfigManager.cpp utility/ConfigManager.h + utility/FileSystem.cpp + utility/FileSystem.h utility/Vector.h Application.cpp diff --git a/src/lib/utility/FileSystem.cpp b/src/lib/utility/FileSystem.cpp new file mode 100644 index 00000000..ed0deebd --- /dev/null +++ b/src/lib/utility/FileSystem.cpp @@ -0,0 +1,43 @@ +#include "utility/FileSystem.h" + +#include "boost/filesystem.hpp" +#include "utility/logging/logging.h" + +std::vector FileSystem::getSourceFilesFromDirectory( + const std::string& path, const std::vector& extensions +) +{ + std::vector files; + if (boost::filesystem::is_directory(path)) + { + boost::filesystem::recursive_directory_iterator it(path); + boost::filesystem::recursive_directory_iterator endit; + while(it != endit) + { + if (boost::filesystem::is_regular_file(*it) && isValidExtension(it->path().string(), extensions)) + { + files.push_back(it->path().string()); + } + ++it; + } + } + return files; +} + +bool FileSystem::isValidExtension(const std::string& filepath, const std::vector& extensions) +{ + boost::filesystem::path path(filepath); + for(std::string extension : extensions) + { + if(path.extension() == extension) + { + return true; + } + } + return false; +} + +bool FileSystem::exists(const std::string& path) +{ + return boost::filesystem::exists(boost::filesystem::path(path)); +} diff --git a/src/lib/utility/FileSystem.h b/src/lib/utility/FileSystem.h new file mode 100644 index 00000000..94f72037 --- /dev/null +++ b/src/lib/utility/FileSystem.h @@ -0,0 +1,18 @@ +#ifndef FILE_SYSTEM_H +#define FILE_SYSTEM_H + +#include +#include + +class FileSystem +{ +public: + static std::vector getSourceFilesFromDirectory( + const std::string& path, const std::vector& extensions + ); + static bool exists(const std::string& path); +private: + static bool isValidExtension(const std::string& filepath, const std::vector& extensions); +}; + +#endif // FILE_SYSTEM_H diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index db11e981..138e52ef 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -3,6 +3,7 @@ add_files( ConfigManagerTestSuite.h CxxParserTestSuite.h + FileSystemTestSuite.h LogManagerTestSuite.h MessageQueueTestSuite.h TestSuiteFixture.cpp diff --git a/src/test/FileSystemTestSuite.h b/src/test/FileSystemTestSuite.h new file mode 100644 index 00000000..125d9c68 --- /dev/null +++ b/src/test/FileSystemTestSuite.h @@ -0,0 +1,65 @@ +#include "cxxtest/TestSuite.h" + +#include +#include +#include + +#include "utility/FileSystem.h" + +class FileSystemTestSuite : public CxxTest::TestSuite +{ +public: + void test_find_cpp_files() + { + std::vector extensions; + extensions.push_back(".cpp"); + + std::vector cppFiles = FileSystem::getSourceFilesFromDirectory("data/src",extensions); + + TS_ASSERT_EQUALS(cppFiles.size(), 2) + TS_ASSERT(isInVector(cppFiles, "data/src/main.cpp")) + TS_ASSERT(isInVector(cppFiles, "data/src/Settings/sample.cpp")) + } + + void test_find_h_files() + { + std::vector extensions; + extensions.push_back(".h"); + + std::vector headerFiles = FileSystem::getSourceFilesFromDirectory("data/src",extensions); + + TS_ASSERT_EQUALS(headerFiles.size(), 2) + TS_ASSERT(isInVector(headerFiles, "data/src/tictactoe.h")) + TS_ASSERT(isInVector(headerFiles, "data/src/Settings/player.h")) + } + + void test_find_all_source_files() + { + std::vector extensions; + extensions.push_back(".h"); + extensions.push_back(".hpp"); + extensions.push_back(".cpp"); + + std::vector sourceFiles = FileSystem::getSourceFilesFromDirectory("data/src",extensions); + + TS_ASSERT_EQUALS(sourceFiles.size(), 5) + } + + void test_filesystem_finds_existing_files() + { + TS_ASSERT(FileSystem::exists("data/src")) + TS_ASSERT(FileSystem::exists("data/src/tictactoe.h")); + } + + void test_filesystem_does_not_find_non_existing_files() + { + TS_ASSERT(!FileSystem::exists("data/foo")); + TS_ASSERT(!FileSystem::exists("data/src/blabla.h")); + } + +private: + bool isInVector(const std::vector& files, const std::string filename) + { + return std::end(files) != std::find(std::begin(files), std::end(files), filename); + } +};