summaryrefslogtreecommitdiffstats
path: root/src/H5M.c
blob: 57a042e9d732a750f088d6e12fe2687fd52b7708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/****************************************************************************
* NCSA HDF                                                                 *
* Software Development Group                                               *
* National Center for Supercomputing Applications                          *
* University of Illinois at Urbana-Champaign                               *
* 605 E. Springfield, Champaign IL 61820                                   *
*                                                                          *
* For conditions of distribution and use, see the accompanying             *
* hdf/COPYING file.                                                        *
*                                                                          *
****************************************************************************/

#ifdef RCSID
static char RcsId[] = "@(#)$Revision$";
#endif

/* $Id$ */

/*LINTLIBRARY */
/*+
   FILE
       hdf5meta.c
   HDF5 "Meta-Object" routines

   EXPORTED ROUTINES
       H5Mcreate    -- Create an object
       H5Mcopy      -- Copy an object
       H5Mget_file  -- Get the file ID for an object
       H5Mrelease   -- Release access to an object

   LIBRARY-SCOPED ROUTINES

   LOCAL ROUTINES
       H5M_init_interface    -- initialize the interface
   + */

#include "hdf5.h"
#include "H5private.h"  /* Generic functions */
#include "H5Cproto.h"   /* Template interface */
#include "H5Tproto.h"   /* Datatype interface */
#include "H5Mprivate.h" /* Meta-object interface */
#include "H5Cprivate.h"   /* Template interface */

#define PABLO_MASK	H5M_mask

/*--------------------- Locally scoped variables -----------------------------*/

/* Whether we've installed the library termination function yet for this interface */
static intn interface_initialize_g = FALSE;

/*------------------_-- Local function prototypes ----------------------------*/
static herr_t H5M_init_interface(void);

/*--------------------------------------------------------------------------
NAME
   H5M_init_interface -- Initialize interface-specific information
USAGE
    herr_t H5M_init_interface()
   
RETURNS
   SUCCEED/FAIL
DESCRIPTION
    Initializes any interface-specific data or routines.

MODIFICATIONS
    Robb Matzke, 4 Aug 1997
    Changed the FUNC variable value to H5M_init_interface.

--------------------------------------------------------------------------*/
static herr_t H5M_init_interface(void)
{
    herr_t ret_value = SUCCEED;
    FUNC_ENTER (H5M_init_interface, NULL, FAIL);

    FUNC_LEAVE(ret_value);
}	/* H5M_init_interface */

/*--------------------------------------------------------------------------
 NAME
    H5M_find_type
 PURPOSE
    Find the type of meta-object to issue a method call on
 USAGE
    intn H5M_find_type(type)
        hobjtype_t type;        IN: Type of object to create
 RETURNS
     Returns the index of the type in the array of methods on success, or FAIL 
        on failure.
 DESCRIPTION
        This function performs a search to find the index of the type of a 
    meta-object in the array of function pointers.
--------------------------------------------------------------------------*/
static intn H5M_find_type(hobjtype_t type)
{
    intn i;         /* local counting variable */
    intn ret_value = FAIL;

    FUNC_ENTER(H5M_find_type, H5M_init_interface, FAIL);

    /* Clear errors and check args and all the boring stuff. */
    H5ECLEAR;

    /*
     * Currently this uses a stright linear search, which can easily be changed
     * to a binary search when it becomes too slow.
     */
    for(i=0; i<(sizeof(meta_func_arr)/sizeof(meta_func_t)); i++)
        if(type==meta_func_arr[i].type)
            HGOTO_DONE(i);

done:
    if(ret_value == FAIL)   
      { /* Error condition cleanup */

      } /* end if */

    /* Normal function cleanup */

    FUNC_LEAVE(ret_value);
} /* end H5M_find_type() */

/*--------------------------------------------------------------------------
 NAME
    H5Mcreate
 PURPOSE
    Create a new HDF5 object.
 USAGE
    hatom_t H5Mcreate(owner_id, type, name)
        hatom_t owner_id;       IN: Group/file which owns this object
        hobjtype_t type;        IN: Type of object to create
        const char *name;       IN: Name of the object
 RETURNS
    Returns ID (atom) on success, FAIL on failure
 DESCRIPTION
        This function re-directs the object's creation into the appropriate
    interface, as defined by the function pointers in hdf5fptr.h
--------------------------------------------------------------------------*/
hatom_t H5Mcreate(hatom_t owner_id, hobjtype_t type, const char *name)
{
    intn i;         /* local counting variable */
    hatom_t        ret_value = SUCCEED;

    FUNC_ENTER(H5Mcreate, H5M_init_interface, FAIL);

    /* Clear errors and check args and all the boring stuff. */
    H5ECLEAR;
    if(type<=BADGROUP || type>=MAXGROUP)
        HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);

    i=H5M_find_type(type);
    if(meta_func_arr[i].create==NULL)
        HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
    ret_value=meta_func_arr[i].create(owner_id,type,name);

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

    /* Normal function cleanup */

    FUNC_LEAVE(ret_value);
} /* end H5Mcreate() */


