iutest  1.17.99.14
iutest_factory.hpp
[詳解]
1 //======================================================================
2 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 //======================================================================
15 #ifndef INCG_IRIS_IUTEST_FACTORY_HPP_9C2B4B94_95A0_479A_9C9D_43FB31845A73_
16 #define INCG_IRIS_IUTEST_FACTORY_HPP_9C2B4B94_95A0_479A_9C9D_43FB31845A73_
17 
18 namespace iutest {
19 
20 //======================================================================
21 // declare
22 class Test;
23 
24 namespace detail
25 {
26 
27 //======================================================================
28 // class
33 class iuFactoryBase
34 {
36 public:
37  iuFactoryBase() IUTEST_CXX_NOEXCEPT_SPEC {}
38  virtual ~iuFactoryBase() {}
39 public:
40  virtual auto_ptr<Test> Create() = 0;
41 };
42 
48 template<class Tester>
49 class iuFactory IUTEST_CXX_FINAL : public iuFactoryBase
50 {
51 public:
52  virtual auto_ptr<Test> Create() IUTEST_CXX_OVERRIDE
53  {
54  auto_ptr<Test> p( new Tester() );
55  return p;
56  }
57 };
58 
64 template<typename ParamType>
65 class iuParamTestFactoryBase : public iuFactoryBase
66 {
67 public:
68  iuParamTestFactoryBase() : m_param() {}
69  explicit iuParamTestFactoryBase(ParamType param) : m_param(param) {}
70 public:
71  void SetParam(ParamType param) { m_param = param; }
72  const ParamType& GetParam() const { return m_param; }
73 protected:
74  ParamType m_param;
75 };
76 
77 
83 template<class Tester>
84 class iuParamTestFactory IUTEST_CXX_FINAL : public iuParamTestFactoryBase<typename Tester::ParamType>
85 {
86  typedef typename Tester::ParamType ParamType;
87  typedef iuParamTestFactoryBase<ParamType> _Mybase;
88 public:
89  iuParamTestFactory() IUTEST_CXX_DEFAULT_FUNCTION
90  explicit iuParamTestFactory(ParamType param) : _Mybase(param) {}
91 
92 public:
93  virtual auto_ptr<Test> Create() IUTEST_CXX_OVERRIDE
94  {
95  Tester::SetParam(&this->m_param);
96  auto_ptr<Test> p( new Tester() );
97  return p;
98  }
99 };
100 
101 } // end of namespace detail
102 } // end of namespace iutest
103 
104 #endif // INCG_IRIS_IUTEST_FACTORY_HPP_9C2B4B94_95A0_479A_9C9D_43FB31845A73_
#define IUTEST_CXX_FINAL
final definition
Definition: iutest_compiler.hpp:756
#define IUTEST_CXX_OVERRIDE
override definition
Definition: iutest_compiler.hpp:747
#define IUTEST_CXX_NOEXCEPT_SPEC
noexcept specification definition
Definition: iutest_compiler.hpp:811
#define IUTEST_CXX_DEFAULT_FUNCTION
default function
Definition: iutest_compiler.hpp:494
#define IUTEST_PP_DISALLOW_COPY_AND_ASSIGN(TypeName)
コピー禁止定義
Definition: iutest_pp.hpp:31
iutest root namespace
Definition: iutest_charcode.hpp:33