From 8af67009ee35a348d3be3bead6fc76b48e368566 Mon Sep 17 00:00:00 2001 From: kohait Date: Thu, 30 Sep 2010 09:31:09 +0000 Subject: [PATCH] bazaar: CMeter: MinMax double Dispatcher: beauty Gen: cleanup and Copyable interfaces, examples to come git-svn-id: svn://ultimatepp.org/upp/trunk@2730 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/CMeter/CMeter.h | 1 - bazaar/Dispatcher/Dispatcher.cpp | 2 +- bazaar/Dispatcher/Dispatcher.h | 3 ++ bazaar/Dispatcher/Dispatcher.hpp | 4 +- bazaar/Gen/Gen.h | 68 ++++++++++++++++---------------- 5 files changed, 41 insertions(+), 37 deletions(-) diff --git a/bazaar/CMeter/CMeter.h b/bazaar/CMeter/CMeter.h index 42bf1171a..d83917a10 100644 --- a/bazaar/CMeter/CMeter.h +++ b/bazaar/CMeter/CMeter.h @@ -63,7 +63,6 @@ public: virtual void SetData(const Value& data) { Set(data); } Value GetMin() const { return Min(); } Value GetMax() const { return Max(); } - CMeter & MinMax(const Value& min = 0.0, const Value& max = 1.0) { return MinMax(min, max); } CMeter & Set(double val); double Get() const { return val; } diff --git a/bazaar/Dispatcher/Dispatcher.cpp b/bazaar/Dispatcher/Dispatcher.cpp index a2e7f4a82..e8289e5e2 100644 --- a/bazaar/Dispatcher/Dispatcher.cpp +++ b/bazaar/Dispatcher/Dispatcher.cpp @@ -34,7 +34,7 @@ Dispatcher0::~Dispatcher0() void Dispatcher0::DoDispatch() const { - if(!EnableOption<>::IsEnabled()) return; + if(!R::IsEnabled()) return; for(int i = 0; i < dests.GetCount(); i++) { const Callback & dest = dests.operator[](i); diff --git a/bazaar/Dispatcher/Dispatcher.h b/bazaar/Dispatcher/Dispatcher.h index ef950d5de..519f76f91 100644 --- a/bazaar/Dispatcher/Dispatcher.h +++ b/bazaar/Dispatcher/Dispatcher.h @@ -43,6 +43,7 @@ class Dispatcher { public: typedef Dispatcher CLASSNAME; + typedef EnableOption<> R; Dispatcher(); virtual ~Dispatcher(); @@ -90,6 +91,7 @@ class DispatcherCB { public: typedef DispatcherCB CLASSNAME; + typedef EnableOption<> R; DispatcherCB(); virtual ~DispatcherCB(); @@ -133,6 +135,7 @@ class Dispatcher0 { public: typedef Dispatcher0 CLASSNAME; + typedef EnableOption<> R; Dispatcher0(); virtual ~Dispatcher0(); diff --git a/bazaar/Dispatcher/Dispatcher.hpp b/bazaar/Dispatcher/Dispatcher.hpp index cf5c97bb9..f7c1c9da0 100644 --- a/bazaar/Dispatcher/Dispatcher.hpp +++ b/bazaar/Dispatcher/Dispatcher.hpp @@ -52,7 +52,7 @@ Dispatcher::~Dispatcher() template void Dispatcher::DoDispatch(const T & o) const { - if(!EnableOption<>::IsEnabled()) return; + if(!R::IsEnabled()) return; for(int i = 0; i < dests.GetCount(); i++) { Dispatchable * dest = dests.operator[](i); @@ -164,7 +164,7 @@ DispatcherCB::~DispatcherCB() template void DispatcherCB::DoDispatch(const T & o) const { - if(!EnableOption<>::IsEnabled()) return; + if(!R::IsEnabled()) return; for(int i = 0; i < dests.GetCount(); i++) { const Callback1 & dest = dests.operator[](i); diff --git a/bazaar/Gen/Gen.h b/bazaar/Gen/Gen.h index 2035eac15..fc4747fd4 100644 --- a/bazaar/Gen/Gen.h +++ b/bazaar/Gen/Gen.h @@ -40,6 +40,7 @@ public: virtual ~GetSetData() {} //might be used as base interface virtual T GetData() const = 0; virtual void SetData(const T& _v) = 0; + virtual T& GetRef() = 0; virtual const T& GetRef() const = 0; T operator~() const { return GetData(); } const T& operator<<=(const T& v) { SetData(v); return v; } @@ -53,6 +54,7 @@ public: virtual ~GetSetDataMulti() {} //might be used as base interface virtual T GetDataMulti(int i) const = 0; virtual void SetDataMulti(int i, const T& _v) = 0; + virtual T& GetRefMulti(int i) = 0; virtual const T& GetRefMulti(int i) const = 0; T operator~() const { return GetDataMulti(0); } const T& operator<<=(const T& v) { SetDataMulti(0, v); return v; } @@ -64,10 +66,14 @@ class MinMaxOption : public B public: MinMaxOption() : nn(false) {} MinMaxOption(const T & min, const T& max) : min(min), max(max), nn(false) {} - virtual MinMaxOption& Min(const T& _min) { min = _min; return *this; } + virtual MinMaxOption& SetMin(const T& _min){ min = _min; return *this; } + inline MinMaxOption& Min(const T& _min) { return SetMin(_min); } T GetMin() const { return min; } - virtual MinMaxOption& Max(const T& _max) { max = _max; return *this; } + inline T Min() const { return GetMin(); } + virtual MinMaxOption& SetMax(const T& _max){ max = _max; return *this; } + inline MinMaxOption& Max(const T& _max) { return SetMax(_max); } T GetMax() const { return max; } + inline T Max() const { return GetMax(); } virtual MinMaxOption& NotNull(bool _nn = true) { nn = _nn; return *this; } T IsNotNull() const { return nn; } protected: @@ -75,8 +81,6 @@ protected: bool nn; }; -#if 0 - //copyable interface, implementing the Copy function, used by PolyDeepCopyNew template @@ -84,53 +88,43 @@ class Copyable : public B { public: virtual ~Copyable() {} - virtual T* Copy() const { return new T(); } - virtual T* PartialCopy() const { return new T(); } + virtual T* Copy() const { return PartialCopy(); } + virtual T* PartialCopy() const = 0; //{ NEVER(); return NULL; } }; -//this is a nice helper, menat to be used like i.e. PolyCopying -//assigning Copy'ed instances to PolyCopying* with a cast, as Ctrl is direct base class of EditCtrl -template -class PolyCopying : public Copyable< PolyCopying, PolyDeepCopyNew, T> > {}; - -//USE: -//PolyCopying a; -//PolyCopying* p = (PolyCopying*)a.Copy; -//p->SizePos(); //< -class CopyableC +template +class CopyableC : public Copyable, B> { public: - virtual ~CopyableC() {} - virtual CopyableC* Copy() const = 0; - virtual CopyableC* PartialCopy() const = 0; - virtual const C& GetC() const = 0; virtual C& GetC() = 0; - operator const C&() const {return GetC(); } - operator C&() {return GetC(); } + operator const C&() const { return GetC(); } + operator C&() { return GetC(); } }; //provides the implementation of Copy, which is used by PolyDeepNew //and implements the base class accessors. //T is the derived type, i.e. EditInt, C is common base class, i.e. Ctrl - -template -class PolyCopyingC : public PolyDeepCopyNew, T>, public CopyableC +//forward another baseclass CB to extend CopyableC interface +template +class PolyCopyableC : public PolyDeepCopyNew, public CopyableC { public: - virtual PolyCopyingC* Copy() const { return new PolyCopyingC(); } - virtual PolyCopyingC* PartialCopy() const { return new PolyCopyingC(); } + //works + //virtual PolyCopyableC* PartialCopy() const { return new T(); } + + //doesnt work, signature differences somehow..T is not yet part of derive hiearchy at this point.. + //so compiler does not recognize it legitime override. thus it moves to derived + //virtual T* PartialCopy() const { return new T(); } + + using CopyableC::Copy; + using CopyableC::PartialCopy; + virtual const C& GetC() const { return *this; } virtual C& GetC() { return *this; } }; @@ -142,6 +136,14 @@ public: //THIS ONE WORKS //by providing additional information about the common base class //with template specialization can be defined what is copied + +template +class PolyCopyingC : public PolyCopyableC,B,C,CB> +{ +public: + virtual PolyCopyingC* PartialCopy() const { return new PolyCopyingC(); } +}; + #endif //declares a class Serializable for Stream