|
Last change
on this file since 746ff1 was 746ff1, checked in by Frederik Heber <heber@…>, 15 years ago |
|
Added Creator and Factory pattern.
- unittests added.
- new subfolder stubs that contains stubs for Creator and Factory.
- the only preprocessor stuff is in Factory_impl.hpp.
- FactoryTypeList.hpp is necessary as long as no variadic template argument
lists are possible.
- library version is 2:0:0, API version is 1.0.2.
|
-
Property mode
set to
100644
|
|
File size:
989 bytes
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * CreatorStub.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jan 4, 2011
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef CREATORSTUB_HPP_
|
|---|
| 9 | #define CREATORSTUB_HPP_
|
|---|
| 10 |
|
|---|
| 11 | #include <typeinfo>
|
|---|
| 12 |
|
|---|
| 13 | #include "Creator.hpp"
|
|---|
| 14 |
|
|---|
| 15 | class ICreatorStub {
|
|---|
| 16 | public:
|
|---|
| 17 | virtual ~ICreatorStub() {};
|
|---|
| 18 | virtual void count() = 0;
|
|---|
| 19 | virtual int getcount() = 0;
|
|---|
| 20 | virtual std::string name() = 0;
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | namespace teststubs {
|
|---|
| 24 | class Aclass
|
|---|
| 25 | {
|
|---|
| 26 | public:
|
|---|
| 27 | Aclass() :
|
|---|
| 28 | counter(0)
|
|---|
| 29 | {};
|
|---|
| 30 | ~Aclass() {};
|
|---|
| 31 |
|
|---|
| 32 | int counter;
|
|---|
| 33 | };
|
|---|
| 34 |
|
|---|
| 35 | class Bclass
|
|---|
| 36 | {
|
|---|
| 37 | public:
|
|---|
| 38 | Bclass() :
|
|---|
| 39 | counter(256)
|
|---|
| 40 | {};
|
|---|
| 41 | ~Bclass() {};
|
|---|
| 42 |
|
|---|
| 43 | int counter;
|
|---|
| 44 | };
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | template <class T>
|
|---|
| 49 | class CreatorStub : public ICreatorStub, public Creator<ICreatorStub, CreatorStub<T> >
|
|---|
| 50 | {
|
|---|
| 51 | public:
|
|---|
| 52 | CreatorStub() {};
|
|---|
| 53 | virtual ~CreatorStub() {};
|
|---|
| 54 |
|
|---|
| 55 | virtual void count() {
|
|---|
| 56 | member.counter++;
|
|---|
| 57 | }
|
|---|
| 58 | virtual int getcount() {
|
|---|
| 59 | return member.counter;
|
|---|
| 60 | }
|
|---|
| 61 | virtual std::string name() {
|
|---|
| 62 | return std::string(typeid(T).name());
|
|---|
| 63 | }
|
|---|
| 64 | private:
|
|---|
| 65 | T member;
|
|---|
| 66 | };
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | #endif /* CREATORSTUB_HPP_ */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.