/*
 ******************************************************************************
 *  Copyright 1984-1993 United States Data Corporation. All Rights Reserved.
 ******************************************************************************
 *                                - NOTICE -
 *
 *  The information contained herein is confidential information of United
 *  States Data Corporation, a Delaware corporation, and is protected by
 *  United States copyright and trade secret law and international treaties.
 *  This information is not to be disclosed, used or copied by or transferred
 *  to any individual, corporation, company or other person without the
 *  express written permission of United States Data Corporation.
 ******************************************************************************
 *
 * Module:	HDT_HSDA.H
 *
 *	Header file for historian structure manipulation functions.
 *
 * History:
 *		bjc 05/06/93	Created. 
 */


#ifndef _HSDA_INCLUDED
#define _HSDA_INCLUDED

#include <hdt_base.h>	

/*
 ************************************************************************
 *                              Constants                               *       
 ************************************************************************
 */


/*
 ************************************************************************
 *                              Structures                              * 
 ************************************************************************
 */


/*
 ************************************************************************
 *                              Macros                                  *       
 ************************************************************************
 */

/*
 *  Function re-direction macros
 */

#define hsda_bld_insq(hs_da, tblname, query, maxlen) \
	hsda_bld_addq(hs_da, tblname, DBUT_INSQ, query, maxlen)

#define hsda_bld_logq(hs_da, tblname, query, maxlen) \
	hsda_bld_addq(hs_da, tblname, DBUT_LOGQ, query, maxlen)

#define hsda_to_dig(da, ndx, offset)		((DIG)(hsda_to_float(da, ndx, offset)))
#define hsda_from_dig(da, ndx, offset, dig)	(hsda_from_float(da, ndx, offset, (FLP) dig))

#define hsda_to_ana(da, ndx, offset)		((ANA)(hsda_to_float(da, ndx, offset)))
#define hsda_from_ana(da, ndx, offset, ana)	(hsda_from_float(da, ndx, offset, (FLP) ana))

#define hsda_to_lana(da, ndx, offset)		((LANA)(hsda_to_float(da, ndx, offset)))
#define hsda_from_lana(da, ndx, offset, lana)	(hsda_from_float(da, ndx, offset, (FLP) lana))

#define hsda_set_null(da, ndx, offset)		hsda_from_string(da, ndx, offset, NULL)

/*
 *  HS_DA access macros
 */

#define hsda_get_var_cnt(hs_da)		((hs_da)->var_count)
#define hsda_get_max_rows(hs_da)	((hs_da)->max_rows)
#define hsda_get_data_rows(hs_da)	((hs_da)->data_rows)
#define hsda_inc_data_rows(hs_da, n)	((hs_da)->data_rows += n)
#define hsda_init_data_rows(hs_da)	((hs_da)->data_rows = 0)

/*
 *  HS_VAR access macros
 */

#define hsda_get_var_name(hs_da, n)	((hs_da)->var_array[n].col_name)
#define hsda_get_var_type(hs_da, n)	((hs_da)->var_array[n].data_type)
#define hsda_get_var_size(hs_da, n)	((hs_da)->var_array[n].data_size)
#define hsda_get_var_dbtype(hs_da, n)	((hs_da)->var_array[n].db_data_type)
#define hsda_get_var_dbsize(hs_da, n)	((hs_da)->var_array[n].db_data_size)
#define hsda_get_var(hs_da, n)		(&((hs_da)->var_array[n]))
#define hsda_is_var_null(hs_da, n, o)	(((hs_da)->var_array[n]).data_null[o])

#define hsvar_get_name(hsvar)		((hsvar)->col_name)
#define hsvar_get_type(hsvar)		((hsvar)->data_type)
#define hsvar_get_size(hsvar)		((hsvar)->data_size)
#define hsvar_get_dbtype(hsvar)		((hsvar)->db_data_type)
#define hsvar_get_dbsize(hsvar)		((hsvar)->db_data_size)


/*
 ************************************************************************
 *                         Function Prototypes                          * 
 ************************************************************************
 */
#ifdef __cplusplus
extern "C" {
#endif

extern HS_DA*	hsda_create(short num_vars);
extern int	hsda_create_data(HS_DA *hs_da, short num_rows);
extern void	hsda_destroy(HS_DA *hs_da, int destroy_data);
extern void	hsda_destroy_data(HS_DA *hs_da);

extern short	hsda_find_var(HS_DA *hsda, char *fldname);
extern int	hsda_cfg_var(HS_DA *hsda, short var_ndx, short fl_type, 
		             short db_type, short size, char *col_name);
extern int	hsda_cfg_var_data(HS_DA *hsda, short var_ndx, 
		                  void *data, short *null);
extern int	hsda_set_var2var(HS_DA *dst, short dst_ndx,
		                 HS_DA *src, short src_ndx);

extern void* 	hsda_to_buffer(HS_DA *hsda, short var_ndx, short offset, 
		               void *buffer, size_t len);
extern void	hsda_from_buffer(HS_DA *hsda, short var_ndx, short offset, 
		                 void *buffer, size_t len);
extern char*	hsda_to_string(HS_DA *hsda, short var_ndx, short offset, 
		               char *string, size_t len);
extern void	hsda_from_string(HS_DA *hsda, short var_ndx, 
		                 short offset, char *string);
extern FLP	hsda_to_float(HS_DA *hsda, short var_ndx, short offset);
extern void	hsda_from_float(HS_DA *hsda, short var_ndx, 
		                short offset, FLP value);
extern void	hsda_xfer_data(HS_DA *dst, short dst_ndx, short dst_offset, 
		               HS_DA *src, short src_ndx, short src_offset);
extern void	hsda_nullify_row(HS_DA *hsda, short offset);

extern int	hsda_delin_flds(HS_DA *hs_da, short num_col, short *cols, 
		                char *outstr, int maxlen);
extern int	hsda_bld_regq(HS_DA *hs_da, char *tblname, 
		              char *query, int maxlen);
extern int 	hsda_bld_addq(HS_DA *hs_da, char *tblname, int add_type,
		              char *query, int maxlen);

#ifdef __cplusplus
}
#endif

#endif

