#ifndef _TUPLE_H
#define _TUPLE_H

#include "schema.h"
#include <cstdio>

// Attribute in the tuple

typedef struct atrribute{
  // type of this attribute
  int attr_type; 
  // the value of this attribute
  // use attr_type to figure out which of these field is the one to access
  union value {
    int_type int_val; // integer value
    double_type double_val; // double value
    char_type char_val; // character string value
  }attr_val;
}attribute;

// Tuple 
typedef struct tuple{
  int num_attrs; // number of attributes in the tuple
  attribute *attr_list;  // array for the attributes
}tuple;


/*
 * This function creates a new tuple from a relation schema
 * information object.
 * Input: rel_info - pointer to relation information structure.
 * Output: a new tuple that conforms to the schema.
 */
tuple *make_tuple(relation_info *rel_info);

/*
 * This function creates a new tuple based on the schema 
 * information contained in a projection list.
 * Input: proj_list - list of infornmation about projections to be performed.
 * Output: a new tuple that conforms to the schema for the projections.
 */
tuple *make_tuple(proj_attr_list *proj_list);

/*
 * Returns the size in bytes of an attribute based on the schema
 * information about a relation.
 * Input: rel_info - pointer to a relation schema information structure
 * Ouput: number of bytes in a tuple that follows the given schema.
 */
int tuple_size(relation_info *rel_info);


/*
 * This method is used to fill in the data stored in a block of 
 * bytes into a tuple.
 * Input: src - pointer the beginning of the data block.
 * Input: src_size - number of bytes in the data block.
 * Input: rel_info - pointer to the relation schema info.
 * Input: target - pointer to the tuple where the data is to be stored.
 * Ouput: Diagnostic value indicating if the operation was a success or not.
 */

int fill_in_tuple(char *src, int src_size,  relation_info *rel_info,  
		  tuple *target);

/*
 * Copies an integer value from one attribute to another.
 * Input: dest - the attribute where the integer value is to be stored.
 * Input: src - the attribute where the integer is currently held.
 */
void copy_int_attr(attribute& dest, const attribute& src);

/*
 * Copies an double value from one attribute to another.
 * Input: dest - the attribute where the double value is to be stored.
 * Input: src - the attribute where the double is currently held.
 */
void copy_double_attr(attribute& dest, const attribute& src);


/*
 * Copies an character value from one attribute to another.
 * Input: dest - the attribute where the character value is to be stored.
 * Input: src - the attribute where the characted is currently held.
 */
void copy_char_attr(attribute& dest, const attribute& src);

/*
 * Prints the contents of a tuples to a given file.
 * Input: tup - the tuple being printed
 * Input: out - the destination file
 */
void print_tuple(tuple *tup, FILE *out);

#endif
