From 204218c71bf76ba5edb52e7277867f58d0ed4778 Mon Sep 17 00:00:00 2001 From: a7458969 <290198252@qq.com> Date: Tue, 19 May 2020 00:53:46 +0800 Subject: [PATCH] no message --- general/src/pattern/factory.hpp | 7 ++++--- test/CMakeLists.txt | 2 +- test/src/patterntest/CMakeLists.txt | 12 ++++++++++++ test/src/patterntest/pattern_test.cpp | 22 ++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 test/src/patterntest/CMakeLists.txt create mode 100644 test/src/patterntest/pattern_test.cpp diff --git a/general/src/pattern/factory.hpp b/general/src/pattern/factory.hpp index 8a6ce5c..b20a913 100644 --- a/general/src/pattern/factory.hpp +++ b/general/src/pattern/factory.hpp @@ -19,12 +19,13 @@ public: virtual T* Clone(){ } -} +}; + template class Prototype{ public: - Prototype(CloneAble *){ - + Prototype(CloneAble *s){ + mProto = s->Clone(); } virtual T*GetProduct(){ return mProto->Clone(); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ddf1514..73f35af 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -10,4 +10,4 @@ link_libraries(libGeneral.a) link_libraries(ws2_32) link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../third/lib/libevent.a) link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/../third/lib/libevent_core.a) -add_executable(tcptest src/tcpclient_test.cpp) \ No newline at end of file +add_executable(tcptest src/tcpclient_test.cpp src/patterntest/pattern_test.cpp) \ No newline at end of file diff --git a/test/src/patterntest/CMakeLists.txt b/test/src/patterntest/CMakeLists.txt new file mode 100644 index 0000000..9856bf0 --- /dev/null +++ b/test/src/patterntest/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.15) +project(pattern_test) + +message("current dir" ../..) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../general/obj/inc/third/include) +include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../../general/obj/inc/) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../general/obj/inc/third/include) +message("shit" ${CMAKE_CURRENT_SOURCE_DIR}/../../../general/obj/inc/) +message("shit" ${CMAKE_CURRENT_SOURCE_DIR}/../../../general/obj/inc/third/include) + +add_executable(pattern_test pattern_test.cpp) \ No newline at end of file diff --git a/test/src/patterntest/pattern_test.cpp b/test/src/patterntest/pattern_test.cpp new file mode 100644 index 0000000..0fa6769 --- /dev/null +++ b/test/src/patterntest/pattern_test.cpp @@ -0,0 +1,22 @@ +// +// Created by 29019 on 2020/5/18. +// +#include "factory.hpp" + +class Product :public CloneAble{ +public: + Product *Clone(){ + Product *ret = new Product; + ret->mAttribute1 = this->mAttribute1; + ret->mAttribute2 = this->mAttribute2; + return ret; + } +private: + int mAttribute1; + char mAttribute2; +}; +int main(){ + Product z; + Prototype x(&z); + x.GetProduct(); +} \ No newline at end of file