4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 // Key/value table with persistent storage in stringfiles.
30 #include "bcwindowbase.inc"
31 #include "bctextbox.inc"
39 BC_Hash(const char *filename);
42 int load_file(FILE *fp);
43 int load(); // load from disk file
44 int save_file(FILE *fp);
45 int save(); // save to disk file
46 int load_string(const char *string); // load from string
47 int save_string(char* &string); // save to new string
48 int update(const char *name, double value); // update a value if it exists
49 int update(const char *name, float value); // update a value if it exists
50 int update(const char *name, int32_t value); // update a value if it exists
51 int update(const char *name, int64_t value); // update a value if it exists
52 int update(const char *name, const char *value); // create it if it doesn't
54 double get(const char *name, double default_); // retrieve a value if it exists
55 float get(const char *name, float default_); // retrieve a value if it exists
56 int32_t get(const char *name, int32_t default_); // retrieve a value if it exists
57 int64_t get(const char *name, int64_t default_); // retrieve a value if it exists
58 char* get(const char *name, char *default_); // return 1 if it doesn't
60 // same as above using vararg format to specify name
61 int updatef(double value, const char *fmt, ...);
62 int updatef(float value, const char *fmt, ...);
63 int updatef(int32_t value, const char *fmt, ...);
64 int updatef(int64_t value, const char *fmt, ...);
65 int updatef(const char *value, const char *fmt, ...);
67 double getf(double default_, const char *fmt, ...);
68 float getf(float default_, const char *fmt, ...);
69 int32_t getf(int32_t default_, const char *fmt, ...);
70 int64_t getf(int64_t default_, const char *fmt, ...);
71 char* getf(char *default_, const char *fmt, ...);
73 // Update values with values from another table.
74 // Adds values that don't exist and updates existing values.
75 void copy_from(BC_Hash *src);
76 // Return 1 if the tables are equivalent
77 int equivalent(BC_Hash *src);
82 char* get_key(int number);
83 char* get_value(int number);
87 // Reallocate table so at least total entries exist
88 void reallocate_table(int total);
90 char **names; // list of string names
91 char **values; // list of values
92 int total; // number of defaults
93 int allocated; // allocated defaults
94 char filename[BCTEXTLEN]; // filename the defaults are stored in