1 #if !defined( TABLE_INCLUDED )  /* Include this file only once */
2 #define TABLE_INCLUDED
3 /*
4 *+
5 *  Name:
6 *     table.h
7 
8 *  Type:
9 *     C include file.
10 
11 *  Purpose:
12 *     Define the interface to the Table class.
13 
14 *  Invocation:
15 *     #include "table.h"
16 
17 *  Description:
18 *     This include file defines the interface to the Table class and
19 *     provides the type definitions, function prototypes and macros,
20 *     etc. needed to use this class.
21 
22 *  Inheritance:
23 *     The Table class inherits from the KeyMap class.
24 
25 *  Copyright:
26 *     Copyright (C) 2010 Science & Technology Facilities Council.
27 *     All Rights Reserved.
28 
29 *  Licence:
30 *     This program is free software: you can redistribute it and/or
31 *     modify it under the terms of the GNU Lesser General Public
32 *     License as published by the Free Software Foundation, either
33 *     version 3 of the License, or (at your option) any later
34 *     version.
35 *
36 *     This program is distributed in the hope that it will be useful,
37 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
38 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39 *     GNU Lesser General Public License for more details.
40 *
41 *     You should have received a copy of the GNU Lesser General
42 *     License along with this program.  If not, see
43 *     <http://www.gnu.org/licenses/>.
44 
45 *  Authors:
46 *     DSB: David S. Berry (Starlink)
47 
48 *  History:
49 *     22-NOV-2010 (DSB):
50 *        Original version.
51 *-
52 */
53 
54 /* Include files. */
55 /* ============== */
56 /* Interface definitions. */
57 /* ---------------------- */
58 #include "keymap.h"              /* Parent class */
59 
60 #if defined(astCLASS)            /* Protected */
61 #include "channel.h"             /* I/O channels */
62 #endif
63 
64 /* C header files. */
65 /* --------------- */
66 #if defined(astCLASS)            /* Protected */
67 #include <stddef.h>
68 #endif
69 
70 /* Macros */
71 /* ====== */
72 
73 /* Define a dummy __attribute__ macro for use on non-GNU compilers. */
74 #ifndef __GNUC__
75 #  define  __attribute__(x)  /*NOTHING*/
76 #endif
77 
78 #if defined(astCLASS)            /* Protected */
79 
80 /* Maximum length of a column name */
81 #define AST__MXCOLNAMLEN 100
82 
83 /* Maximum length of a key for a column cell */
84 #define AST__MXCOLKEYLEN ( AST__MXCOLNAMLEN + 23 )
85 
86 #endif
87 
88 
89 /* Type Definitions. */
90 /* ================= */
91 /* Table structure. */
92 /* ----------------- */
93 /* This structure contains all information that is unique to each
94    object in the class (e.g. its instance variables). */
95 typedef struct AstTable {
96 
97 /* Attributes inherited from the parent class. */
98    AstKeyMap keymap;             /* Parent class structure */
99 
100 /* Attributes specific to objects in this class. */
101    int nrow;                     /* Mo. of rows in table */
102    AstKeyMap *columns;           /* KeyMap holding column definitions */
103    AstKeyMap *parameters;        /* KeyMap holding parameter definitions */
104 } AstTable;
105 
106 /* Virtual function table. */
107 /* ----------------------- */
108 /* This table contains all information that is the same for all
109    objects in the class (e.g. pointers to its virtual functions). */
110 #if defined(astCLASS)            /* Protected */
111 typedef struct AstTableVtab {
112 
113 /* Properties (e.g. methods) inherited from the parent class. */
114    AstKeyMapVtab keymap_vtab;  /* Parent class virtual function table */
115 
116 /* A Unique identifier to determine class membership. */
117    AstClassIdentifier id;
118 
119 /* Properties (e.g. methods) specific to this class. */
120    AstKeyMap *(* ColumnProps)( AstTable *, int * );
121    AstKeyMap *(* ParameterProps)( AstTable *, int * );
122    const char *(* ColumnName)( AstTable *, int, int * );
123    const char *(* ParameterName)( AstTable *, int, int * );
124    const char *(* GetColumnUnit)( AstTable *, const char *, int * );
125    int (* GetColumnLenC)( AstTable *, const char *, int * );
126    int (* GetColumnLength)( AstTable *, const char *, int * );
127    int (* GetColumnNdim)( AstTable *, const char *, int * );
128    int (* GetColumnType)( AstTable *, const char *, int * );
129    int (* GetNcolumn)( AstTable *, int * );
130    int (* GetNparameter)( AstTable *, int * );
131    int (* GetNrow)( AstTable *, int * );
132    int (* HasColumn)( AstTable *, const char *, int * );
133    int (* HasParameter)( AstTable *, const char *, int * );
134    void (* AddColumn)( AstTable *, const char *, int, int, int *, const char *, int * );
135    void (* AddParameter)( AstTable *, const char *, int * );
136    void (* ColumnShape)( AstTable *, const char *, int, int *, int *, int * );
137    void (* PurgeRows)( AstTable *, int * );
138    void (* RemoveColumn)( AstTable *, const char *, int * );
139    void (* RemoveParameter)( AstTable *, const char *, int * );
140    void (* RemoveRow)( AstTable *, int, int * );
141    void (* SetNrow)( AstTable *, int, int * );
142 } AstTableVtab;
143 
144 #if defined(THREAD_SAFE)
145 
146 /* Define a structure holding all data items that are global within the
147    object.c file. */
148 
149 typedef struct AstTableGlobals {
150    AstTableVtab Class_Vtab;
151    int Class_Init;
152    char GetAttrib_Buff[ 101 ];
153 } AstTableGlobals;
154 
155 
156 /* Thread-safe initialiser for all global data used by this module. */
157 void astInitTableGlobals_( AstTableGlobals * );
158 
159 #endif
160 
161 
162 #endif
163 
164 /* Function prototypes. */
165 /* ==================== */
166 /* Prototypes for standard class functions. */
167 /* ---------------------------------------- */
168 astPROTO_CHECK(Table)           /* Check class membership */
169 astPROTO_ISA(Table)             /* Test class membership */
170 
171 /* Constructor. */
172 #if defined(astCLASS)            /* Protected. */
173 AstTable *astTable_( const char *, int *, ...);
174 #else
175 AstTable *astTableId_( const char *, ... )__attribute__((format(printf,1,2)));
176 #endif
177 
178 #if defined(astCLASS)            /* Protected */
179 
180 /* Initialiser. */
181 AstTable *astInitTable_( void *, size_t, int, AstTableVtab *,
182                          const char *, int * );
183 
184 /* Vtab initialiser. */
185 void astInitTableVtab_( AstTableVtab *, const char *, int * );
186 
187 /* Loader. */
188 AstTable *astLoadTable_( void *, size_t, AstTableVtab *,
189                          const char *, AstChannel *, int * );
190 #endif
191 
192 /* Prototypes for member functions. */
193 /* -------------------------------- */
194 void astAddColumn_( AstTable *, const char *, int, int, int *, const char *, int * );
195 void astAddParameter_( AstTable *, const char *, int * );
196 void astRemoveColumn_( AstTable *, const char *, int * );
197 void astRemoveParameter_( AstTable *, const char *, int * );
198 void astRemoveRow_( AstTable *, int, int * );
199 void astPurgeRows_( AstTable *, int * );
200 const char *astColumnName_( AstTable *, int, int * );
201 const char *astParameterName_( AstTable *, int, int * );
202 void astColumnShape_( AstTable *, const char *, int, int *, int *, int * );
203 int astHasColumn_( AstTable *, const char *, int * );
204 int astHasParameter_( AstTable *, const char *, int * );
205 
206 #if defined(astCLASS)            /* Protected */
207 AstKeyMap *astColumnProps_( AstTable *, int * );
208 AstKeyMap *astParameterProps_( AstTable *, int * );
209 const char *astGetColumnUnit_( AstTable *, const char *, int * );
210 int astGetColumnLenC_( AstTable *, const char *, int * );
211 int astGetColumnLength_( AstTable *, const char *, int * );
212 int astGetColumnNdim_( AstTable *, const char *, int * );
213 int astGetColumnType_( AstTable *, const char *, int * );
214 int astGetNcolumn_( AstTable *, int * );
215 int astGetNparameter_( AstTable *, int * );
216 int astGetNrow_( AstTable *, int * );
217 void astSetNrow_( AstTable *, int, int * );
218 #endif
219 
220 /* Function interfaces. */
221 /* ==================== */
222 /* These macros are wrap-ups for the functions defined by this class
223    to make them easier to invoke (e.g. to avoid type mis-matches when
224    passing pointers to objects from derived classes). */
225 
226 /* Interfaces to standard class functions. */
227 /* --------------------------------------- */
228 /* Some of these functions provide validation, so we cannot use them
229    to validate their own arguments. We must use a cast when passing
230    object pointers (so that they can accept objects from derived
231    classes). */
232 
233 /* Check class membership. */
234 #define astCheckTable(this) astINVOKE_CHECK(Table,this,0)
235 #define astVerifyTable(this) astINVOKE_CHECK(Table,this,1)
236 
237 /* Test class membership. */
238 #define astIsATable(this) astINVOKE_ISA(Table,this)
239 
240 /* Constructor. */
241 #if defined(astCLASS)            /* Protected. */
242 #define astTable astINVOKE(F,astTable_)
243 #else
244 #define astTable astINVOKE(F,astTableId_)
245 #endif
246 
247 #if defined(astCLASS)            /* Protected */
248 
249 /* Initialiser. */
250 #define astInitTable(mem,size,init,vtab,name) \
251 astINVOKE(O,astInitTable_(mem,size,init,vtab,name,STATUS_PTR))
252 
253 /* Vtab Initialiser. */
254 #define astInitTableVtab(vtab,name) astINVOKE(V,astInitTableVtab_(vtab,name,STATUS_PTR))
255 /* Loader. */
256 #define astLoadTable(mem,size,vtab,name,channel) \
257 astINVOKE(O,astLoadTable_(mem,size,vtab,name,astCheckChannel(channel),STATUS_PTR))
258 #endif
259 
260 /* Interfaces to public member functions. */
261 /* -------------------------------------- */
262 /* Here we make use of astCheckTable to validate Table pointers
263    before use.  This provides a contextual error report if a pointer
264    to the wrong sort of Object is supplied. */
265 
266 #define astAddColumn(this,name,type,ndim,dims,unit) astINVOKE(V,astAddColumn_(astCheckTable(this),name,type,ndim,dims,unit, STATUS_PTR))
267 #define astAddParameter(this,name) astINVOKE(V,astAddParameter_(astCheckTable(this),name,STATUS_PTR))
268 #define astRemoveColumn(this,name) astINVOKE(V,astRemoveColumn_(astCheckTable(this),name,STATUS_PTR))
269 #define astRemoveParameter(this,name) astINVOKE(V,astRemoveParameter_(astCheckTable(this),name,STATUS_PTR))
270 #define astRemoveRow(this,index) astINVOKE(V,astRemoveRow_(astCheckTable(this),index,STATUS_PTR))
271 #define astPurgeRows(this) astINVOKE(V,astPurgeRows_(astCheckTable(this),STATUS_PTR))
272 #define astColumnName(this,index) astINVOKE(V,astColumnName_(astCheckTable(this),index,STATUS_PTR))
273 #define astParameterName(this,index) astINVOKE(V,astParameterName_(astCheckTable(this),index,STATUS_PTR))
274 #define astColumnShape(this,column,mxdim,ndim,dims) astINVOKE(V,astColumnShape_(astCheckTable(this),column,mxdim,ndim,dims,STATUS_PTR))
275 #define astHasColumn(this,column) astINVOKE(V,astHasColumn_(astCheckTable(this),column,STATUS_PTR))
276 #define astHasParameter(this,param) astINVOKE(V,astHasParameter_(astCheckTable(this),param,STATUS_PTR))
277 
278 #if defined(astCLASS)            /* Protected */
279 
280 #define astColumnProps(this) \
281 astINVOKE(O,astColumnProps_(astCheckTable(this),STATUS_PTR))
282 #define astParameterProps(this) \
283 astINVOKE(O,astParameterProps_(astCheckTable(this),STATUS_PTR))
284 #define astGetNcolumn(this) \
285 astINVOKE(V,astGetNcolumn_(astCheckTable(this),STATUS_PTR))
286 #define astGetNparameter(this) \
287 astINVOKE(V,astGetNparameter_(astCheckTable(this),STATUS_PTR))
288 #define astGetNrow(this) \
289 astINVOKE(V,astGetNrow_(astCheckTable(this),STATUS_PTR))
290 #define astSetNrow(this,value) \
291 astINVOKE(V,astSetNrow_(astCheckTable(this),value,STATUS_PTR))
292 #define astGetColumnLenC(this,column) \
293 astINVOKE(V,astGetColumnLenC_(astCheckTable(this),column,STATUS_PTR))
294 #define astGetColumnLength(this,column) \
295 astINVOKE(V,astGetColumnLength_(astCheckTable(this),column,STATUS_PTR))
296 #define astGetColumnNdim(this,column) \
297 astINVOKE(V,astGetColumnNdim_(astCheckTable(this),column,STATUS_PTR))
298 #define astGetColumnType(this,column) \
299 astINVOKE(V,astGetColumnType_(astCheckTable(this),column,STATUS_PTR))
300 #define astGetColumnUnit(this,column) \
301 astINVOKE(V,astGetColumnUnit_(astCheckTable(this),column,STATUS_PTR))
302 
303 #endif
304 #endif
305 
306 
307 
308 
309 
310