loaders: Add meta-data clear method and double type.
[gfxprim.git] / include / loaders / GP_MetaData.h
blob4da30f18e174035e0aa63fb4ff245d4431df059e
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,
31 GP_META_DOUBLE,
34 union GP_MetaValue {
35 int i;
36 double d;
37 const char *str;
40 typedef struct GP_MetaRecord {
41 char id[GP_META_RECORD_ID_MAX];
42 unsigned int hash;
43 enum GP_MetaType type;
44 struct GP_MetaRecord *next;
45 union GP_MetaValue val;
46 } GP_MetaRecord;
48 typedef struct GP_MetaData GP_MetaData;
51 * Creates a metadata storage for at least expected_records values.
53 * Returns NULL if allocation has failed.
55 GP_MetaData *GP_MetaDataCreate(unsigned int expected_records);
58 * Clears meta-data storage.
60 void GP_MetaDataClear(GP_MetaData *self);
63 * Destroys metadata (frees all alocated memory).
65 void GP_MetaDataDestroy(GP_MetaData *self);
68 * Prints metadata into the stdout.
70 void GP_MetaDataPrint(GP_MetaData *self);
73 * Looks for metadata record with id.
75 GP_MetaRecord *GP_MetaDataGetRecord(GP_MetaData *self, const char *id);
78 * Looks for integer metadata with id. Returns 0 on success and res is set to
79 * found metadata value.
81 int GP_MetaDataGetInt(GP_MetaData *self, const char *id, int *res);
84 * Looks for string metadata by id. Returns pointe to found string, or NULL if
85 * there was no such value.
87 const char *GP_MetaDataGetString(GP_MetaData *self, const char *id);
90 * Creates an record and returns pointer to it.
92 * May return NULL if allocation has failed.
94 GP_MetaRecord *GP_MetaDataCreateRecord(GP_MetaData *self, const char *id);
97 * Creates an integer record and returns pointer to it.
99 GP_MetaRecord *GP_MetaDataCreateInt(GP_MetaData *self, const char *id, int val);
102 * Creates an double record and returns pointer to it.
104 GP_MetaRecord *GP_MetaDataCreateDouble(GP_MetaData *self, const char *id,
105 double val);
108 * Creates an string record and returns pointer to it.
110 * If dup is set to 1, the string is duplicated inside of the MetaData
111 * structure, otherwise only the pointer is saved.
113 GP_MetaRecord *GP_MetaDataCreateString(GP_MetaData *self, const char *id,
114 const char *str, int dup);
116 #endif /* LOADERS_GP_METADATA_H */