Initial Commit

This commit is contained in:
Paul Reeves 2023-01-19 16:52:45 +01:00
parent 68b3cf286d
commit a340f4e1da
2 changed files with 205 additions and 0 deletions

33
sql/MyFirstUDRKit.sql Normal file
View File

@ -0,0 +1,33 @@
set term ^;
create or alter package my_first_udr_kit
as
begin
-- Add Procedure and Function Headers here
-- eg:
/*
procedure split_boolean (
in_txt blob sub_type text,
in_separator varchar(31))
returns (
out_boolean boolean);
*/
end ^
recreate package body my_first_udr_kit
as
begin
procedure split_boolean (
in_txt blob sub_type text,
in_separator varchar(31))
returns (
out_boolean boolean)
external name 'my_first_udr_kit!split' engine udr;
end ^
set term ;^

172
src/MyFirstUDFKit.h Normal file
View File

@ -0,0 +1,172 @@
/*
* License Boiler plate here
*/
#ifndef MY_FIRST_UDR_KIT_H
#define MY_FIRST_UDR_KIT_H
#define FB_UDR_STATUS_TYPE ::Firebird::ThrowStatusWrapper
#include "ibase.h"
#include "firebird/UdrCppEngine.h"
#include <assert.h>
#include <stdio.h>
// This is the basic stuff from UdrCppExample.h - seems to be declared in all UDR libraries
namespace
{
template <typename T>
class AutoReleaseClear
{
public:
static void clear(T* ptr)
{
if (ptr)
ptr->release();
}
};
template <typename T>
class AutoDisposeClear
{
public:
static void clear(T* ptr)
{
if (ptr)
ptr->dispose();
}
};
template <typename T>
class AutoDeleteClear
{
public:
static void clear(T* ptr)
{
delete ptr;
}
};
template <typename T>
class AutoArrayDeleteClear
{
public:
static void clear(T* ptr)
{
delete [] ptr;
}
};
template <typename T, typename Clear>
class AutoImpl
{
public:
AutoImpl<T, Clear>(T* aPtr = NULL)
: ptr(aPtr)
{
}
~AutoImpl()
{
Clear::clear(ptr);
}
AutoImpl<T, Clear>& 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<T, Clear>(AutoImpl<T, Clear>&);
void operator =(AutoImpl<T, Clear>&);
private:
T* ptr;
};
template <typename T> class AutoDispose : public AutoImpl<T, AutoDisposeClear<T> >
{
public:
AutoDispose(T* ptr = NULL)
: AutoImpl<T, AutoDisposeClear<T> >(ptr)
{
}
};
template <typename T> class AutoRelease : public AutoImpl<T, AutoReleaseClear<T> >
{
public:
AutoRelease(T* ptr = NULL)
: AutoImpl<T, AutoReleaseClear<T> >(ptr)
{
}
};
template <typename T> class AutoDelete : public AutoImpl<T, AutoDeleteClear<T> >
{
public:
AutoDelete(T* ptr = NULL)
: AutoImpl<T, AutoDeleteClear<T> >(ptr)
{
}
};
template <typename T> class AutoArrayDelete : public AutoImpl<T, AutoArrayDeleteClear<T> >
{
public:
AutoArrayDelete(T* ptr = NULL)
: AutoImpl<T, AutoArrayDeleteClear<T> >(ptr)
{
}
};
}
#endif // MY_FIRST_UDR_KIT_H