00001
00002
00003
00004
00005
00006
00007
00008 #ifndef _SK_UTIL_SLOT_POLICY_STORING_HXX_
00009 #define _SK_UTIL_SLOT_POLICY_STORING_HXX_
00010
00011 #include <sk/util/slot/Mixable.hxx>
00012 #include <sk/util/MissingResourceException.h>
00013
00014 namespace sk {
00015 namespace util {
00016 namespace slot {
00017 namespace policy {
00018 template<typename T, typename SlotMixin = slot::mixin::None>
00019 class Storing
00020 {
00021 protected:
00022 Storing()
00023 : _slot(0) {}
00024
00025 void setSlot(slot::Mixable<T, SlotMixin>* slot) {
00026 _slot = slot;
00027 }
00028
00029 void setObject(T& object) {
00030 clearSlot();
00031 setSlot(new slot::Reference<T, SlotMixin>(object));
00032 }
00033
00034 void setObject(T* object) {
00035 clearSlot();
00036 if(object != 0) {
00037 setSlot(new slot::Pointer<T, SlotMixin>(object));
00038 }
00039 }
00040
00041 bool hasSlot() const {
00042 return _slot != 0;
00043 }
00044
00045 static bool hasSlot(const Storing<T, SlotMixin>& other) {
00046 return other.hasSlot();
00047 }
00048
00049 void clearSlot() {
00050 delete _slot;
00051 _slot = 0;
00052 }
00053
00054 slot::Mixable<T, SlotMixin>& getSlot() const {
00055 if(hasSlot() == false) {
00056 throw MissingResourceException("sk::util::slot::policy::Storing#getSlot()");
00057 }
00058 return *_slot;
00059 }
00060
00061 static slot::Mixable<T, SlotMixin>& getSlot(const Storing<T, SlotMixin>& other) {
00062 return other.getSlot();
00063 }
00064
00065 private:
00066 Storing(const Storing<T, SlotMixin>& other);
00067 Storing<T, SlotMixin>& operator = (const Storing<T, SlotMixin>& other);
00068
00069 slot::Mixable<T, SlotMixin>* _slot;
00070 };
00071 }
00072 }
00073 }
00074 }
00075
00076 #endif