comparison src/core/save.h @ 84:a6c2067709ce

core: implement basic save routines, closes #2476 @2h
author David Demelier <markand@malikania.fr>
date Sat, 07 Mar 2020 17:06:01 +0100
parents
children
comparison
equal deleted inserted replaced
83:f5d3e469eb93 84:a6c2067709ce
1 /*
2 * save.h -- save functions
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_SAVE_H
20 #define MOLKO_SAVE_H
21
22 /**
23 * \file save.h
24 * \brief Save functions.
25 */
26
27 #include <stdbool.h>
28
29 /**
30 * \brief Max property value.
31 */
32 #define SAVE_PROPERTY_VALUE_MAX 1024
33
34 /**
35 * Open a database by index.
36 *
37 * This function use the preferred path to store local files under the user
38 * home directory. The parameter idx specifies the save slot to use.
39 *
40 * \param idx the save slot
41 * \return false on error
42 */
43 bool
44 save_open(unsigned int idx);
45
46 /**
47 * Open the save slot specified by path.
48 *
49 * \pre path != NULL
50 * \param path the path to the save slot
51 * \return false on error
52 */
53 bool
54 save_open_path(const char *path);
55
56 /**
57 * Sets an arbitrary property.
58 *
59 * If the property already exists, replace it.
60 *
61 * \pre key != NULL
62 * \pre value != NULL && strlen(value) <= SAVE_PROPERTY_VALUE_MAX
63 * \param key the property key
64 * \param value the property value
65 */
66 bool
67 save_set_property(const char *key, const char *value);
68
69 /**
70 * Get a property.
71 *
72 * \pre key != NULL
73 * \param key the property key
74 * \return the key or NULL if not found
75 */
76 const char *
77 save_get_property(const char *key);
78
79 /**
80 * Remove a property.
81 *
82 * \pre key != NULL
83 * \param key the property key
84 * \return false on error
85 */
86 bool
87 save_remove_property(const char *key);
88
89 /**
90 * Close the save slot.
91 */
92 void
93 save_finish(void);
94
95 #endif /* !MOLKO_SAVE_H */