libsc  1.6.0
src/sc_keyvalue.h
00001 /*
00002   This file is part of the SC Library.
00003   The SC Library provides support for parallel scientific applications.
00004 
00005   Copyright (C) 2010 The University of Texas System
00006 
00007   The SC Library is free software; you can redistribute it and/or
00008   modify it under the terms of the GNU Lesser General Public
00009   License as published by the Free Software Foundation; either
00010   version 2.1 of the License, or (at your option) any later version.
00011 
00012   The SC Library is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015   Lesser General Public License for more details.
00016 
00017   You should have received a copy of the GNU Lesser General Public
00018   License along with the SC Library; if not, write to the Free Software
00019   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020   02110-1301, USA.
00021 */
00022 
00023 #ifndef SC_KEYVALUE_H
00024 #define SC_KEYVALUE_H
00025 
00026 #include <sc.h>
00027 #include <sc_containers.h>
00028 
00029 SC_EXTERN_C_BEGIN;
00030 
00031 typedef enum
00032 {
00033   SC_KEYVALUE_ENTRY_NONE = 0,
00034   SC_KEYVALUE_ENTRY_INT,
00035   SC_KEYVALUE_ENTRY_DOUBLE,
00036   SC_KEYVALUE_ENTRY_STRING,
00037   SC_KEYVALUE_ENTRY_POINTER,
00038 }
00039 sc_keyvalue_entry_type_t;
00040 
00041 typedef struct sc_keyvalue
00042 {
00043   sc_hash_t          *hash;
00044   sc_mempool_t       *value_allocator;
00045 }
00046 sc_keyvalue_t;
00047 
00048 /* Constructors / destructors */
00049 sc_keyvalue_t      *sc_keyvalue_new ();
00050 
00051 /* Arguments come in pairs of 2: static string "type:key" and value;
00052    type is a letter like the identifier names in sc_keyvalue_entry.value */
00053 sc_keyvalue_t      *sc_keyvalue_newf (int dummy, ...);
00054 sc_keyvalue_t      *sc_keyvalue_newv (va_list ap);
00055 
00056 void                sc_keyvalue_destroy (sc_keyvalue_t * kv);
00057 
00058 /* Routine to check existence of an entry
00059    returns the type if found, and SC_KEYVALUE_ENTRY_NONE otherwise */
00060 sc_keyvalue_entry_type_t sc_keyvalue_exists (sc_keyvalue_t * kv,
00061                                              const char *key);
00062 
00063 /* Routine to remove an entry
00064    returne type if found and removed, SC_KEYVALUE_ENTRY_NONE otherwise */
00065 sc_keyvalue_entry_type_t sc_keyvalue_unset (sc_keyvalue_t * kv,
00066                                             const char *key);
00067 
00068 /* Routines to extract values from keys
00069    if the key is not present then dvalue is returned */
00070 int                 sc_keyvalue_get_int (sc_keyvalue_t * kv,
00071                                          const char *key, int dvalue);
00072 double              sc_keyvalue_get_double (sc_keyvalue_t * kv,
00073                                             const char *key, double dvalue);
00074 const char         *sc_keyvalue_get_string (sc_keyvalue_t * kv,
00075                                             const char *key,
00076                                             const char *dvalue);
00077 void               *sc_keyvalue_get_pointer (sc_keyvalue_t * kv,
00078                                              const char *key, void *dvalue);
00079 
00080 /* Routines to set values for a given key */
00081 void                sc_keyvalue_set_int (sc_keyvalue_t * kv,
00082                                          const char *key, int newvalue);
00083 void                sc_keyvalue_set_double (sc_keyvalue_t * kv,
00084                                             const char *key, double newvalue);
00085 void                sc_keyvalue_set_string (sc_keyvalue_t * kv,
00086                                             const char *key,
00087                                             const char *newvalue);
00088 void                sc_keyvalue_set_pointer (sc_keyvalue_t * kv,
00089                                              const char *key, void *newvalue);
00090 
00098 typedef int         (*sc_keyvalue_foreach_t) (const char *key,
00099                                               const sc_keyvalue_entry_type_t
00100                                               type, void *entry,
00101                                               const void *u);
00102 
00103 void                sc_keyvalue_foreach (sc_keyvalue_t * kv,
00104                                          sc_keyvalue_foreach_t fn,
00105                                          void *user_data);
00106 SC_EXTERN_C_END;
00107 
00108 #endif /* !SC_KEYVALUE_H */
 All Data Structures Files Functions Variables Typedefs Defines