/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 1.3.38
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

namespace BerkeleyDB.Internal {

using System;
using System.Runtime.InteropServices;

internal class DBC : IDisposable {
  private HandleRef swigCPtr;
  protected bool swigCMemOwn;

  internal DBC(IntPtr cPtr, bool cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = new HandleRef(this, cPtr);
  }

  internal static HandleRef getCPtr(DBC obj) {
    return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
  }

  ~DBC() {
    Dispose();
  }

  public virtual void Dispose() {
    lock(this) {
      if(swigCPtr.Handle != IntPtr.Zero && swigCMemOwn) {
        swigCMemOwn = false;
        libdb_csharpPINVOKE.delete_DBC(swigCPtr);
      }
      swigCPtr = new HandleRef(null, IntPtr.Zero);
      GC.SuppressFinalize(this);
    }
  }

	internal DBC dup(uint flags) {
		int err = 0;
		DBC ret = dup(flags, ref err);
		DatabaseException.ThrowException(err);
		return ret;
	}

  internal int close() {
		int ret = libdb_csharpPINVOKE.DBC_close(swigCPtr);
		if (ret == 0)
			/* Close is a db handle destructor.  Reflect that in the wrapper class. */
			swigCPtr = new HandleRef(null, IntPtr.Zero);
		else
			DatabaseException.ThrowException(ret);
		return ret;
}

  internal int cmp(DBC other_dbc, ref int result, uint flags) {
		int ret;
		ret = libdb_csharpPINVOKE.DBC_cmp(swigCPtr, DBC.getCPtr(other_dbc), ref result, flags);
		DatabaseException.ThrowException(ret);
		return ret;
}

  internal int count(ref uint cnt, uint flags) {
		int ret;
		ret = libdb_csharpPINVOKE.DBC_count(swigCPtr, ref cnt, flags);
		DatabaseException.ThrowException(ret);
		return ret;
}

  internal int del(uint flags) {
		int ret;
		ret = libdb_csharpPINVOKE.DBC_del(swigCPtr, flags);
		DatabaseException.ThrowException(ret);
		return ret;
}

  private DBC dup(uint flags, ref int err) {
    IntPtr cPtr = libdb_csharpPINVOKE.DBC_dup(swigCPtr, flags, ref err);
    DBC ret = (cPtr == IntPtr.Zero) ? null : new DBC(cPtr, false);
    return ret;
  }

  internal int get(DatabaseEntry key, DatabaseEntry data, uint flags) {
    try {
		int ret;
		ret = libdb_csharpPINVOKE.DBC_get(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(key)), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags);
		DatabaseException.ThrowException(ret);
		return ret;
} finally {
      GC.KeepAlive(key);
      GC.KeepAlive(data);
    }
  }

  internal int pget(DatabaseEntry key, DatabaseEntry pkey, DatabaseEntry data, uint flags) {
    try {
		int ret;
		ret = libdb_csharpPINVOKE.DBC_pget(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(key)), DBT.getCPtr(DatabaseEntry.getDBT(pkey)), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags);
		DatabaseException.ThrowException(ret);
		return ret;
} finally {
      GC.KeepAlive(key);
      GC.KeepAlive(pkey);
      GC.KeepAlive(data);
    }
  }

  internal int put(DatabaseEntry key, DatabaseEntry data, uint flags) {
    try {
		int ret;
		ret = libdb_csharpPINVOKE.DBC_put(swigCPtr, DBT.getCPtr(DatabaseEntry.getDBT(key)), DBT.getCPtr(DatabaseEntry.getDBT(data)), flags);
		DatabaseException.ThrowException(ret);
		return ret;
} finally {
      GC.KeepAlive(key);
      GC.KeepAlive(data);
    }
  }

  internal int set_priority(uint priority) {
		int ret;
		ret = libdb_csharpPINVOKE.DBC_set_priority(swigCPtr, priority);
		DatabaseException.ThrowException(ret);
		return ret;
}

  internal DBC() : this(libdb_csharpPINVOKE.new_DBC(), true) {
  }

}

}