X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fbases%2FAutoRefCnt.hxx;h=9511aef588ced85d8585ea1e288234c471c61a0a;hb=ae15468afa2938df5524992e79eca3d661e1b92e;hp=003a73e82a6d4726ee43dbbe95e55cf5eb123d9d;hpb=17b2be6fdceef9981751309428fbfe58f155c48e;p=modules%2Fyacs.git diff --git a/src/bases/AutoRefCnt.hxx b/src/bases/AutoRefCnt.hxx index 003a73e82..9511aef58 100644 --- a/src/bases/AutoRefCnt.hxx +++ b/src/bases/AutoRefCnt.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2006-2016 CEA/DEN, EDF R&D +// Copyright (C) 2006-2019 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -33,6 +33,9 @@ namespace YACS AutoRefCnt(const AutoRefCnt& other):_ptr(0) { referPtr(other._ptr); } AutoRefCnt(T *ptr=0):_ptr(ptr) { } ~AutoRefCnt() { destroyPtr(); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } + void nullify() { destroyPtr(); _ptr=0; } bool operator==(const AutoRefCnt& other) const { return _ptr==other._ptr; } bool operator==(const T *other) const { return _ptr==other; } AutoRefCnt &operator=(const AutoRefCnt& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; } @@ -44,6 +47,7 @@ namespace YACS operator T *() { return _ptr; } operator const T *() const { return _ptr; } T *retn() { if(_ptr) _ptr->incrRef(); return _ptr; } + void takeRef(T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; if(_ptr) _ptr->incrRef(); } } private: void referPtr(T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } void destroyPtr() { if(_ptr) _ptr->decrRef(); } @@ -51,6 +55,32 @@ namespace YACS T *_ptr; }; + template + class AutoConstRefCnt + { + public: + AutoConstRefCnt(const AutoConstRefCnt& other):_ptr(0) { referPtr(other._ptr); } + AutoConstRefCnt(const T *ptr=0):_ptr(ptr) { } + ~AutoConstRefCnt() { destroyPtr(); } + bool isNull() const { return _ptr==0; } + bool isNotNull() const { return !isNull(); } + void nullify() { destroyPtr(); _ptr=0; } + bool operator==(const AutoConstRefCnt& other) const { return _ptr==other._ptr; } + bool operator==(const T *other) const { return _ptr==other; } + AutoConstRefCnt &operator=(const AutoConstRefCnt& other) { if(_ptr!=other._ptr) { destroyPtr(); referPtr(other._ptr); } return *this; } + AutoConstRefCnt &operator=(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; } return *this; } + const T *operator->() const { return _ptr; } + const T& operator*() const { return *_ptr; } + operator const T *() const { return _ptr; } + const T *retn() { if(_ptr) _ptr->incrRef(); return _ptr; } + void takeRef(const T *ptr) { if(_ptr!=ptr) { destroyPtr(); _ptr=ptr; if(_ptr) _ptr->incrRef(); } } + private: + void referPtr(const T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); } + void destroyPtr() { if(_ptr) _ptr->decrRef(); } + private: + const T *_ptr; + }; + template typename YACS::BASES::AutoRefCnt DynamicCast(typename YACS::BASES::AutoRefCnt& autoSubPtr) throw() {