diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-09-05 11:58:14 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-09-05 11:58:14 +0200 |
commit | d6518580059c6a0d34d7a1683fabc3bfcc4b5e27 (patch) | |
tree | 1d0cb1b8fd8f7fb98b52a8433c5cc4d1ef4383f1 /odb/oracle/auto-descriptor.hxx | |
parent | 83d687748558cb4f138cecfff2ccbe5cbbc0d761 (diff) |
Add RAII handle management for OCI handles and descriptors
Diffstat (limited to 'odb/oracle/auto-descriptor.hxx')
-rw-r--r-- | odb/oracle/auto-descriptor.hxx | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/odb/oracle/auto-descriptor.hxx b/odb/oracle/auto-descriptor.hxx new file mode 100644 index 0000000..9e3172c --- /dev/null +++ b/odb/oracle/auto-descriptor.hxx @@ -0,0 +1,95 @@ +// file : odb/oracle/auto-descriptor.hxx +// author : Constantin Michael <constantin@codesynthesis.com> +// copyright : Copyright (c) 2005-2011 Code Synthesis Tools CC +// license : ODB NCUEL; see accompanying LICENSE file + +#ifndef ODB_ORACLE_AUTO_DESCRIPTOR_HXX +#define ODB_ORACLE_AUTO_DESCRIPTOR_HXX + +#include <odb/pre.hxx> + +#include <odb/oracle/version.hxx> +#include <odb/oracle/oracle-fwd.hxx> + +#include <odb/oracle/details/export.hxx> + +namespace odb +{ + namespace oracle + { + // + // descriptor_type_traits + // + + template <typename D> + struct descriptor_type_traits; + + template <> + struct descriptor_type_traits<OCIParam> + { static const ub4 dtype; }; + + // + // descriptor_traits + // + + LIBODB_ORACLE_EXPORT void + oci_descriptor_free (void* descriptor, ub4 type); + + template <typename D> + struct descriptor_traits + { + static void + release (OCIParam* d) + { + oci_descriptor_free (d, descriptor_type_traits<D>::dtype); + } + }; + + template <typename D> + class auto_descriptor + { + public: + auto_descriptor (D* d = 0) + : d_ (d) + { + } + + ~auto_descriptor () + { + if (d_ != 0) + descriptor_traits<D>::release (d_); + } + + operator D* () + { + return d_; + } + + D* + get () + { + return d_; + } + + void + reset (D* d = 0) + { + if (d_ != 0) + descriptor_traits<D>::release (d_); + + d_ = d; + } + + private: + auto_descriptor (const auto_descriptor&); + auto_descriptor& operator= (const auto_descriptor&); + + private: + D* d_; + }; + } +} + +#include <odb/post.hxx> + +#endif // ODB_ORACLE_AUTO_DESCRIPTOR_HXX |