/*
 * File: ref.h
 * -----------
 * This interface exports several simple functions for allocating pointers
 * to the atomic types.
 */

#ifndef _ref_h
#define _ref_h

#include "cslib.h"

/*
 * Function: newRefInt
 * Usage: ref = newRefInt(value);
 * ------------------------------
 * Allocates a ref pointing to the specified int value.
 */

void *newRefInt(int value);

/*
 * Function: newRefShort
 * Usage: ref = newRefShort(value);
 * --------------------------------
 * Allocates a ref pointing to the specified short value.
 */

void *newRefShort(short value);

/*
 * Function: newRefLong
 * Usage: ref = newRefLong(value);
 * -------------------------------
 * Allocates a ref pointing to the specified long value.
 */

void *newRefLong(long value);

/*
 * Function: newRefFloat
 * Usage: ref = newRefFloat(value);
 * --------------------------------
 * Allocates a ref pointing to the specified float value.
 */

void *newRefFloat(float value);

/*
 * Function: newRefDouble
 * Usage: ref = newRefDouble(value);
 * ---------------------------------
 * Allocates a ref pointing to the specified double value.
 */

void *newRefDouble(double value);

/*
 * Function: newRefChar
 * Usage: ref = newRefChar(value);
 * -------------------------------
 * Allocates a ref pointing to the specified char value.
 */

void *newRefChar(char value);

/*
 * Function: newRefBool
 * Usage: ref = newRefBool(value);
 * -------------------------------
 * Allocates a ref pointing to the specified bool value.
 */

void *newRefBool(bool value);

/*
 * Function: newRefUnsigned
 * Usage: ref = newRefUnsigned(value);
 * -----------------------------------
 * Allocates a ref pointing to the specified unsigned value.
 */

void *newRefUnsigned(unsigned value);

/*
 * Function: newRefUnsignedShort
 * Usage: ref = newRefUnsignedShort(value);
 * ----------------------------------------
 * Allocates a ref pointing to the specified unsigned short value.
 */

void *newRefUnsignedShort(unsigned short value);

/*
 * Function: newRefUnsignedLong
 * Usage: ref = newRefUnsignedLong(value);
 * ---------------------------------------
 * Allocates a ref pointing to the specified unsigned long value.
 */

void *newRefUnsignedLong(unsigned long value);

/*
 * Function: newRefUnsignedChar
 * Usage: ref = newRefUnsignedChar(value);
 * ---------------------------------------
 * Allocates a ref pointing to the specified unsigned char value.
 */

void *newRefUnsignedChar(unsigned char value);

/*
 * Part 2 -- Functions to dereference generic pointers
 * ---------------------------------------------------
 * These functions take a generic pointer of type void * and return the
 * value to which it points, which must be of the type indicated by the
 * function name.  For example, refToInt(ref) interprets ref as a pointer
 * to an int and returns the integer at that address.
 */

/*
 * Function: refToInt
 * Usage: i = refToInt(ref);
 * -------------------------
 * Returns the int to which this reference points.
 */

int refToInt(void *ref);

/*
 * Function: refToShort
 * Usage: s = refToShort(ref);
 * ---------------------------
 * Returns the short to which this reference points.
 */

short refToShort(void *ref);

/*
 * Function: refToLong
 * Usage: l = refToLong(ref);
 * --------------------------
 * Returns the long to which this reference points.
 */

long refToLong(void *ref);

/*
 * Function: refToFloat
 * Usage: f = refToFloat(ref);
 * ---------------------------
 * Returns the float to which this reference points.
 */

float refToFloat(void *ref);

/*
 * Function: refToDouble
 * Usage: d = refToDouble(ref);
 * ----------------------------
 * Returns the double to which this reference points.
 */

double refToDouble(void *ref);

/*
 * Function: refToChar
 * Usage: c = refToChar(ref);
 * --------------------------
 * Returns the char to which this reference points.
 */

char refToChar(void *ref);

/*
 * Function: refToBool
 * Usage: b = refToBool(ref);
 * --------------------------
 * Returns the bool to which this reference points.
 */

bool refToBool(void *ref);

/*
 * Function: refToUnsigned
 * Usage: u = refToUnsigned(ref);
 * ------------------------------
 * Returns the unsigned to which this reference points.
 */

unsigned refToUnsigned(void *ref);

/*
 * Function: refToUnsignedShort
 * Usage: us = refToUnsignedShort(ref);
 * ------------------------------------
 * Returns the unsigned short to which this reference points.
 */

unsigned short refToUnsignedShort(void *ref);

/*
 * Function: refToUnsignedLong
 * Usage: ul = refToUnsignedLong(ref);
 * -----------------------------------
 * Returns the unsigned long to which this reference points.
 */

unsigned long refToUnsignedLong(void *ref);

/*
 * Function: refToUnsignedChar
 * Usage: uc = refToUnsignedChar(ref);
 * -----------------------------------
 * Returns the unsigned char to which this reference points.
 */

unsigned char refToUnsignedChar(void *ref);

#endif