00001 // +-------------------------------------------------------------------------+ 00002 // | I__n__t__e__L__i__b 0.6.10 development | 00003 // | Copyright (c) Andrey Vikt. Stolyarov <crocodil_AT_croco.net> 2000-2007. | 00004 // | | 00005 // | This is free software. The library part is available under | 00006 // | GNU LESSER GENERAL PUBLIC LICENSE v.2.1. | 00007 // | GNU LGPL v2.1 is found in docs/gnu_gpl2.txt, or at http://www.gnu.org | 00008 // | Please see also docs/readme.txt and visit http://www.intelib.org | 00009 // | | 00010 // | !!! THERE IS NO WARRANTY OF ANY KIND, NEITHER EXPRESSED NOR IMPLIED !!! | 00011 // +-------------------------------------------------------------------------+ 00012 00013 00014 00015 00024 #ifndef INTELIB_GENSREF_HPP_SENTRY 00025 #define INTELIB_GENSREF_HPP_SENTRY 00026 00027 #include "iexcept.hpp" 00028 #include "sexpress.hpp" 00029 00031 00035 template<class Tp, class X_wrongtype> 00036 class GenericSReference : public SReference { 00037 public: 00039 GenericSReference() : SReference() {} 00041 GenericSReference(const Tp *ts) 00042 : SReference((const SExpression*)ts) {} 00044 GenericSReference(const GenericSReference<Tp, X_wrongtype> &other) 00045 : SReference(other) {} 00047 00053 GenericSReference(const SReference &other, bool ignore_type = false) 00054 : SReference(other) 00055 { 00056 if(!ignore_type && other.GetPtr() && 00057 !other->TermType().IsSubtypeOf(Tp::TypeId)) 00058 { 00059 throw X_wrongtype(other); 00060 } 00061 } 00062 ~GenericSReference() {} 00063 00065 Tp* GetPtr() const 00066 { return static_cast<Tp*>(SReference::GetPtr()); } 00067 00069 Tp& operator*() const { return *GetPtr(); } 00071 Tp* operator->() const { return GetPtr(); } 00073 GenericSReference<Tp,X_wrongtype>& 00074 operator =(const GenericSReference<Tp,X_wrongtype>& ref) 00075 { SReference::operator=(ref); return *this; } 00077 GenericSReference<Tp,X_wrongtype>& operator =(Tp *lt) 00078 { SReference::operator=(lt); return *this; } 00080 GenericSReference<Tp,X_wrongtype>& operator =(Tp <) 00081 { SReference::operator=(lt); return *this; } 00082 private: 00083 // made private to prevent the user from mistakes and 00084 // to make sure this always points to an object of Tp. 00085 void operator =(const SReference& ref) {} 00086 }; 00087 00088 00089 #endif // sentry