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 NEW_POLY_H
10 #define NEW_POLY_H
11 #include <classdesc.h>
12 
13 namespace 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
31  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 
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 // template <class T> struct tn<classdesc::PolyBase<T> >
86 // {
87 // static std::string name()
88 // {return "classdesc::PolyBase<"+typeName<T>()+">";}
89 // };
90 // template <class T, class Base> struct tn<classdesc::Poly<T,Base> >
91 // {
92 // static std::string name()
93 // {return "classdesc::Poly<"+typeName<T>()+","+typeName<Base>()+">";}
94 // };
95 
96 
97 }
98 
99 #include "polyBase.cd"
100 #endif
Poly * clone() const
clone has to return a Poly* to satisfy covariance
Definition: polyBase.h:82
U * cloneT() const
Definition: polyBase.h:34
Definition: polyBase.h:79
Definition: polyBase.h:17
base class for polymorphic types. T is a type enumerator class
Definition: polyBase.h:21
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514