#ifndef CCMIO_BUFFER_H
#define CCMIO_BUFFER_H

/*@@
 *  Program: Star File Format Library  - $RCSfile: ccmiobuffer.h,v $
 *  Author:  Geoff Prewett
 *  Date:    July 31, 2003
 *
 *
 *  Star File Format Library - Copyright (C) 2003 by adapco, Ltd.
 *
 *  This program is the property of adapco, Ltd. and contains
 *  confidential and proprietary information.  The unauthorized use,
 *  distribution, or duplication of this program is prohibited.
 *  All rights reserved.
 *
 *  $Id: ccmiobuffer.h,v 1.2 2004/07/07 20:13:50 prewett Exp $
 */

#ifdef __cplusplus
extern "C" {
#endif

#include <stdarg.h>
typedef char CCMIOBufferDataType;
struct _CCMIOBuffer {
    long size;			/** Size of buffer */
    long start;			/** Byte offset that buffer[0] represents */
    CCMIOBufferDataType *buffer;	/** The buffer */
    CCMIONode node;		/** The node */
    int nDims;			/** The number of dimensions (cached) */
    int *dims;			/** The size of dimensions (cached) */
    unsigned int max;		/** Number of items in the node (cached) */
    int typeSize;		/** Size of the datatype in the buffer(cached)*/
    int isRead;			/** TRUE if buffer is a read buffer, FALSE
				    otherwise */
    };

typedef struct _CCMIOBuffer* CCMIOBuffer;

/* \ingroup core */
#define kCCMIOInfinite		0
/* \ingroup core */
#define kCCMIODefaultBufferSize	kCCMIOInfinite

/* \{
   \name CCMIOBuffer
   \brief Buffers reading and writing.
   \ingroup core */

/** Sets the buffer size (in elements) for new buffers.  If n is kCCMIOInfinite,
    a buffer as big as the node's data will be allocated. */
extern void CCMIOSetBufferSize( int n );

/** Creates a buffer */
extern CCMIOError CCMIOCreateBuffer( CCMIOError *err, CCMIONode node,
				     CCMIOBufferType which, CCMIOBuffer *buff );

/** Destroys the buffer (even if an err is not kCCMIONoErr) */
extern CCMIOError CCMIODestroyBuffer( CCMIOError *err, CCMIOBuffer buff );

/** Reads one data point
    \param err		Error input and output.  If the incoming error is
    			not kCCMIONoErr, the function will do nothing.  Is set
			the the function's return value on exit.
    \param buff		The buffer to use.
    \param ...		The number and size of the dimensions, terminated with
			a kCCMIOEndArgs.  For instance an array of
			"int ary[5][10];" would be
			"CCMIOReadDataPoint(node, data, 5, 10, kCCMIOEndArgs)".
			A single dimension of size 1 is equivalent to a scalar
			value.  If n is out of range returns kCCMIONoDataErr. */
extern CCMIOError CCMIOBufferReadDataPoint( CCMIOError *err, CCMIOBuffer buff,
					    void *data, ... );
extern CCMIOError CCMIOvBufferReadDataPoint( CCMIOError *err, CCMIOBuffer buff,
					     void *data, va_list args );

/** Reads one data point
    \param err		Error input and output.  If the incoming error is
    			not kCCMIONoErr, the function will do nothing.  Is set
			the the function's return value on exit.
    \param buff		The buffer to use.
    \param n		The offset of the data point as if the data were one
    			contiguous array (even if in actuality the array is
			multi-dimensional).  If n is out of range returns
			kCCMIONoDataErr. */
extern CCMIOError CCMIOBufferWriteNextDataPoint( CCMIOError *err,
						 CCMIOBuffer buff,
						 int n, void *data );

/** Writes one data point to the buffer, which is written when the buffer
    is closed.  Note that the buffer must be opened as a write buffer. */
extern CCMIOError CCMIOBufferWriteDataPoint( CCMIOError *err, CCMIOBuffer buff,
					     void *data, ... );
extern CCMIOError CCMIOvBufferWriteDataPoint( CCMIOError *err, CCMIOBuffer buff,
					      void *data, va_list args );
/** Returns the node associated with the buffer */
extern CCMIOError CCMIOBufferGetNode( CCMIOError *err, CCMIOBuffer buff,
				      CCMIONode *node);
/*\}*/
#ifdef __cplusplus
}
#endif
#endif // CCMIO_BUFFER_H
