/* * The contents of this file are subject to the Initial * Developer's Public License Version 1.0 (the "License"); * you may not use this file except in compliance with the * License. You may obtain a copy of the License at * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. * * Software distributed under the License is distributed AS IS, * WITHOUT WARRANTY OF ANY KIND, either express or implied. * See the License for the specific language governing rights * and limitations under the License. * * The Original Code was created by Adriano dos Santos Fernandes * for the Firebird Open Source RDBMS project. * * Copyright (c) 2015 Adriano dos Santos Fernandes * and all contributors signed below. * * All Rights Reserved. * Contributor(s): ______________________________________. */ //// DOC NOTE This is the basic stuff from UdrCppExample.h - seems to be declared in all UDR libraries #ifndef UDR_CPP_TEMPLATES_H #define UDR_CPP_TEMPLATES_H #define FB_UDR_STATUS_TYPE ::Firebird::ThrowStatusWrapper #include "ibase.h" #include "firebird/UdrCppEngine.h" //#include //#include namespace { template class AutoReleaseClear { public: static void clear(T* ptr) { if (ptr) ptr->release(); } }; template class AutoDisposeClear { public: static void clear(T* ptr) { if (ptr) ptr->dispose(); } }; template class AutoDeleteClear { public: static void clear(T* ptr) { delete ptr; } }; template class AutoArrayDeleteClear { public: static void clear(T* ptr) { delete [] ptr; } }; template class AutoImpl { public: AutoImpl(T* aPtr = NULL) : ptr(aPtr) { } ~AutoImpl() { Clear::clear(ptr); } AutoImpl& operator =(T* aPtr) { Clear::clear(ptr); ptr = aPtr; return *this; } operator T*() { return ptr; } operator const T*() const { return ptr; } bool operator !() const { return !ptr; } bool hasData() const { return ptr != NULL; } T* operator ->() { return ptr; } T* release() { T* tmp = ptr; ptr = NULL; return tmp; } void reset(T* aPtr = NULL) { if (aPtr != ptr) { Clear::clear(ptr); ptr = aPtr; } } private: // not implemented AutoImpl(AutoImpl&); void operator =(AutoImpl&); private: T* ptr; }; template class AutoDispose : public AutoImpl > { public: AutoDispose(T* ptr = NULL) : AutoImpl >(ptr) { } }; template class AutoRelease : public AutoImpl > { public: AutoRelease(T* ptr = NULL) : AutoImpl >(ptr) { } }; template class AutoDelete : public AutoImpl > { public: AutoDelete(T* ptr = NULL) : AutoImpl >(ptr) { } }; template class AutoArrayDelete : public AutoImpl > { public: AutoArrayDelete(T* ptr = NULL) : AutoImpl >(ptr) { } }; } #endif // MY_FIRST_UDR_KIT_H