misc.cxx 1.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * misc.cc -- miscellaneous utitlity functions
 * 
 * author:  msturm 
 * created: 27 Mar 1997
 * changes: mastyner
 */


#include "misc.h"


void* ipAllocateData(const int size, const size_t elemsize)
{
  void *data = NULL;

  if (!(data = malloc(size * elemsize))) {
    fprintf(stderr,"Error: ipAllocateData [%s, line %d]: memory allocation failed:",
            __FILE__, __LINE__);
    perror("");
    exit(errno);
  }
  
  memset(data, 0, size * elemsize);

  return(data);
}


size_t ipGetDataSize(const ipDataType type)
{
  size_t retval;

  switch (type) {
  case IP_BYTE:
    retval = sizeof(char);
    break;
  case IP_SHORT:
    retval = sizeof(short);
    break;
  case IP_INT:
    retval = sizeof(int);
    break;
  case IP_FLOAT:
    retval = sizeof(float);
    break;
  case IP_DOUBLE:
    retval = sizeof(double);
    break;
  default:
#ifdef DEBUG_VSKEL
    fprintf(stderr,"Warning: ipGetDataSize [%s, line %d]: unsuported data type: %d\n",
            __FILE__, __LINE__, type);
#endif

    retval = 0;
    break;
  }

  return retval;
  
}