Ion C
C library for Ion
ion_types.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at:
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
12  * language governing permissions and limitations under the License.
13  */
14 
23 #ifndef ION_TYPES_H_
24 #define ION_TYPES_H_
25 
26 #include "ion_errors.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stdint.h>
33 #include <decNumber/decQuad.h>
34 #include <decNumber/decNumber.h>
35 
36 #ifdef ION_INIT
37  #define GLOBAL ION_API_EXPORT
38  #define INITTO(x) = x
39  #define INIT_STATICS
40 #else
41  #define GLOBAL extern
42  #define INITTO(x) /* nothing */
43  #ifdef INIT_STATICS
44  #undef INIT_STATICS
45  #endif
46 #endif
47 
48 #ifndef NULL
49 #define NULL ((void *)0)
50 #endif
51 
52 #ifndef TRUE
53 #define TRUE 1
54 #define FALSE 0
55 #endif
56 
57 #ifndef MAX_INT32
58 #define MAX_INT32 0x7FFFFFFF // 2,147,483,647
59 #define MIN_INT32 -0x7FFFFFFF-1 // -2,147,483,648
60 #endif
61 
62 #ifndef MAX_INT64
63 #define MAX_INT64 0x7FFFFFFFFFFFFFFFLL
64 #define MIN_INT64 -0x7FFFFFFFFFFFFFFFLL-1
65 #define HIGH_BIT_INT64 (((uint64_t)(1)) << 63)
66 #endif
67 
69 typedef struct ion_type *ION_TYPE;
70 #define ION_TYPE_INT(x) ((intptr_t) (x))
71 
75 #define tid_none ((ION_TYPE)(tid_none_INT))
76 
80 #define tid_EOF ((ION_TYPE)(tid_EOF_INT))
81 
85 #define tid_NULL ((ION_TYPE) tid_NULL_INT)
86 #define tid_BOOL ((ION_TYPE) tid_BOOL_INT)
87 #define tid_INT ((ION_TYPE) tid_INT_INT)
88 #define tid_FLOAT ((ION_TYPE) tid_FLOAT_INT)
89 #define tid_DECIMAL ((ION_TYPE) tid_DECIMAL_INT)
90 #define tid_TIMESTAMP ((ION_TYPE) tid_TIMESTAMP_INT)
91 #define tid_SYMBOL ((ION_TYPE) tid_SYMBOL_INT)
92 #define tid_STRING ((ION_TYPE) tid_STRING_INT)
93 #define tid_CLOB ((ION_TYPE) tid_CLOB_INT)
94 #define tid_BLOB ((ION_TYPE) tid_BLOB_INT)
95 #define tid_LIST ((ION_TYPE) tid_LIST_INT)
96 #define tid_SEXP ((ION_TYPE) tid_SEXP_INT)
97 #define tid_STRUCT ((ION_TYPE) tid_STRUCT_INT)
98 #define tid_DATAGRAM ((ION_TYPE) tid_DATAGRAM_INT)
99 
100 #define tid_none_INT -0x200
101 #define tid_EOF_INT -0x100
102 #define tid_NULL_INT 0x000
103 #define tid_BOOL_INT 0x100
104 #define tid_INT_INT 0x200
105 #define tid_FLOAT_INT 0x400
106 #define tid_DECIMAL_INT 0x500
107 #define tid_TIMESTAMP_INT 0x600
108 #define tid_SYMBOL_INT 0x700
109 #define tid_STRING_INT 0x800
110 #define tid_CLOB_INT 0x900
111 #define tid_BLOB_INT 0xA00
112 #define tid_LIST_INT 0xB00
113 #define tid_SEXP_INT 0xC00
114 #define tid_STRUCT_INT 0xD00
115 #define tid_DATAGRAM_INT 0xF00
116 
117 typedef int32_t SID;
118 typedef int32_t SIZE;
119 typedef uint8_t BYTE;
120 typedef int BOOL;
121 #define MAX_SIZE INT32_MAX
122 
123 //
124 // forward references of pointers for linked lists
125 //
126 typedef struct _ion_symbol_table ION_SYMBOL_TABLE;
127 typedef struct _ion_catalog ION_CATALOG;
128 
134 typedef struct _ion_string ION_STRING;
135 typedef struct _ion_symbol ION_SYMBOL;
136 
137 typedef struct _ion_symbol_table_import_descriptor ION_SYMBOL_TABLE_IMPORT_DESCRIPTOR;
138 typedef struct _ion_symbol_table_import ION_SYMBOL_TABLE_IMPORT;
139 
140 typedef struct _ion_reader ION_READER;
141 typedef struct _ion_writer ION_WRITER;
142 typedef struct _ion_int ION_INT;
143 typedef struct _ion_decimal ION_DECIMAL;
144 typedef struct _ion_timestamp ION_TIMESTAMP;
145 typedef struct _ion_collection ION_COLLECTION;
146 
147 #ifndef ION_STREAM_DECL
148 #define ION_STREAM_DECL
149 
150 // needed when the stream is used outside the context of the
151 // general Ion library. Otherwise this must be defined in the
152 // Ion type header (ion_types.h).
153 typedef struct _ion_stream ION_STREAM;
154 
155 // decl's for user managed stream
156 struct _ion_user_stream;
157 typedef iERR (*ION_STREAM_HANDLER)(struct _ion_user_stream *pstream);
159 {
160  BYTE *curr;
161  BYTE *limit;
162  void *handler_state;
163  ION_STREAM_HANDLER handler;
164 };
165 
166 #endif
167 
168 // some public pointers to these, which we don't really need
169 // and should be changed TODO
170 typedef ION_STRING *iSTRING;
171 typedef ION_SYMBOL *iSYMBOL;
172 typedef ION_SYMBOL_TABLE_IMPORT *iIMPORT;
173 typedef ION_SYMBOL_TABLE *iSYMTAB;
174 typedef ION_CATALOG *iCATALOG;
175 typedef ION_STREAM *iSTREAM;
176 typedef ION_TIMESTAMP *iTIMESTAMP;
177 
178 // TODO: switch to: typedef struct _ion_catalog_proxy *hCATALOG;
179 typedef void *hOWNER;
180 typedef ION_READER *hREADER;
181 typedef ION_WRITER *hWRITER;
182 typedef ION_SYMBOL_TABLE *hSYMTAB;
183 typedef ION_CATALOG *hCATALOG;
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif
190 
struct ion_type * ION_TYPE
Definition: ion_types.h:69
Definition: ion_collection.h:72
Definition: ion_decimal.h:89
Definition: ion_int.h:100
Definition: ion_string.h:40
Definition: ion_symbol_table.h:34
Definition: ion_timestamp.h:47
Definition: ion_types.h:159