From 5a422aba704c375a307a902bafe658342e209906 Mon Sep 17 00:00:00 2001 From: scuri Date: Fri, 17 Oct 2008 06:10:15 +0000 Subject: First commit - moving from LuaForge to SourceForge --- src/im_datatype.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/im_datatype.cpp (limited to 'src/im_datatype.cpp') diff --git a/src/im_datatype.cpp b/src/im_datatype.cpp new file mode 100644 index 0000000..c75483e --- /dev/null +++ b/src/im_datatype.cpp @@ -0,0 +1,54 @@ +/** \file + * \brief Data Type Utilities + * + * See Copyright Notice in im_lib.h + * $Id: im_datatype.cpp,v 1.1 2008/10/17 06:10:16 scuri Exp $ + */ + + +#include "im.h" +#include "im_util.h" + +#include + +typedef struct _iTypeInfo +{ + int size; + unsigned long max; + long min; + char* name; +} iTypeInfo; + +static iTypeInfo iTypeInfoTable[] = +{ + {1, 255, 0, "byte"}, + {2, 65535, 0, "ushort"}, + {4, 2147483647, -2147483647-1, "int"}, + {4, 0, 0, "float"}, + {8, 0, 0, "cfloat"} +}; + +const char* imDataTypeName(int data_type) +{ + assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT); + return iTypeInfoTable[data_type].name; +} + +int imDataTypeSize(int data_type) +{ + assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT); + assert(sizeof(int) == 4); + return iTypeInfoTable[data_type].size; +} + +unsigned long imDataTypeIntMax(int data_type) +{ + assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT); + return iTypeInfoTable[data_type].max; +} + +long imDataTypeIntMin(int data_type) +{ + assert(data_type >= IM_BYTE && data_type <= IM_CFLOAT); + return iTypeInfoTable[data_type].min; +} -- cgit v1.2.3