mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
.uppdev
git-svn-id: svn://ultimatepp.org/upp/trunk@2790 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
38314e3e9f
commit
72a38659b2
3 changed files with 99 additions and 0 deletions
86
uppdev/Kpoly/Kpoly.cpp
Normal file
86
uppdev/Kpoly/Kpoly.cpp
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
//without this one beeing in namespace upp it doesnt work eaither
|
||||
//suppose because of friend DeepCopyNew not beeing placed / referenced to template definition
|
||||
NAMESPACE_UPP
|
||||
|
||||
template<class T, class B = EmptyClass>
|
||||
class Copyable : public B
|
||||
{
|
||||
public:
|
||||
virtual ~Copyable() {}
|
||||
virtual T* Copy() const { return PartialCopy(); }
|
||||
virtual T* PartialCopy() const = 0; //{ NEVER(); return NULL; }
|
||||
};
|
||||
|
||||
template<class C, class B = EmptyClass>
|
||||
class CopyableC : public Copyable<CopyableC<C,B>, B>
|
||||
{
|
||||
public:
|
||||
virtual const C& GetC() const = 0;
|
||||
virtual C& GetC() = 0;
|
||||
|
||||
operator const C&() const { return GetC(); }
|
||||
operator C&() { return GetC(); }
|
||||
};
|
||||
|
||||
template<class B, class C, class CB = EmptyClass>
|
||||
class PolyCopyableC : public B, public PolyDeepCopyNew<CopyableC<C, CB>, CopyableC<C, CB> >
|
||||
{
|
||||
public:
|
||||
virtual const C& GetC() const { return *this; }
|
||||
virtual C& GetC() { return *this; }
|
||||
};
|
||||
|
||||
END_UPP_NAMESPACE
|
||||
|
||||
//OWN CLASSES
|
||||
|
||||
//this one doesnt help
|
||||
//NAMESPACE_UPP
|
||||
|
||||
//a common base interface, that should be available after copying, (i.e Offer() )
|
||||
//is meant as an extension interface on very bottom
|
||||
//should be implemented at very top
|
||||
class CBase
|
||||
{
|
||||
public:
|
||||
virtual void Offer(int a) = 0;
|
||||
};
|
||||
|
||||
//a common base class, which should be accessible via GetC (could be i.e Ctrl)
|
||||
class Base {};
|
||||
|
||||
//a Base version (could be any Ctrl derive, i.e StaticText)
|
||||
//neither Base nor Derived are to be changed, they are foreign
|
||||
//thats why so complicated
|
||||
class Derived : public Base {};
|
||||
|
||||
//extension of the whole thing, to make everything cloneable..
|
||||
class Master : public PolyCopyableC<Derived, Base, CBase>
|
||||
{
|
||||
public:
|
||||
Master* PartialCopy() const { return new Master(); }
|
||||
virtual void Offer(int a) {}
|
||||
};
|
||||
|
||||
//END_UPP_NAMESPACE
|
||||
|
||||
//with this one both work, but i'd like to avoid that and to have it automatic in PolyCopyableC
|
||||
#if 0
|
||||
NAMESPACE_UPP
|
||||
template<>
|
||||
inline CopyableC<Base, CBase>* DeepCopyNew(const CopyableC<Base, CBase>& x) {
|
||||
return x.Copy();
|
||||
}
|
||||
END_UPP_NAMESPACE
|
||||
#endif
|
||||
|
||||
CONSOLE_APP_MAIN
|
||||
{
|
||||
Array<CopyableC<Base, CBase> > a1, a2;
|
||||
a1.Add(new Master());
|
||||
a1 <<= a2;
|
||||
}
|
||||
9
uppdev/Kpoly/Kpoly.upp
Normal file
9
uppdev/Kpoly/Kpoly.upp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
Kpoly.cpp;
|
||||
|
||||
mainconfig
|
||||
"" = "";
|
||||
|
||||
4
uppdev/Kpoly/init
Normal file
4
uppdev/Kpoly/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _Kpoly_icpp_init_stub
|
||||
#define _Kpoly_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue