view 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
line wrap: on
line source

/*
 * save.h -- save functions
 *
 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef MOLKO_SAVE_H
#define MOLKO_SAVE_H

/**
 * \file save.h
 * \brief Save functions.
 */

#include <stdbool.h>

/**
 * \brief Max property value.
 */
#define SAVE_PROPERTY_VALUE_MAX 1024

/**
 * Open a database by index.
 *
 * This function use the preferred path to store local files under the user
 * home directory. The parameter idx specifies the save slot to use.
 *
 * \param idx the save slot
 * \return false on error
 */
bool
save_open(unsigned int idx);

/**
 * Open the save slot specified by path.
 *
 * \pre path != NULL
 * \param path the path to the save slot
 * \return false on error
 */
bool
save_open_path(const char *path);

/**
 * Sets an arbitrary property.
 *
 * If the property already exists, replace it.
 *
 * \pre key != NULL
 * \pre value != NULL && strlen(value) <= SAVE_PROPERTY_VALUE_MAX
 * \param key the property key
 * \param value the property value
 */
bool
save_set_property(const char *key, const char *value);

/**
 * Get a property.
 *
 * \pre key != NULL
 * \param key the property key
 * \return the key or NULL if not found
 */
const char *
save_get_property(const char *key);

/**
 * Remove a property.
 *
 * \pre key != NULL
 * \param key the property key
 * \return false on error
 */
bool
save_remove_property(const char *key);

/**
 * Close the save slot.
 */
void
save_finish(void);

#endif /* !MOLKO_SAVE_H */