source: src/Patterns/unittests/stubs/CloneStub.hpp@ 1afcbe

Last change on this file since 1afcbe was 1afcbe, checked in by Frederik Heber <heber@…>, 15 years ago

Added Clone pattern.

  • Clone is necessary for having prototypes, i.e. it defines an interface class that has a virtual * clone() const function that each derived type has to implement.
  • Added unit test.
  • made CommonStub a bit cleaner.
  • updated documentation fo Factory and FactoryTypeList
  • Library version is now 2:2:0, API is 1.0.4.
  • Property mode set to 100644
File size: 822 bytes
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
18struct 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
26template <class T>
27class Prototype :
28 public IPrototype,
29 public Clone<IPrototype>
30{
31public:
32 Prototype() {
33 member.setcount(0);
34 }
35 ~Prototype() {};
36
37 void count() {
38 member.count();
39 }
40 int getcount() const {
41 return member.getcount();
42 }
43 void setcount(int const _counter) {
44 member.setcount(_counter);
45 }
46
47 IPrototype* clone() const;
48private:
49 T member;
50};
51
52
53#endif /* CLONESTUB_HPP_ */
Note: See TracBrowser for help on using the repository browser.