/*--------------------------------------------------------------------------
 NAME
    H5Mcopy
 PURPOSE
    Copy an HDF5 object.
 USAGE
    hatom_t H5Mcopy(oid)
        hatom_t oid;       IN: Object to copy
 RETURNS
    SUCCEED/FAIL
 DESCRIPTION
        This function re-directs the object's copy into the appropriate
    interface, as defined by the function pointers in hdf5fptr.h
--------------------------------------------------------------------------*/
hatom_t H5Mcopy(hatom_t oid)
{
    group_t group=H5Aatom_group(oid);   /* Atom group for incoming object */
    intn i;         /* local counting variable */
    herr_t        ret_value = SUCCEED;

    FUNC_ENTER(H5Mcopy, H5M_init_interface, FAIL);

    /* Clear errors and check args and all the boring stuff. */
    H5ECLEAR;
    if(group<=BADGROUP || group>=MAXGROUP)
        HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);

    i=H5M_find_type(group);
    if(meta_func_arr[i].copy==NULL)
        HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
    ret_value=meta_func_arr[i].copy(oid);

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

    /* Normal function cleanup */

    FUNC_LEAVE(ret_value);
} /* end H5Mcopy() */

/*--------------------------------------------------------------------------
 NAME
    H5Mflush
 PURPOSE
    Flush an HDF5 object out to a file.
 USAGE
    hatom_t H5Mget_file(oid)
        hatom_t oid;       IN: Object to flush
 RETURNS
    SUCCEED/FAIL
 DESCRIPTION
        This function re-directs the object's flush into the appropriate
    interface, as defined by the function pointers in hdf5fptr.h
--------------------------------------------------------------------------*/
hatom_t H5Mflush(hatom_t oid)
{
    group_t group=H5Aatom_group(oid);   /* Atom group for incoming object */
    intn i;         /* local counting variable */
    herr_t        ret_value = SUCCEED;

    FUNC_ENTER(H5Mflush, H5M_init_interface, FAIL);

    /* Clear errors and check args and all the boring stuff. */
    H5ECLEAR;
    if(group<=BADGROUP || group>=MAXGROUP)
        HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);

    i=H5M_find_type(group);
    if(meta_func_arr[i].flush==NULL)
        HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
    ret_value=meta_func_arr[i].flush(oid);

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

    /* Normal function cleanup */

    FUNC_LEAVE(ret_value);
} /* end H5Mflush() */

/*--------------------------------------------------------------------------
 NAME
    H5Mget_file
 PURPOSE
    Get the file ID an HDF5 object.
 USAGE
    hatom_t H5Mget_file(oid)
        hatom_t oid;       IN: Object to query
 RETURNS
    SUCCEED/FAIL
 DESCRIPTION
        This function re-directs the object's query into the appropriate
    interface, as defined by the function pointers in hdf5fptr.h
--------------------------------------------------------------------------*/
hatom_t H5Mget_file(hatom_t oid)
{
    group_t group=H5Aatom_group(oid);   /* Atom group for incoming object */
    intn i;         /* local counting variable */
    herr_t        ret_value = SUCCEED;

    FUNC_ENTER(H5Mget_file, H5M_init_interface, FAIL);

    /* Clear errors and check args and all the boring stuff. */
    H5ECLEAR;
    if(group<=BADGROUP || group>=MAXGROUP)
        HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);

    i=H5M_find_type(group);
    if(meta_func_arr[i].get_file==NULL)
        HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
    ret_value=meta_func_arr[i].get_file(oid);

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

    /* Normal function cleanup */

    FUNC_LEAVE(ret_value);
} /* end H5Mget_file() */

/*--------------------------------------------------------------------------
 NAME
    H5Mrelease
 PURPOSE
    Release access to an HDF5 object.
 USAGE
    herr_t H5Mrelease(oid)
        hatom_t oid;       IN: Object to release access to
 RETURNS
    SUCCEED/FAIL
 DESCRIPTION
        This function re-directs the object's release into the appropriate
    interface, as defined by the function pointers in hdf5fptr.h
--------------------------------------------------------------------------*/
herr_t H5Mrelease(hatom_t oid)
{
    group_t group=H5Aatom_group(oid);   /* Atom group for incoming object */
    intn i;         /* local counting variable */
    herr_t        ret_value = SUCCEED;

    FUNC_ENTER(H5Mrelease, H5M_init_interface, FAIL);

    /* Clear errors and check args and all the boring stuff. */
    H5ECLEAR;
    if(group<=BADGROUP || group>=MAXGROUP)
        HGOTO_ERROR(H5E_ARGS, H5E_BADRANGE, FAIL);

    i=H5M_find_type(group);
    if(meta_func_arr[i].release==NULL)
        HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL);
    ret_value=meta_func_arr[i].release(oid);

done:
  if(ret_value == FAIL)   
    { /* Error condition cleanup */

    } /* end if */

    /* Normal function cleanup */

    FUNC_LEAVE(ret_value);
} /* end H5Mrelease() */