diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ef7013..a85e43a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,55 +8,6 @@ SET(CMAKE_BUILD_TYPE Debug) set (EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin) set (LIBRARY_OUTPUT_PATH ${EXECUTABLE_OUTPUT_PATH}) -# add a target to generate API documentation with Doxygen -find_package(Doxygen) -if(DOXYGEN_FOUND) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY) - add_custom_target(doc - ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMENT "Generating API documentation with Doxygen" VERBATIM - ) -endif(DOXYGEN_FOUND) - - -# Download and unpack googletest at configure time -configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) -execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) -if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") -endif() -execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) -if(result) - message(FATAL_ERROR "Build step for googletest failed: ${result}") -endif() - -# Prevent overriding the parent project's compiler/linker -# settings on Windows -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - -# Add googletest directly to our build. This defines -# the gtest and gtest_main targets. -add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src - ${CMAKE_CURRENT_BINARY_DIR}/googletest-build - EXCLUDE_FROM_ALL) - -# The gtest/gtest_main targets carry header search path -# dependencies automatically when using CMake 2.8.11 or -# later. Otherwise we have to add them here ourselves. -if (CMAKE_VERSION VERSION_LESS 2.8.11) - include_directories("${gtest_SOURCE_DIR}/include") -endif() - -# Now simply link against gtest or gtest_main as needed. Eg -#add_executable(example example.cpp) -#target_link_libraries(example gtest_main) -#add_test(NAME example_test COMMAND example) - add_subdirectory(src) -set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" "CMakeFiles" "C" "googletest-build" "googletest-download" "googletest-src" "lib") +set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "bin" "doc" "CMakeFiles" "C" "lib") diff --git a/CMakeLists.txt.in b/CMakeLists.txt.in deleted file mode 100644 index d3c1d55..0000000 --- a/CMakeLists.txt.in +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 2.8.2) - -project(googletest-download NONE) - -include(ExternalProject) -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG master - SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" - BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - TEST_COMMAND "" - ) \ No newline at end of file diff --git a/Doxyfile b/Doxyfile deleted file mode 100644 index db8cd15..0000000 --- a/Doxyfile +++ /dev/null @@ -1,42 +0,0 @@ -#--------------------------------------------------------------------------- -# Project related configuration options -#--------------------------------------------------------------------------- -PROJECT_NAME = C/C++ -PROJECT_NUMBER = -OUTPUT_DIRECTORY = @CMAKE_CURRENT_SOURCE_DIR@/doc -CREATE_SUBDIRS = NO -OUTPUT_LANGUAGE = English -... -JAVADOC_AUTOBRIEF = YES -... -#--------------------------------------------------------------------------- -# Build related configuration options -#--------------------------------------------------------------------------- -EXTRACT_ALL = NO -... -#--------------------------------------------------------------------------- -# configuration options related to the input files -#--------------------------------------------------------------------------- -INPUT = @CMAKE_CURRENT_SOURCE_DIR@/src/ -FILE_PATTERNS = -RECURSIVE = YES -EXCLUDE = -... -#--------------------------------------------------------------------------- -# configuration options related to the HTML output -#--------------------------------------------------------------------------- -GENERATE_HTML = YES -HTML_OUTPUT = html -HTML_FILE_EXTENSION = .html -HTML_HEADER = -HTML_FOOTER = -... -... - -GENERATE_LATEX = NO -#--------------------------------------------------------------------------- -# Configuration::additions related to the search engine -#--------------------------------------------------------------------------- -SEARCHENGINE = YES - - diff --git a/src/07_STD/CMakeLists.txt b/src/07_STD/CMakeLists.txt index 659f9c3..3dc8a35 100644 --- a/src/07_STD/CMakeLists.txt +++ b/src/07_STD/CMakeLists.txt @@ -1,4 +1,2 @@ add_executable(07_STD_MP MP/grundgeruest.cpp MP/BinaryOctet.cpp MP/BinaryOctet.h) -add_executable(07_STD_Testat Testat/grundgeruest.cpp Testat/BinaryOctet.h Testat/BinaryOctet.cpp) -target_link_libraries(07_STD_Testat gtest_main) -add_test(NAME 07_STD_Testat COMMAND InsertBinaryOctet) \ No newline at end of file +add_executable(07_STD_Testat Testat/grundgeruest.cpp Testat/BinaryOctet.h Testat/BinaryOctet.cpp) \ No newline at end of file diff --git a/src/07_STD/Testat/grundgeruest.cpp b/src/07_STD/Testat/grundgeruest.cpp index 7888893..2fe11ca 100644 --- a/src/07_STD/Testat/grundgeruest.cpp +++ b/src/07_STD/Testat/grundgeruest.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "BinaryOctet.h" // for println(); @@ -61,7 +60,3 @@ int main() { std::cout << binaryOctet << std::endl; } } - -TEST(STD_Testat, InsertBinaryOctet) { - ASSERT_EQ(42, 42); -} diff --git a/src/08_PTRN/CMakeLists.txt b/src/08_PTRN/CMakeLists.txt index ecc59ef..66ff7c8 100644 --- a/src/08_PTRN/CMakeLists.txt +++ b/src/08_PTRN/CMakeLists.txt @@ -1,2 +1,2 @@ add_executable(08_PTRN_MP MP/VehicleFactory.cpp MP/VehicleFactory.hpp MP/Vehicle.cpp MP/Vehicle.hpp MP/Car.cpp MP/Car.hpp MP/Truck.cpp MP/Truck.hpp MP/Logger.cpp MP/Logger.hpp MP/main.cpp) -add_executable(08_PTRN_Testat Testat/main.cpp Testat/Money.cpp Testat/Money.h Testat/Logger.cpp Testat/Logger.hpp Testat/Currency.h Testat/BankAccount.cpp Testat/BankAccount.h Testat/Cash.cpp Testat/Cash.h Testat/Currency.cpp Testat/Coin.cpp Testat/Coin.h Testat/Bill.cpp Testat/Bill.h Testat/CashFactory.cpp Testat/CashFactory.h) \ No newline at end of file +add_executable(08_PTRN_Testat Testat/main.cpp Testat/Money.cpp Testat/Money.h Testat/Currency.h Testat/BankAccount.cpp Testat/BankAccount.h Testat/Cash.cpp Testat/Cash.h Testat/Currency.cpp Testat/Coin.cpp Testat/Coin.h Testat/Bill.cpp Testat/Bill.h Testat/CashFactory.cpp Testat/CashFactory.h Testat/Person.cpp Testat/Person.h) \ No newline at end of file diff --git a/src/08_PTRN/Testat/BankAccount.cpp b/src/08_PTRN/Testat/BankAccount.cpp index 4493ff1..c6dac8f 100644 --- a/src/08_PTRN/Testat/BankAccount.cpp +++ b/src/08_PTRN/Testat/BankAccount.cpp @@ -1,14 +1,16 @@ #include "BankAccount.h" -BankAccount::BankAccount(std::string name) : name(std::move(name)) {} +BankAccount::BankAccount(Person *owner, std::string name) : name(std::move(name)) { +this->owner = owner; +} BankAccount * BankAccount::operator+(Money* money) { BankAccount::money = new Money(money->getValue() + getMoney().getValue()); return this; } -bool BankAccount::operator<(BankAccount bankAccount) { - return money.getValue() < bankAccount.money.getValue(); +bool BankAccount::operator<(BankAccount * bankAccount) { + return money.getValue() < bankAccount->money.getValue(); } std::string BankAccount::getName() { @@ -19,5 +21,9 @@ Money BankAccount::getMoney() { return money; } +Person *BankAccount::getOwner() { + return owner; +} + diff --git a/src/08_PTRN/Testat/BankAccount.h b/src/08_PTRN/Testat/BankAccount.h index 12cd8bb..41280ee 100644 --- a/src/08_PTRN/Testat/BankAccount.h +++ b/src/08_PTRN/Testat/BankAccount.h @@ -5,16 +5,19 @@ #include "Money.h" #include "Cash.h" +#include "Person.h" class BankAccount { private: std::string name; + Person * owner; Money money; public: - explicit BankAccount(std::string name); - BankAccount* operator+(Money* money); - bool operator<(BankAccount bankAccount); + explicit BankAccount(Person * owner, std::string name); + BankAccount* operator+(Money * money); + bool operator<(BankAccount * bankAccount); std::string getName(); + Person * getOwner(); Money getMoney(); }; diff --git a/src/08_PTRN/Testat/Bill.h b/src/08_PTRN/Testat/Bill.h index 71feaf5..56a1ee4 100644 --- a/src/08_PTRN/Testat/Bill.h +++ b/src/08_PTRN/Testat/Bill.h @@ -13,4 +13,4 @@ public: }; -#endif +#endif \ No newline at end of file diff --git a/src/08_PTRN/Testat/CashFactory.cpp b/src/08_PTRN/Testat/CashFactory.cpp index 0051730..669bf26 100644 --- a/src/08_PTRN/Testat/CashFactory.cpp +++ b/src/08_PTRN/Testat/CashFactory.cpp @@ -8,7 +8,7 @@ int allowedCoins[8] = {1, 2, 5, 10, 20, 50, 100, 200}; Bill * CashFactory::printBill(int value, Currency currency) { auto * iter = std::find(std::begin(allowedBills), std::end(allowedBills), value); if(iter == std::end(allowedBills)) { - std::cout << "Ungültiger Schein" << std::endl; + return nullptr; }else { std::string serial = randomString(15); while(std::find(usedSerials.begin(), usedSerials.end(), serial) != usedSerials.end()) { @@ -19,6 +19,13 @@ Bill * CashFactory::printBill(int value, Currency currency) { } } +Coin * CashFactory::printCoin(int value, Currency currency) { + auto * iter = std::find(std::begin(allowedCoins), std::end(allowedCoins), value); + if(iter == std::end(allowedCoins)) { + return nullptr; + }else return new Coin(value, currency); +} + std::string CashFactory::randomString(size_t length) { auto randchar = []() -> char { const char charset[] = diff --git a/src/08_PTRN/Testat/CashFactory.h b/src/08_PTRN/Testat/CashFactory.h index 8b02e7a..a133672 100644 --- a/src/08_PTRN/Testat/CashFactory.h +++ b/src/08_PTRN/Testat/CashFactory.h @@ -4,13 +4,15 @@ #include #include #include "Bill.h" +#include "Coin.h" class CashFactory { private: std::vector usedSerials; std::string randomString(size_t length); public: - Bill* printBill(int value, Currency currency); + Bill * printBill(int value, Currency currency); + Coin * printCoin(int value, Currency currency); }; diff --git a/src/08_PTRN/Testat/Coin.cpp b/src/08_PTRN/Testat/Coin.cpp index 5908b61..77744e8 100644 --- a/src/08_PTRN/Testat/Coin.cpp +++ b/src/08_PTRN/Testat/Coin.cpp @@ -2,4 +2,4 @@ Coin::Coin(int value, Currency currency) : Cash(value, currency) { -} +} \ No newline at end of file diff --git a/src/08_PTRN/Testat/Coin.h b/src/08_PTRN/Testat/Coin.h index b700dec..0ff4dde 100644 --- a/src/08_PTRN/Testat/Coin.h +++ b/src/08_PTRN/Testat/Coin.h @@ -10,5 +10,4 @@ public: Coin(int value, Currency currency); }; - #endif diff --git a/src/08_PTRN/Testat/Logger.cpp b/src/08_PTRN/Testat/Logger.cpp deleted file mode 100644 index 29df18d..0000000 --- a/src/08_PTRN/Testat/Logger.cpp +++ /dev/null @@ -1,15 +0,0 @@ -// file Logger.cpp -#include "Logger.hpp" - -Logger* Logger::_theInstance = nullptr; - -Logger* Logger::getInstance(){ - if (!_theInstance){ - _theInstance = new StdoutLogger(); - } - return _theInstance; -} - -void StdoutLogger::log(std::string message, std::string file, int line){ - std::cerr << message << " in " << file << " line " << line << std::endl; -} diff --git a/src/08_PTRN/Testat/Logger.hpp b/src/08_PTRN/Testat/Logger.hpp deleted file mode 100644 index 9b3006c..0000000 --- a/src/08_PTRN/Testat/Logger.hpp +++ /dev/null @@ -1,19 +0,0 @@ -// file Logger.hpp -#ifndef Logger_hpp -#define Logger_hpp - -#include - -class Logger { - static Logger* _theInstance; -public: - virtual void log(std::string message, std::string file="", int line=0) = 0; - static Logger* getInstance(); -}; - -class StdoutLogger: public Logger { -public: - void log(std::string message, std::string file="", int line=0); -}; - -#endif diff --git a/src/08_PTRN/Testat/Money.cpp b/src/08_PTRN/Testat/Money.cpp index 3ceba89..b5d1601 100644 --- a/src/08_PTRN/Testat/Money.cpp +++ b/src/08_PTRN/Testat/Money.cpp @@ -18,28 +18,22 @@ Money &Money::operator=(Money *money) { Money Money::operator+(Money &a) { if(currency == a.currency) { - return Money(); + return Money(value + a.value); }else return Money(-1, Currency(CurrencyValue::USD)); } Money Money::operator-(Money &a) { - return Money(); + if(currency == a.currency) { + return Money(value - a.value); + }else return Money(-1, Currency(CurrencyValue::USD)); } const Money Money::operator++(int) { - return Money(); + return Money(value++); } const Money Money::operator--(int) { - return Money(); -} - -bool Money::operator==(Money &a) { - return false; -} - -bool Money::operator!=(Money &a) { - return false; + return Money(value--); } Currency Money::getCurrency() { diff --git a/src/08_PTRN/Testat/Money.h b/src/08_PTRN/Testat/Money.h index 3b95672..34866e1 100644 --- a/src/08_PTRN/Testat/Money.h +++ b/src/08_PTRN/Testat/Money.h @@ -15,8 +15,6 @@ public: Money operator-(Money &a); const Money operator++(int); const Money operator--(int); - bool operator==(Money &a); - bool operator!=(Money &a); int getValue(); Currency getCurrency(); diff --git a/src/08_PTRN/Testat/Person.cpp b/src/08_PTRN/Testat/Person.cpp new file mode 100644 index 0000000..32ba318 --- /dev/null +++ b/src/08_PTRN/Testat/Person.cpp @@ -0,0 +1,11 @@ +#include + +#include "Person.h" + +Person::Person(std::string name) : name(std::move(name)){ + +} + +std::string Person::getName() { + return name; +} diff --git a/src/08_PTRN/Testat/Person.h b/src/08_PTRN/Testat/Person.h new file mode 100644 index 0000000..d59b0bf --- /dev/null +++ b/src/08_PTRN/Testat/Person.h @@ -0,0 +1,16 @@ +#ifndef C_C_PERSON_H +#define C_C_PERSON_H + + +#include + +class Person { +private: + std::string name; +public: + Person(std::string name); + std::string getName(); +}; + + +#endif diff --git a/src/08_PTRN/Testat/main.cpp b/src/08_PTRN/Testat/main.cpp index 09711fb..570ecce 100644 --- a/src/08_PTRN/Testat/main.cpp +++ b/src/08_PTRN/Testat/main.cpp @@ -38,8 +38,13 @@ std::ostream &operator<<(std::ostream &os, Money money) { return os; } +std::ostream &operator<<(std::ostream &os, Person * person) { + os << person->getName(); + return os; +} + std::ostream &operator<<(std::ostream &os, BankAccount bankAccount) { - os << bankAccount.getName() << ": " << bankAccount.getMoney(); + os << bankAccount.getOwner() << " " << bankAccount.getName() << ": " << bankAccount.getMoney(); return os; } @@ -48,10 +53,13 @@ std::ostream &operator<<(std::ostream &os, BankAccount bankAccount) { int main(int argc, char **argv) { std::set accounts; - accounts.insert(new BankAccount("Max Müller")); - accounts.insert(new BankAccount("Max Maier")); - accounts.insert(new BankAccount("Marius Muller")); - accounts.insert(new BankAccount("Test 123")); + Person * max = new Person("Max Müller"); + Person * marius = new Person("Marius Müller"); + + accounts.insert(new BankAccount(max, "Konto 1")); + accounts.insert(new BankAccount(max, "Konto 2")); + accounts.insert(new BankAccount(marius, "Konto 1")); + accounts.insert(new BankAccount(marius, "Konto 2")); auto * cashFactory = new CashFactory(); @@ -60,8 +68,13 @@ int main(int argc, char **argv) { for (int i = 0; i < 1000; ++i) { int rnd = distribution(generator); Bill * bill = cashFactory->printBill(rnd, CurrencyValue::USD); - //std::cout << *bill << std::endl; - BankAccount* res = *bankAccount + bill; + Coin * coin = cashFactory->printCoin(rnd, CurrencyValue::USD); + if(bill != nullptr) { + *bankAccount + bill; + } + if(coin != nullptr) { + *bankAccount + coin; + } } std::cout << *bankAccount << std::endl; });