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

namespace RakNet {

using System;
using System.Runtime.InteropServices;

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

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

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

  ~Table() {
    Dispose();
  }

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


	public RakNetPageRow GetListHead() {
		return GetListHeadHelper();
	}

  	public void SortTable(SortQuery [] sortQueries, uint numSortQueries, out Row[] arg2) 
 	{
		RakNetListSortQuery sortQueriesList =null;
 		if (sortQueries!=null)
 		{
 			sortQueriesList = new RakNetListSortQuery();
 			int listLen = sortQueries.Length;
 			for (int i = 0; i < listLen; i++)
 			{
      	 		    sortQueriesList.Insert(sortQueries[i], "", 1);
 			}
 		}
 
 		int rowCount= (int)GetRowCount();
 		Row[] rowArray= new Row[rowCount];
 		RakNetListTableRow passVal = new RakNetListTableRow();
 		SortTableHelper(sortQueriesList,numSortQueries,passVal);
 		for (int i=0; i<rowCount;i++)
 		{
 		rowArray[i]=passVal[i];
	 	} 
 		arg2=rowArray;
  	}

 	public void GetCellValueByIndex(uint rowIndex, uint columnIndex, out byte[] outByteArray, out int outputLength) 
         {
 		int returnInt=0;
 		Row row = GetRowByIndex(rowIndex,ref returnInt);
 		int arrayLen=0;
 		if (row!=null)
 		{
 			arrayLen=(int)row.cells[(int)columnIndex].i;
 		}
 		byte[] inOutByteArray = new byte[arrayLen];
 		GetCellValueByIndexHelper(rowIndex,columnIndex,inOutByteArray,out outputLength);
 		outByteArray=inOutByteArray;
 	}

 	public void GetCellValueByIndex(uint rowIndex, uint columnIndex,out string output) 
 	{
 		int returnInt=0;
 		Row row = GetRowByIndex(rowIndex,ref returnInt);
 		int arrayLen=0;
 		if (row!=null)
 		{
 			arrayLen=(int)row.cells[(int)columnIndex].i;
 		}
    		String tmp = new String('c', arrayLen);
 		output=GetCellValueByIndexHelper( rowIndex, columnIndex, tmp);
 	}

       public  void QueryTable(uint[] columnIndicesSubset, uint numColumnSubset, FilterQuery[] inclusionFilters, uint numInclusionFilters, uint[] rowIds, uint numRowIDs, Table result)
 	{
 		RakNetListFilterQuery inclusionFiltersList =null;
 		if (inclusionFiltersList!=null)
 		{
 			inclusionFiltersList = new RakNetListFilterQuery();
 			int listLen = inclusionFilters.Length;
 			for (int i = 0; i < listLen; i++)
 			{
      	 		    inclusionFiltersList.Insert(inclusionFilters[i], "", 1);
 			}
 		}
 		QueryTableHelper(columnIndicesSubset, numColumnSubset, inclusionFiltersList, numInclusionFilters, rowIds, numRowIDs, result);
 	}

 	public uint ColumnIndex(string columnName) {
 	return ColumnIndexHelper(columnName);
 	}
 
  public Table() : this(RakNetPINVOKE.new_Table(), true) {
  }

  public uint AddColumn(string columnName, Table.ColumnType columnType) {
    uint ret = RakNetPINVOKE.Table_AddColumn(swigCPtr, columnName, (int)columnType);
    return ret;
  }

  public void RemoveColumn(uint columnIndex) {
    RakNetPINVOKE.Table_RemoveColumn(swigCPtr, columnIndex);
  }

  public string ColumnName(uint index) {
    string ret = RakNetPINVOKE.Table_ColumnName(swigCPtr, index);
    return ret;
  }

  public Table.ColumnType GetColumnType(uint index) {
    Table.ColumnType ret = (Table.ColumnType)RakNetPINVOKE.Table_GetColumnType(swigCPtr, index);
    return ret;
  }

  public uint GetColumnCount() {
    uint ret = RakNetPINVOKE.Table_GetColumnCount(swigCPtr);
    return ret;
  }

  public uint GetRowCount() {
    uint ret = RakNetPINVOKE.Table_GetRowCount(swigCPtr);
    return ret;
  }

