NCBI C++ ToolKit
ncbi_std.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_std.h 98577 2022-12-06 19:37:30Z gouriano $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  *
27  */
28 
29 /** @file ncbi_std.h
30  * Type and macro definitions from C toolkit that are not defined in C++
31  * toolkit.
32  */
33 
34 
35 
36 #ifndef ALGO_BLAST_CORE__NCBI_STD
37 #define ALGO_BLAST_CORE__NCBI_STD
38 
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 
43 #include <math.h>
44 #include <ctype.h>
45 #include <assert.h>
46 
47 /* which toolkit are we using? */
48 #include "blast_toolkit.h"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 #ifndef NCBI_RESTRICT /* now defined in the C++ Toolkit */
56 /** For some reason, ICC claims a suitable __STDC_VERSION__ but then
57  barfs on restrict. Added ECC per Haruna Cofer */
58 #if defined(__ICC) || defined(__ECC)
59 #define NCBI_RESTRICT __restrict
60 #elif __STDC_VERSION__ >= 199901 && (!defined(__IBMC__) || defined(__C99_RESTRICT))
61 #define NCBI_RESTRICT restrict
62 #else
63 #define NCBI_RESTRICT
64 #endif
65 #endif
66 
67 /* inlining support -- compiler dependent */
68 #if defined(__cplusplus) || __STDC_VERSION__ >= 199901
69 /** C++ and C99 both guarantee "inline" */
70 #define NCBI_INLINE inline
71 #elif defined(__GNUC__)
72 /* So does GCC, normally, but it may be running with strict options
73  that require the extra underscores */
74 #define NCBI_INLINE __inline__
75 #elif defined(_MSC_VER) || defined(__sgi) || defined(HPUX)
76 /* MSVC and (older) MIPSpro always require leading underscores */
77 #define NCBI_INLINE __inline
78 #else
79 /** "inline" seems to work on our remaining in-house compilers
80  (WorkShop, Compaq, ICC, MPW) */
81 #define NCBI_INLINE inline
82 #endif
83 
84 #ifdef _MSC_VER
85 #define strcasecmp _stricmp
86 #define strdup _strdup
87 # if _MSC_VER < 1900
88 #define snprintf _snprintf
89 # endif
90 #endif
91 
92 #ifndef _NCBISTD_ /* if we're not in the C toolkit... */
93 /** bool replacment for C */
94 typedef Uint1 Boolean;
95 #ifndef TRUE
96 /** bool replacment for C indicating true. */
97 #define TRUE 1
98 #endif
99 #ifndef FALSE
100 /** bool replacment for C indicating false. */
101 #define FALSE 0
102 #endif
103 #endif
104 
105 /** macro for assert. */
106 #ifndef ASSERT
107 #define ASSERT assert
108 #endif
109 
110 #ifndef MIN
111 /** returns smaller of a and b. */
112 #define MIN(a,b) ((a)>(b)?(b):(a))
113 #endif
114 
115 #ifndef MAX
116 /** returns larger of a and b. */
117 #define MAX(a,b) ((a)>=(b)?(a):(b))
118 #endif
119 
120 #ifndef ABS
121 /** returns absolute value of a (|a|) */
122 #define ABS(a) ((a)>=0?(a):-(a))
123 #endif
124 
125 #ifndef SIGN
126 /** return +1 for a > 0, -1 for a < 0 */
127 #define SIGN(a) ((a)>0?1:((a)<0?-1:0))
128 #endif
129 
130 /* low-level ANSI-style functions */
131 
132 #ifndef _NCBISTD_ /* if we're not in the C toolkit ... */
133 
134 #ifndef UINT4_MAX
135 /** largest number represented by unsigned int. */
136 #define UINT4_MAX 4294967295U
137 #endif
138 
139 #ifndef INT4_MAX
140 /** largest nubmer represented by signed int */
141 #define INT4_MAX 2147483647
142 #endif
143 
144 #ifndef INT4_MIN
145 /** Smallest (most negative) number represented by signed int */
146 #define INT4_MIN (-2147483647-1)
147 #endif
148 
149 #ifndef NCBIMATH_LN2
150 /** natural log of 2. */
151 #define NCBIMATH_LN2 0.69314718055994530941723212145818
152 #endif
153 
154 #ifndef INT2_MAX
155 /** largest number represented by signed (two byte) short */
156 #define INT2_MAX 32767
157 #endif
158 
159 #ifndef INT2_MIN
160 /** smallest (most negative) number represented by signed (two byte) short */
161 #define INT2_MIN (-32768)
162 #endif
163 
164 #ifndef INT1_MAX
165 /** largest number represented by signed short (one byte) */
166 #define INT1_MAX 127
167 #endif
168 
169 #ifndef INT1_MIN
170 /** smallest (most negative) number represented by signed short (one byte) */
171 #define INT1_MIN (-128)
172 #endif
173 
174 #ifndef DIM
175 /** dimension of an array. */
176 #define DIM(A) (sizeof(A)/sizeof((A)[0]))
177 #endif
178 
179 #ifndef NULLB
180 /** terminating byte of a char* string. */
181 #define NULLB '\0'
182 #endif
183 
184 #endif /* _NCBISTD_ */
185 
186 /** 64-bit integers */
187 #ifndef NCBI_CONST_INT8 /* C Toolkit */
188 # ifdef INT64_C /* stdint.h should have this */
189 # define NCBI_CONST_INT8(v) INT64_C(v)
190 # define NCBI_CONST_UINT8(v) UINT64_C(v)
191 # elif defined(_MSC_VER)
192 # define NCBI_CONST_INT8(v) v##i64
193 # define NCBI_CONST_UINT8(v) v##ui64
194 # else /* Try treating as (unsigned) long long */
195 # define NCBI_CONST_INT8(v) v##LL
196 # define NCBI_CONST_UINT8(v) v##ULL
197 # endif
198 #endif
199 
200 /** Copies memory using memcpy and malloc
201  * @param orig memory to be copied [in]
202  * @param size amount to be copied [in]
203  * @return pointer to newly allocated memory. NULL if orig NULL, size is zero,
204  * or allocation fails.
205  */
207 void* BlastMemDup (const void *orig, size_t size);
208 
209 
210 /******************************************************************************/
211 
212 /** A generic linked list node structure */
213 typedef struct ListNode {
214  Uint1 choice; /**< to pick a choice */
215  void *ptr; /**< attached data */
216  struct ListNode *next; /**< next in linked list */
218 
219 /** Create a new list node
220  * @param vnp Pointer to the start of the list, may be NULL [in]
221  * @return newly allocated node
222  */
225 
226 /** Add a node to the list.
227  * @param head Pointer to the start of the list, if *head is NULL will
228  * be Pointer to new node. [in] [out]
229  * @return New node
230  */
233 
234 /** Add a node to the list with a given choice and data pointer.
235  * @param head Pointer to the start of the list, if *head is NULL will
236  * be Pointer to new node. [in] [out]
237  * @param choice Choice value for the new node. [in]
238  * @param value Data pointer for the new node. [in]
239  * @return New node
240  */
243 
244 /** Free all list's nodes, does not attempt to free data.
245  * @param vnp objects to be freed [in]
246  * @return NULL
247  */
250 
251 /** Free nodes as well as data (vnp->ptr) assuming it is one contiguous chunk.
252  * @param vnp objects to be freed [in]
253  * @return NULL
254  */
257 
258 /** Add a node to the list with a provided choice, and attached data
259  * pointing to a provided string.
260  * @param head Pointer to the start of the list, if *head is NULL will
261  * be Pointer to new node. [in] [out]
262  * @param choice sets the "choice" field in ListNode [in]
263  * @param str char* buffer to be copied [in]
264  * @return newly allocated node
265  */
268 
269 #ifdef __cplusplus
270 }
271 #endif
272 
273 #endif /* !ALGO_BLAST_CORE__NCBI_STD */
Defines to provide correct exporting from BLAST DLL in Windows.
#define NCBI_XBLAST_EXPORT
NULL operations for other cases.
Definition: blast_export.h:65
Choose C++ basic defines.
#define head
Definition: ct_nlmzip_i.h:138
static const char * str(char *buf, int n)
Definition: stats.c:84
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
where boath are integers</td > n< td ></td > n</tr > n< tr > n< td > tse</td > n< td > optional</td > n< td > String</td > n< td class=\"description\"> TSE option controls what blob is orig
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
ListNode * ListNodeNew(ListNode *vnp)
Create a new list node.
Definition: ncbi_std.c:55
ListNode * ListNodeCopyStr(ListNode **head, Uint1 choice, const char *str)
Add a node to the list with a provided choice, and attached data pointing to a provided string.
Definition: ncbi_std.c:124
struct ListNode ListNode
A generic linked list node structure.
ListNode * ListNodeAdd(ListNode **head)
Add a node to the list.
Definition: ncbi_std.c:77
void * BlastMemDup(const void *orig, size_t size)
Copies memory using memcpy and malloc.
Definition: ncbi_std.c:35
Uint1 Boolean
bool replacment for C
Definition: ncbi_std.h:94
ListNode * ListNodeAddPointer(ListNode **head, Uint1 choice, void *value)
Add a node to the list with a given choice and data pointer.
Definition: ncbi_std.c:99
ListNode * ListNodeFreeData(ListNode *vnp)
Free nodes as well as data (vnp->ptr) assuming it is one contiguous chunk.
Definition: ncbi_std.c:169
ListNode * ListNodeFree(ListNode *vnp)
Free all list's nodes, does not attempt to free data.
Definition: ncbi_std.c:148
A generic linked list node structure.
Definition: ncbi_std.h:213
void * ptr
attached data
Definition: ncbi_std.h:215
struct ListNode * next
next in linked list
Definition: ncbi_std.h:216
Uint1 choice
to pick a choice
Definition: ncbi_std.h:214
Modified on Fri Jun 14 16:47:00 2024 by modify_doxy.py rev. 669887