
/**********************************************************//**
 **
 ** @file data/Store/tablecursor_c.h
 **
 ** Copyright (C) 2009  Xpace, LLC.  All rights reserved
 **
 ** www.xpace.net
 **
 **************************************************************/

#ifndef XPACE_TABLECURSOR_C_H
#define XPACE_TABLECURSOR_C_H

#include "base/types_c.h"
#include "base/exception_c.h"

#ifdef __cplusplus
  #include "data/store/tablecursor.h"
  struct Xpace_TableCursor
  {
    Xpace::TableCursor* tc;
  };
  extern "C"
  {

#else
  typedef struct
  {
    void* v;
  }
  Xpace_TableCursor;
#endif

/// @param c the Table's Configuration
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_Create
  (Xpace_String c,
   Xpace_TableCursor* result);

XPACE_EXPORT void XPACE_ABI Xpace_TableCursor_Destroy
  (Xpace_TableCursor);

XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getConfig
  (const Xpace_TableCursor,
   Xpace_String* result);

/// @retval true if the table is empty
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_isEmpty
  (const Xpace_TableCursor,
   bool* result);

/// @retval the table's name
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getName
  (const Xpace_TableCursor tc,
   Xpace_String* result);

/// add a column with this Configuration to the table
/// @param c the new column's Configuration
/// @retval true iff succesful
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_addColumn
  (Xpace_TableCursor,
   Xpace_String c,
   bool* result);

/// Get a column's configuration
/// @param col the column number
/// @retval the column's Configuration
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getColumnConfig
  (const Xpace_TableCursor, 
   uint col,
   Xpace_String* result);

/// @retval the number of rows in the table
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getRowCount
  (const Xpace_TableCursor,
   uint64* result);

/// @retval the number of columns in the table
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getColumnCount
  (const Xpace_TableCursor,
   uint* result);

/// @param row move cursor to this row
/// @retval true if successful, false (and don't move) if not
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_moveToRow
  (Xpace_TableCursor,
   uint64 row,
   bool* result);

/// append a row to the table, making it current
/// @retval true if successful, false (and don't move) if not
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_addRow
  (Xpace_TableCursor,
   bool* result);

/// get the (String) contents of a cell from the current row
/// @param column from this column
/// @retval the (String) contents of the cell
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getCellStr
  (const Xpace_TableCursor,
   uint column,
   Xpace_String* result);

/// set the (String) contents of a cell on the current row
/// @param column set this column
/// @param str the (String) contents of the cell
/// @retval true iff successful
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_setCell
  (Xpace_TableCursor,
   uint column,
   const Xpace_String str,
   bool* result);

/// get the (integer) contents of a cell from the current row
/// @param column from this column
/// @param ok fillin true if successful
/// @retval the (integer) contents of the cell
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getCellInt
  (const Xpace_TableCursor,
   uint column,
   bool* ok,
   int64* result);

/// set the (integer) contents of a cell on the current row
/// @param column set this column
/// @param n the (integer) contents of the cell
/// @return true iff successful
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_setCellInt
  (const Xpace_TableCursor,
   uint column,
   int64 n,
   bool* result);

/// get the (raw) contents of a cell from the current row
/// @param column from this column
/// @retval the (raw) contents of the cell
XPACE_EXPORT Xpace_Error XPACE_ABI Xpace_TableCursor_getCellBytes
  (const Xpace_TableCursor,
   uint column,
   Xpace_Bytes* result);

#ifdef __cplusplus
}
#endif

#endif