  public Row AddRow(uint rowId) {
    IntPtr cPtr = RakNetPINVOKE.Table_AddRow__SWIG_0(swigCPtr, rowId);
    Row ret = (cPtr == IntPtr.Zero) ? null : new Row(cPtr, false);
    return ret;
  }

  public Row AddRow(uint rowId, RakNetListCell initialCellValues) {
    IntPtr cPtr = RakNetPINVOKE.Table_AddRow__SWIG_1(swigCPtr, rowId, RakNetListCell.getCPtr(initialCellValues));
    Row ret = (cPtr == IntPtr.Zero) ? null : new Row(cPtr, false);
    if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public Row AddRow(uint rowId, RakNetListCellPointer initialCellValues, bool copyCells) {
    IntPtr cPtr = RakNetPINVOKE.Table_AddRow__SWIG_2(swigCPtr, rowId, RakNetListCellPointer.getCPtr(initialCellValues), copyCells);
    Row ret = (cPtr == IntPtr.Zero) ? null : new Row(cPtr, false);
    if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public Row AddRow(uint rowId, RakNetListCellPointer initialCellValues) {
    IntPtr cPtr = RakNetPINVOKE.Table_AddRow__SWIG_3(swigCPtr, rowId, RakNetListCellPointer.getCPtr(initialCellValues));
    Row ret = (cPtr == IntPtr.Zero) ? null : new Row(cPtr, false);
    if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  public bool RemoveRow(uint rowId) {
    bool ret = RakNetPINVOKE.Table_RemoveRow(swigCPtr, rowId);
    return ret;
  }

  public void RemoveRows(Table tableContainingRowIDs) {
    RakNetPINVOKE.Table_RemoveRows(swigCPtr, Table.getCPtr(tableContainingRowIDs));
  }

  public bool UpdateCell(uint rowId, uint columnIndex, int value) {
    bool ret = RakNetPINVOKE.Table_UpdateCell__SWIG_0(swigCPtr, rowId, columnIndex, value);
    return ret;
  }

  public bool UpdateCell(uint rowId, uint columnIndex, string str) {
    bool ret = RakNetPINVOKE.Table_UpdateCell__SWIG_1(swigCPtr, rowId, columnIndex, str);
    return ret;
  }

  public bool UpdateCellByIndex(uint rowIndex, uint columnIndex, int value) {
    bool ret = RakNetPINVOKE.Table_UpdateCellByIndex__SWIG_0(swigCPtr, rowIndex, columnIndex, value);
    return ret;
  }

  public bool UpdateCellByIndex(uint rowIndex, uint columnIndex, string str) {
    bool ret = RakNetPINVOKE.Table_UpdateCellByIndex__SWIG_1(swigCPtr, rowIndex, columnIndex, str);
    return ret;
  }

  public void GetCellValueByIndex(uint rowIndex, uint columnIndex, out int output) {
    RakNetPINVOKE.Table_GetCellValueByIndex__SWIG_0(swigCPtr, rowIndex, columnIndex, out output);
  }

  public void GetCellValueByIndex(uint rowIndex, uint columnIndex, string output, uint outputLength) {
    RakNetPINVOKE.Table_GetCellValueByIndex__SWIG_1(swigCPtr, rowIndex, columnIndex, output, outputLength);
  }

  public Row GetRowByID(uint rowId) {
    IntPtr cPtr = RakNetPINVOKE.Table_GetRowByID(swigCPtr, rowId);
    Row ret = (cPtr == IntPtr.Zero) ? null : new Row(cPtr, false);
    return ret;
  }

  public Row GetRowByIndex(uint rowIndex, ref int key) {
    IntPtr cPtr = RakNetPINVOKE.Table_GetRowByIndex(swigCPtr, rowIndex, ref key);
    Row ret = (cPtr == IntPtr.Zero) ? null : new Row(cPtr, false);
    return ret;
  }

  public void Clear() {
    RakNetPINVOKE.Table_Clear(swigCPtr);
  }

  public RakNetListColumnDescriptor GetColumns() {
    RakNetListColumnDescriptor ret = new RakNetListColumnDescriptor(RakNetPINVOKE.Table_GetColumns(swigCPtr), false);
    return ret;
  }

  public RakNetBPlusTreeRow GetRows() {
    RakNetBPlusTreeRow ret = new RakNetBPlusTreeRow(RakNetPINVOKE.Table_GetRows(swigCPtr), false);
    return ret;
  }

  public uint GetAvailableRowId() {
    uint ret = RakNetPINVOKE.Table_GetAvailableRowId(swigCPtr);
    return ret;
  }

  public Table CopyData(Table input) {
    Table ret = new Table(RakNetPINVOKE.Table_CopyData(swigCPtr, Table.getCPtr(input)), false);
    if (RakNetPINVOKE.SWIGPendingException.Pending) throw RakNetPINVOKE.SWIGPendingException.Retrieve();
    return ret;
  }

  private RakNetPageRow GetListHeadHelper() {
    IntPtr cPtr = RakNetPINVOKE.Table_GetListHeadHelper(swigCPtr);
    RakNetPageRow ret = (cPtr == IntPtr.Zero) ? null : new RakNetPageRow(cPtr, false);
    return ret;
  }

  private void SortTableHelper(RakNetListSortQuery sortQueries, uint numSortQueries, RakNetListTableRow arg2) {
    RakNetPINVOKE.Table_SortTableHelper(swigCPtr, RakNetListSortQuery.getCPtr(sortQueries), numSortQueries, RakNetListTableRow.getCPtr(arg2));
  }

  private void GetCellValueByIndexHelper(uint rowIndex, uint columnIndex, byte[] inOutByteArray, out int outputLength) {
    RakNetPINVOKE.Table_GetCellValueByIndexHelper__SWIG_0(swigCPtr, rowIndex, columnIndex, inOutByteArray, out outputLength);
  }

  private string GetCellValueByIndexHelper(uint rowIndex, uint columnIndex, string output) {
    string ret = RakNetPINVOKE.Table_GetCellValueByIndexHelper__SWIG_1(swigCPtr, rowIndex, columnIndex, output);
    return ret;
  }

  public void PrintColumnHeaders(byte[] inOutByteArray, int byteArrayLength, char columnDelineator) {
    RakNetPINVOKE.Table_PrintColumnHeaders(swigCPtr, inOutByteArray, byteArrayLength, columnDelineator);
  }

  public void PrintRow(byte[] inOutByteArray, int byteArrayLength, char columnDelineator, bool printDelineatorForBinary, Row inputRow) {
    RakNetPINVOKE.Table_PrintRow(swigCPtr, inOutByteArray, byteArrayLength, columnDelineator, printDelineatorForBinary, Row.getCPtr(inputRow));
  }

  private void QueryTableHelper(uint[] columnIndicesSubset, uint numColumnSubset, RakNetListFilterQuery inclusionFilters, uint numInclusionFilters, uint[] rowIds, uint numRowIDs, Table result) {
    RakNetPINVOKE.Table_QueryTableHelper(swigCPtr, columnIndicesSubset, numColumnSubset, RakNetListFilterQuery.getCPtr(inclusionFilters), numInclusionFilters, rowIds, numRowIDs, Table.getCPtr(result));
  }

  public bool UpdateCell(uint rowId, uint columnIndex, int byteLength, byte[] inByteArray) {
    bool ret = RakNetPINVOKE.Table_UpdateCell__SWIG_2(swigCPtr, rowId, columnIndex, byteLength, inByteArray);
    return ret;
  }

  public bool UpdateCellByIndex(uint rowIndex, uint columnIndex, int byteLength, byte[] inByteArray) {
    bool ret = RakNetPINVOKE.Table_UpdateCellByIndex__SWIG_2(swigCPtr, rowIndex, columnIndex, byteLength, inByteArray);
    return ret;
  }

  private uint ColumnIndexHelper(string columnName) {
    uint ret = RakNetPINVOKE.Table_ColumnIndexHelper(swigCPtr, columnName);
    return ret;
  }

  public enum ColumnType {
    NUMERIC,
    STRING,
    BINARY,
    POINTER
  }

  public enum FilterQueryType {
    QF_EQUAL,
    QF_NOT_EQUAL,
    QF_GREATER_THAN,
    QF_GREATER_THAN_EQ,
    QF_LESS_THAN,
    QF_LESS_THAN_EQ,
    QF_IS_EMPTY,
    QF_NOT_EMPTY
  }

  public enum SortQueryType {
    QS_INCREASING_ORDER,
    QS_DECREASING_ORDER
  }

}

}
