1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF.  The full HDF copyright notice, including       *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /* $Id$ */
15 
16 /*****************************************************************************
17 *
18 * vgint.h
19 *
20 * Part of HDF VSet interface
21 *
22 * defines library private symbols and structures used in v*.c files
23 *
24 * NOTES:
25 * This include file depends on the basic HDF *.h files hdfi.h and hdf.h.
26 * An 'S' in the comment means that that data field is saved in the HDF file.
27 *
28 ******************************************************************************/
29 
30 #ifndef _VGINT_H
31 #define _VGINT_H
32 
33 #include "H4api_adpt.h"
34 
35 #include "hfile.h"
36 
37 /* Include file for Threaded, Balanced Binary Tree implementation */
38 #include "tbbt.h"
39 
40 /*
41  * typedefs for VGROUP, VDATA and VSUBGROUP
42  */
43 typedef struct vgroup_desc VGROUP;
44 typedef struct vdata_desc VDATA;
45 typedef VDATA VSUBGROUP;
46 
47 /*
48  * -----------------------------------------------------------------
49  * structures that are part of the VDATA structure
50  * -----------------------------------------------------------------
51  */
52 
53 typedef struct symdef_struct
54   {
55       char    *name;         /* symbol name */
56       int16    type;         /* whether int, char, float etc */
57       uint16   isize;        /* field size as stored in vdata */
58       uint16   order;        /* order of field */
59   }
60 SYMDEF;
61 
62 typedef struct write_struct
63   {
64       intn     n;            /* S actual # fields in element */
65       uint16   ivsize;       /* S size of element as stored in vdata */
66 
67       char     name[VSFIELDMAX][FIELDNAMELENMAX + 1]; /* S name of each field */
68 
69       int16    len[VSFIELDMAX];   /* S length of each fieldname */
70       int16    type[VSFIELDMAX];  /* S field type */
71       uint16   off[VSFIELDMAX];   /* S field offset in element in vdata */
72       uint16   isize[VSFIELDMAX]; /* S internal (HDF) size [incl order] */
73       uint16   order[VSFIELDMAX]; /* S order of field */
74       uint16   esize[VSFIELDMAX]; /*  external (local machine) size [incl order] */
75   }
76 VWRITELIST;
77 
78 typedef struct dyn_write_struct
79   {
80       intn     n;      /* S actual # fields in element */
81       uint16   ivsize; /* S size of element as stored in vdata */
82       char     **name; /* S name of each field */
83 #ifndef OLD_WAY
84       uint16   *bptr;  /* Pointer to hold the beginning of the buffer */
85 #endif /* OLD_WAY */
86       int16    *type;  /* S field type (into bptr buffer) */
87       uint16   *off;   /* S field offset in element in vdata (into bptr buffer) */
88       uint16   *isize; /* S internal (HDF) size [incl order] (into bptr buffer) */
89       uint16   *order; /* S order of field (into bptr buffer) */
90       uint16   *esize; /* external (local machine) size [incl order] (into bptr buffer) */
91   }
92 DYN_VWRITELIST;
93 
94 /* If there are too many attrs and performance becomes a problem,
95    the vs_attr_t list defined below can be replaced by an
96    array of attr lists, each list contains attrs for 1 field.
97  */
98 typedef struct dyn_vsattr_struct
99 {
100       int32    findex;     /* which field this attr belongs to */
101       uint16   atag, aref; /* tag/ref pair of the attr     */
102 } vs_attr_t;
103 
104 typedef struct dyn_vgattr_struct
105 {
106       uint16   atag, aref; /* tag/ref pair of the attr     */
107 } vg_attr_t;
108 
109 typedef struct dyn_read_struct
110 {
111       intn      n;         /* # fields to read */
112       intn      *item;     /* index into vftable_struct */
113 } DYN_VREADLIST;
114 
115 /*
116  *  -----------------------------------------------
117  *         V G R O U P     definition
118  *  -----------------------------------------------
119  */
120 
121 struct vgroup_desc
122   {
123       uint16      otag, oref;   /* tag-ref of this vgroup */
124       HFILEID     f;            /* HDF file id  */
125       uint16      nvelt;        /* S no of objects */
126       intn        access;       /* 'r' or 'w' */
127       uint16     *tag;          /* S tag of objects */
128       uint16     *ref;          /* S ref of objects */
129       char       *vgname;       /* S name of this vgroup */
130       char       *vgclass;      /* S class name of this vgroup */
131       intn        marked;       /* =1 if new info has been added to vgroup */
132       intn        new_vg;       /* =1 if this is a new Vgroup */
133       uint16      extag, exref; /* expansion tag-ref */
134       intn        msize;        /* max size of storage arrays */
135       uint32      flags;        /* indicate which version of VG should
136                                    be written to the file */
137       int32       nattrs;       /* number of attributes */
138       vg_attr_t  *alist;        /* index of new-style attributes, by Vsetattr */
139       int32       noldattrs;    /* number of old-style attributes */
140       vg_attr_t  *old_alist;    /* refs of attributes - only used in memory to
141                 prevent repeated code in making the list; see
142                 Voldnattrs's header for details -BMR 2/4/2011 */
143       vg_attr_t  *all_alist;    /* combined list; previous approach, only keep
144                 just in case we come back to that approach; will
145                 remove it once we decide not to go back 2/16/11 */
146       int16       version, more; /* version and "more" field */
147       struct vgroup_desc *next; /* pointer to next node (for free list only) */
148   };
149 /* VGROUP */
150 
151 /*
152  *  -----------------------------------------------
153  *         V D A T A      definition
154  *  -----------------------------------------------
155  */
156 
157 struct vdata_desc
158   {
159       uint16      otag, oref;   /* tag,ref of this vdata */
160       HFILEID     f;            /* HDF file id */
161       intn        access;       /* 'r' or 'w' */
162       char        vsname[VSNAMELENMAX + 1];     /* S name of this vdata */
163       char        vsclass[VSNAMELENMAX + 1];    /* S class name of this vdata */
164       int16       interlace;    /* S  interlace as in file */
165       int32       nvertices;    /* S  #vertices in this vdata */
166       DYN_VWRITELIST  wlist;
167       DYN_VREADLIST   rlist;
168       int16       nusym;
169       SYMDEF      *usym;
170       intn        marked;       /* =1 if new info has been added to vdata */
171       intn        new_h_sz;     /* =1 if VH size changed, due to new attrs etc. */
172       intn        islinked;     /* =1 if vdata is a linked-block in file */
173 
174       uint16      extag, exref; /* expansion tag-ref */
175       uint32      flags;     /* bit 0 -- has attr
176                                 bit 1 -- "large field"
177                                 bit 2 -- "interlaced data is appendable"
178                                 bit 3-15  -- unused.   */
179       intn        nattrs;
180       vs_attr_t   *alist;    /* attribute list */
181       int16       version, more;    /* version and "more" field */
182       int32       aid;          /* access id - for LINKED blocks */
183       struct vs_instance_struct *instance;  /* ptr to the intance struct for this VData */
184       struct vdata_desc *next;  /* pointer to next node (for free list only) */
185   };                            /* VDATA */
186 
187 /* .................................................................. */
188 /* Private data structures. Unlikely to be of interest to applications */
189 /*
190    * These are just typedefs. Actual vfile_ts are declared PRIVATE and
191    * are not accessible by applications. However, you may change VFILEMAX
192    * to allow however many files to be opened.
193    *
194    * These are memory-resident copies of the tag-refs of the vgroups
195    * and vdatas for each file that is opened.
196    *
197  */
198 
199 /* this is a memory copy of a vg tag/ref found in the file */
200 typedef struct vg_instance_struct
201   {
202       int32       key;          /* key to look up with the B-tree routines */
203       /* needs to be first in the structure */
204       uintn       ref;          /* ref # of this vgroup in the file */
205       /* needs to be second in the structure */
206       intn        nattach;      /* # of current attachs to this vgroup */
207       int32       nentries;     /* # of entries in that vgroup initially */
208       VGROUP     *vg;           /* points to the vg when it is attached */
209       struct vg_instance_struct *next;  /* pointer to next node (for free list only) */
210   }
211 vginstance_t;
212 
213 /* this is a memory copy of a vs tag/ref found in the file */
214 typedef struct vs_instance_struct
215   {
216       int32       key;          /* key to look up with the B-tree routines */
217       /* needs to be first in the structure */
218       uintn       ref;          /* ref # of this vdata in the file */
219       /* needs to be second in the structure */
220       intn        nattach;      /* # of current attachs to this vdata */
221       int32       nvertices;    /* # of elements in that vdata initially */
222       VDATA      *vs;           /* points to the vdata when it is attached */
223       struct vs_instance_struct *next;  /* pointer to next node (for free list only) */
224   }
225 vsinstance_t;
226 
227 /* each vfile_t maintains 2 linked lists: one of vgs and one of vdatas
228  * that already exist or are just created for a given file.  */
229 typedef struct vfiledir_struct
230   {
231       int32            f;       /* HDF File ID */
232 
233       int32       vgtabn;       /* # of vg entries in vgtab so far */
234       TBBT_TREE  *vgtree;       /* Root of VGroup B-Tree */
235 
236       int32       vstabn;       /* # of vs entries in vstab so far */
237       TBBT_TREE  *vstree;       /* Root of VSet B-Tree */
238       intn        access;       /* the number of active pointers to this file's Vstuff */
239   }
240 vfile_t;
241 
242 /* .................................................................. */
243 
244 #if defined c_plusplus || defined __cplusplus
245 extern      "C"
246 {
247 #endif                          /* c_plusplus || __cplusplus */
248 
249 /*
250  * Library private routines for the VSet layer
251  */
252     VDATA *VSIget_vdata_node(void);
253 
254     void VSIrelease_vdata_node(VDATA *v);
255 
256     intn VSIgetvdatas(int32 id, const char *vsclass, const uintn start_vd,
257             const uintn n_vds, uint16 *refarray);
258 
259     HDFLIBAPI vsinstance_t *VSIget_vsinstance_node(void);
260 
261     HDFLIBAPI void VSIrelease_vsinstance_node(vsinstance_t *vs);
262 
263     VGROUP *VIget_vgroup_node(void);
264 
265     void VIrelease_vgroup_node(VGROUP *v);
266 
267     HDFLIBAPI vginstance_t *VIget_vginstance_node(void);
268 
269     HDFLIBAPI void VIrelease_vginstance_node(vginstance_t *vg);
270 
271     HDFLIBAPI intn VPparse_shutdown(void);
272 
273     HDFLIBAPI vfile_t *Get_vfile(HFILEID f);
274 
275     HDFLIBAPI vsinstance_t *vsinst
276                 (HFILEID f, uint16 vsid);
277 
278     HDFLIBAPI vginstance_t *vginst
279             (HFILEID f, uint16 vgid);
280 
281     HDFLIBAPI DYN_VWRITELIST *vswritelist
282                 (int32 vskey);
283 
284     HDFLIBAPI intn vpackvg
285                 (VGROUP * vg, uint8 buf[], int32 * size);
286 
287     HDFLIBAPI int32 vinsertpair
288                 (VGROUP * vg, uint16 tag, uint16 ref);
289 
290     HDFLIBAPI intn vpackvs
291                 (VDATA * vs, uint8 buf[], int32 * size);
292 
293     HDFLIBAPI VGROUP *VPgetinfo
294                 (HFILEID f,uint16 ref);
295 
296     HDFLIBAPI VDATA *VSPgetinfo
297                 (HFILEID f,uint16 ref);
298 
299     HDFLIBAPI int16 map_from_old_types
300                 (intn type);
301 
302     HDFLIBAPI void trimendblanks
303                 (char *ss);
304 
305 #if defined c_plusplus || defined __cplusplus
306 }
307 #endif                          /* c_plusplus || __cplusplus */
308 
309 #endif                          /* _VGINT_H */
310