-// Copyright (C) 2007-2012 CEA/DEN, EDF R&D
+// Copyright (C) 2007-2014 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
// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+// Author : Anthony Geay (CEA/DEN)
#ifndef __PARAMEDMEM_MEDCOUPLINGAUTOREFCOUNTOBJECTPTR_HXX__
#define __PARAMEDMEM_MEDCOUPLINGAUTOREFCOUNTOBJECTPTR_HXX__
#include "MEDCouplingRefCountObject.hxx"
+#include "InterpKernelException.hxx"
namespace ParaMEDMEM
{
const T& operator*() const { return *_ptr; }
operator T *() { return _ptr; }
operator const T *() const { return _ptr; }
+ T *retn() { if(_ptr) _ptr->incrRef(); return _ptr; }
private:
void referPtr(T *ptr) { _ptr=ptr; if(_ptr) _ptr->incrRef(); }
void destroyPtr() { if(_ptr) _ptr->decrRef(); }
private:
T *_ptr;
};
+
+ template<class T, class U>
+ typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<U> DynamicCast(typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<T>& autoSubPtr) throw()
+ {
+ T *subPtr(autoSubPtr);
+ U *ptr(dynamic_cast<U *>(subPtr));
+ typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<U> ret(ptr);
+ if(ptr)
+ ptr->incrRef();
+ return ret;
+ }
+
+ template<class T, class U>
+ typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<U> DynamicCastSafe(typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<T>& autoSubPtr)
+ {
+ T *subPtr(autoSubPtr);
+ U *ptr(dynamic_cast<U *>(subPtr));
+ if(subPtr && !ptr)
+ throw INTERP_KERNEL::Exception("DynamicCastSafe : U is not a subtype of T !");
+ typename ParaMEDMEM::MEDCouplingAutoRefCountObjectPtr<U> ret(ptr);
+ if(ptr)
+ ptr->incrRef();
+ return ret;
+ }
}
#endif