
/** @file  psScalar.h
 *
 *  @brief Contains basic scalar definitions and operations
 *
 *  This file defines the basic type for a scalar struct and functions useful
 *  in manupulating scalars.
 *
 *  @ingroup Scalar
 *
 *  @author Ross Harman, MHPCC
 *
 *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
 *  @date $Date: 2005-09-15 21:22:22 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 */

#ifndef PS_SCALAR_H
#define PS_SCALAR_H

#include "psType.h"

/// @addtogroup Scalar
/// @{

/** Basic scalar data structure.
 *
 * Struct for maintaining a scalar of frequently used primitive types.
 *
 */
typedef struct
{
    psMathType type;            ///< Type of data.

    union {
        psS8 S8;                ///< Signed 8-bit integer data.
        psS16 S16;              ///< Signed 16-bit integer data.
        psS32 S32;              ///< Signed 32-bit integer data.
        psS64 S64;              ///< Signed 64-bit integer data.
        psU8 U8;                ///< Unsigned 8-bit integer data.
        psU16 U16;              ///< Unsigned 16-bit integer data.
        psU32 U32;              ///< Unsigned 32-bit integer data.
        psU64 U64;              ///< Unsigned 64-bit integer data.
        psF32 F32;              ///< Single-precision float data.
        psF64 F64;              ///< Double-precision float data.
        psC32 C32;              ///< Single-precision complex data.
        psC64 C64;              ///< Double-precision complex data.
    } data;                     ///< Union for data types.
}
psScalar;

/*****************************************************************************/

/* FUNCTION PROTOTYPES                                                       */

/*****************************************************************************/

/** Allocate a scalar.
 *
 * Uses psLib memory allocation functions to create scalar data as defined by the psType type.
 * Accepts a complex 64 bit float for input value, as max size, but resizes according to
 * correct type.
 *
 * @return psScalar*   Pointer to a new psScalar.
 */
psScalar* psScalarAlloc(
    complex value,                     ///< Data to be put into psScalar.
    psElemType type                    ///< Type of data to be held by psScalar.
);


/** Checks the type of a particular pointer.
 *
 *  Uses the appropriate deallocation function in psMemBlock to check the ptr datatype.
 *
 *  @return bool:       True if the pointer matches a psScalar structure, false otherwise.
 */
bool psMemCheckScalar(
    psPtr ptr                          ///< the pointer whose type to check
);


/** Copy a scalar.
 *
 * Uses psLib memory allocation functions to copy a scalar.
 *
 * @return psScalar*    A copy of the input scalar
 */
psScalar* psScalarCopy(
    const psScalar *value              ///< Scalar to copy.
);

/// @}

#endif // #ifndef PS_SCALAR_H
