|
Last change
on this file since d76c105 was d76c105, checked in by Frederik Heber <heber@…>, 15 years ago |
|
Added Prototype Factory pattern.
- the Prototype Factory basically stores Clone instead of Creator patterns in
its lookup tables to produce.
- Clone has not protected cstor/dstor but is friend with CloneTest and
PrototypeFactoryStub to grant them access.
- also these prototypes may be manipulated by befriended classes.
- added unit test and stub.
- Library version is now 3:0:0, API version is 1.0.5.
|
-
Property mode
set to
100644
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * CloneStub.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Jan 4, 2011
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef CLONESTUB_HPP_
|
|---|
| 9 | #define CLONESTUB_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | #include "Clone.hpp"
|
|---|
| 17 |
|
|---|
| 18 | struct IPrototype
|
|---|
| 19 | {
|
|---|
| 20 | virtual ~IPrototype() {};
|
|---|
| 21 | virtual void count()=0;
|
|---|
| 22 | virtual int getcount() const =0;
|
|---|
| 23 | virtual void setcount(int const _counter)=0;
|
|---|
| 24 | };
|
|---|
| 25 |
|
|---|
| 26 | class CloneTest;
|
|---|
| 27 | class PrototypeFactoryStub;
|
|---|
| 28 |
|
|---|
| 29 | template <class T>
|
|---|
| 30 | class Prototype :
|
|---|
| 31 | public IPrototype,
|
|---|
| 32 | public Clone<IPrototype>
|
|---|
| 33 | {
|
|---|
| 34 | /**
|
|---|
| 35 | * Prototype Factory is friend because it needs to access protected cstor
|
|---|
| 36 | * to instantiate prototypes.
|
|---|
| 37 | */
|
|---|
| 38 | friend class PrototypeFactoryStub;
|
|---|
| 39 |
|
|---|
| 40 | /**
|
|---|
| 41 | * Test is friend such that it can access protected cstor.
|
|---|
| 42 | */
|
|---|
| 43 | friend class CloneTest;
|
|---|
| 44 |
|
|---|
| 45 | protected:
|
|---|
| 46 | Prototype() {
|
|---|
| 47 | member.setcount(0);
|
|---|
| 48 | }
|
|---|
| 49 | ~Prototype() {};
|
|---|
| 50 |
|
|---|
| 51 | public:
|
|---|
| 52 | void count() {
|
|---|
| 53 | member.count();
|
|---|
| 54 | }
|
|---|
| 55 | int getcount() const {
|
|---|
| 56 | return member.getcount();
|
|---|
| 57 | }
|
|---|
| 58 | void setcount(int const _counter) {
|
|---|
| 59 | member.setcount(_counter);
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | IPrototype* clone() const;
|
|---|
| 63 | private:
|
|---|
| 64 | T member;
|
|---|
| 65 | };
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | #endif /* CLONESTUB_HPP_ */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.