loaders: Create generic metadata storage.
[gfxprim.git] / include / loaders / GP_MetaData.h
blob2820ee0891671d46233b288108dce1ae74de44e3
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2012 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #ifndef LOADERS_METADATA_H
24 #define LOADERS_METADATA_H
26 #define GP_META_RECORD_ID_MAX 16
28 enum GP_MetaType {
29 GP_META_INT,
30 GP_META_STRING,
33 union GP_MetaValue {
34 int i;
35 const char *str;
38 typedef struct GP_MetaRecord {
39 char id[GP_META_RECORD_ID_MAX];
40 unsigned int hash;
41 enum GP_MetaType type;
42 struct GP_MetaRecord *next;
43 union GP_MetaValue val;
44 } GP_MetaRecord;
46 typedef struct GP_MetaData GP_MetaData;
49 * Creates a metadata storage for at least expected_records values.
51 * Returns NULL if allocation has failed.
53 GP_MetaData *GP_MetaDataCreate(unsigned int expected_records);
56 * Destroys metadata (frees all alocated memory).
58 void GP_MetaDataDestroy(GP_MetaData *self);
61 * Prints metadata into the stdout.
63 void GP_MetaDataPrint(GP_MetaData *self);
66 * Looks for metadata record with id.
68 GP_MetaRecord *GP_MetaDataGetRecord(GP_MetaData *self, const char *id);
71 * Looks for integer metadata with id. Returns 0 on success and res is set to
72 * found metadata value.
74 int GP_MetaDataGetInt(GP_MetaData *self, const char *id, int *res);
77 * Looks for string metadata by id. Returns pointe to found string, or NULL if
78 * there was no such value.
80 const char *GP_MetaDataGetString(GP_MetaData *self, const char *id);
83 * Creates an record and returns pointer to it.
85 * May return NULL if allocation has failed.
87 GP_MetaRecord *GP_MetaDataCreateRecord(GP_MetaData *self, const char *id);
90 * Creates an integer record and returns pointer to it.
92 GP_MetaRecord *GP_MetaDataCreateInt(GP_MetaData *self, const char *id, int val);
95 * Creates an string record and returns pointer to it.
97 * If dup is set to 1, the string is duplicated inside of the MetaData
98 * structure, otherwise only the pointer is saved.
100 GP_MetaRecord *GP_MetaDataCreateString(GP_MetaData *self, const char *id,
101 const char *str, int dup);
103 #endif /* LOADERS_GP_METADATA_H */