NSCL DDAS  1.0
Support for XIA DDAS at the NSCL
 All Classes Namespaces Files Functions Variables Macros Pages
xia_common.h
1 /*
2  * xia_common.h
3  *
4  * Copyright (c) 2004, X-ray Instrumentation Associates
5  * 2005 - 2009, XIA LLC
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms,
9  * with or without modification, are permitted provided
10  * that the following conditions are met:
11  *
12  * * Redistributions of source code must retain the above
13  * copyright notice, this list of conditions and the
14  * following disclaimer.
15  * * Redistributions in binary form must reproduce the
16  * above copyright notice, this list of conditions and the
17  * following disclaimer in the documentation and/or other
18  * materials provided with the distribution.
19  * * Neither the name of X-ray Instrumentation Associates
20  * nor the names of its contributors may be used to endorse
21  * or promote products derived from this software without
22  * specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
25  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
27  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28  * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
33  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
34  * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
35  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *
39  * $Id: xia_common.h 1197 2005-02-23 00:45:53Z SYSTEM $
40  *
41  * All of the useful typedefs and macros
42  * go in here. Two conditions must be met
43  * in order to qualify as an "xia_common"
44  * typedef or macro:
45  * 1) Must not be defined anywhere else and
46  * 2) Must be able to be used in any library/module.
47  *
48  */
49 
50 
51 #ifndef XIA_COMMON_H
52 #define XIA_COMMON_H
53 
54 #include <string.h>
55 #include <math.h>
56 
60 typedef unsigned char byte_t;
61 typedef unsigned char boolean_t;
62 typedef unsigned short parameter_t;
63 typedef unsigned short flag_t;
64 
66 #define TRUE_ (1 == 1)
67 #define FALSE_ (1 == 0)
68 
69 #define UNUSED(x) ((x) = (x))
70 #define STREQ(x, y) (strcmp((x), (y)) == 0)
71 #define STRNEQ(x, y) (strncmp((x), (y), strlen(y)) == 0)
72 #define ROUND(x) ((x) < 0.0 ? ceil((x) - 0.5) : floor((x) + 0.5))
73 #define PRINT_NON_NULL(x) ((x) == NULL ? "NULL" : (x))
74 #define BYTE_TO_WORD(lo, hi) (unsigned short)(((unsigned short)(hi) << 8) | (lo))
75 #define LO_BYTE(word) ((word) & 0xFF)
76 #define HI_BYTE(word) (((word) >> 8) & 0xFF)
77 #define MAKE_LOWER_CASE(s, i) for ((i) = 0; (i) < strlen((s)); (i)++) \
78  (s)[i] = (char)tolower((s)[i])
79 #define N_ELEMS(x) (sizeof(x) / sizeof((x)[0]))
80 
81 
82 /* These macros already exist on Linux, so they need to be protected */
83 
84 #ifndef MIN
85 #define MIN(x, y) ((x) < (y) ? (x) : (y))
86 #endif /* MIN */
87 
88 #ifndef MAX
89 #define MAX(x, y) ((x) > (y) ? (x) : (y))
90 #endif /* MAX */
91 
92 #endif /* Endif for XIA_COMMON_H */