Classdesc 3.44
polyBase.h
1/*
2 @copyright Russell Standish 2000-2013
3 @author Russell Standish
4 This file is part of Classdesc
5
6 Open source licensed under the MIT license. See LICENSE for details.
7*/
8
9#ifndef CLASSDESC_POLYBASE_H
10#define CLASSDESC_POLYBASE_H
11#include <classdesc.h>
12
13namespace classdesc
14{
17 struct PolyBaseMarker {};
18
20 template <class T>
21 struct PolyBase: public PolyBaseMarker
22 {
23 typedef T Type;
24 virtual Type type() const=0;
25 virtual PolyBase* clone() const=0;
26#if defined(__cplusplus) && __cplusplus>=201103L
27 typedef std::unique_ptr<PolyBase> AutoPtr;
28#else
29 typedef std::auto_ptr<PolyBase> AutoPtr;
30#endif
33 template <class U>
34 U* cloneT() const {
35 AutoPtr p(clone());
36 U* t=dynamic_cast<U*>(p.get());
37 if (t)
38 p.release();
39 return t;
40 }
41 virtual ~PolyBase() {}
42 };
43
44
47
77
78 template <class T, class Base>
79 struct Poly: virtual public Base
80 {
82 Poly* clone() const {return new T(*static_cast<const T*>(this));}
83 };
84}
85
86#endif
Contains definitions related to classdesc functionality.
Definition polyBase.h:17
base class for polymorphic types. T is a type enumerator class
Definition polyBase.h:22
U * cloneT() const
Definition polyBase.h:34
Definition polyBase.h:80
Poly * clone() const
clone has to return a Poly* to satisfy covariance
Definition polyBase.h:82