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

namespace clucene.net {

using System;
using System.Runtime.InteropServices;

public class SegmentMerger : IDisposable {
  private HandleRef swigCPtr;
  protected bool swigCMemOwn;

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

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

  ~SegmentMerger() {
    Dispose();
  }

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

  public SegmentMerger(Directory dir, string name, bool compoundFile) : this(libCLcsharpPINVOKE.new_SegmentMerger(Directory.getCPtr(dir), name, compoundFile), true) {
    if (libCLcsharpPINVOKE.SWIGPendingException.Pending) throw libCLcsharpPINVOKE.SWIGPendingException.Retrieve();
  }

  public void add(SegmentReader reader) {
    libCLcsharpPINVOKE.SegmentMerger_add(swigCPtr, SegmentReader.getCPtr(reader));
    if (libCLcsharpPINVOKE.SWIGPendingException.Pending) throw libCLcsharpPINVOKE.SWIGPendingException.Retrieve();
  }

  public IndexReader segmentReader(int i) {
    IntPtr cPtr = libCLcsharpPINVOKE.SegmentMerger_segmentReader(swigCPtr, i);
    IndexReader ret = (cPtr == IntPtr.Zero) ? null : new IndexReader(cPtr, false);
    if (libCLcsharpPINVOKE.SWIGPendingException.Pending) throw libCLcsharpPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public int merge() {
    int ret = libCLcsharpPINVOKE.SegmentMerger_merge(swigCPtr);
    if (libCLcsharpPINVOKE.SWIGPendingException.Pending) throw libCLcsharpPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public void closeReaders() {
    libCLcsharpPINVOKE.SegmentMerger_closeReaders(swigCPtr);
    if (libCLcsharpPINVOKE.SWIGPendingException.Pending) throw libCLcsharpPINVOKE.SWIGPendingException.Retrieve();
  }

}

}
