Change loot_db type from pointer to struct

Pass pointers to loot_db objects explicitly, rather than folding the
pointer nature of the type into the type itself. This means I can use
the same name for the internal structure as the type, which is more
sensible.
This commit is contained in:
Oliver Hamlet
2015-12-12 09:39:39 +00:00
parent 657457de3d
commit c17c336c2b
5 changed files with 34 additions and 34 deletions
+1 -1
View File
@@ -152,7 +152,7 @@ set (LOOT_API_SRC ${LOOT_SRC}
set (LOOT_API_HEADERS ${LOOT_HEADERS}
"${CMAKE_SOURCE_DIR}/include/loot/api.h"
"${CMAKE_SOURCE_DIR}/src/api/_loot_db_int.h")
"${CMAKE_SOURCE_DIR}/src/api/loot_db.h")
set (LOOT_VALIDATOR_SRC ${LOOT_SRC}
"${CMAKE_SOURCE_DIR}/src/validator/main.cpp")
+14 -14
View File
@@ -184,7 +184,7 @@ extern "C"
* made for each game, though it should be kept in mind that the
* API is not thread-safe.
*/
typedef struct _loot_db_int * loot_db;
typedef struct loot_db loot_db;
/**
* @brief A structure that holds the type of a message and the message
@@ -383,7 +383,7 @@ extern "C"
* variable (eg. Linux) can still use the API.
* @returns A return code.
*/
LOOT_API unsigned int loot_create_db(loot_db * const db,
LOOT_API unsigned int loot_create_db(loot_db ** const db,
const unsigned int clientGame,
const char * const gamePath,
const char * const gameLocalPath);
@@ -396,7 +396,7 @@ extern "C"
* @param db
* The database handle to destroy.
*/
LOOT_API void loot_destroy_db(loot_db db);
LOOT_API void loot_destroy_db(loot_db * const db);
/**@}*/
/**********************************************************************//**
@@ -419,7 +419,7 @@ extern "C"
* be loaded.
* @returns A return code.
*/
LOOT_API unsigned int loot_load_lists(loot_db db,
LOOT_API unsigned int loot_load_lists(loot_db * const db,
const char * const masterlistPath,
const char * const userlistPath);
@@ -435,7 +435,7 @@ extern "C"
* The language code that is used for message language comparisons.
* @returns A return code.
*/
LOOT_API unsigned int loot_eval_lists(loot_db db,
LOOT_API unsigned int loot_eval_lists(loot_db * const db,
const unsigned int language);
/**********************************************************************//**
@@ -459,7 +459,7 @@ extern "C"
* A pointer to the size of the outputted array.
* @returns A return code.
*/
LOOT_API unsigned int loot_sort_plugins(loot_db db,
LOOT_API unsigned int loot_sort_plugins(loot_db * const db,
const char * const ** const sortedPlugins,
size_t * const numPlugins);
@@ -473,7 +473,7 @@ extern "C"
* The size of the inputted array.
* @returns A return code.
*/
LOOT_API unsigned int loot_apply_load_order(loot_db db,
LOOT_API unsigned int loot_apply_load_order(loot_db * const db,
const char * const * const loadOrder,
const size_t numPlugins);
@@ -514,7 +514,7 @@ extern "C"
* separately.
* @returns A return code.
*/
LOOT_API unsigned int loot_update_masterlist(loot_db db,
LOOT_API unsigned int loot_update_masterlist(loot_db * const db,
const char * const masterlistPath,
const char * const remoteURL,
const char * const remoteBranch,
@@ -547,7 +547,7 @@ extern "C"
* the revision given.
* @returns A return code.
*/
LOOT_API unsigned int loot_get_masterlist_revision(loot_db db,
LOOT_API unsigned int loot_get_masterlist_revision(loot_db * const db,
const char * const masterlistPath,
const bool getShortID,
const char ** const revisionID,
@@ -579,7 +579,7 @@ extern "C"
* suggested, this will be `0`.
* @returns A return code.
*/
LOOT_API unsigned int loot_get_tag_map(loot_db db,
LOOT_API unsigned int loot_get_tag_map(loot_db * const db,
const char * const ** const tagMap,
size_t * const numTags);
@@ -612,7 +612,7 @@ extern "C"
* userlist, `false` otherwise.
* @returns A return code.
*/
LOOT_API unsigned int loot_get_plugin_tags(loot_db db,
LOOT_API unsigned int loot_get_plugin_tags(loot_db * const db,
const char * const plugin,
const unsigned int ** const tags_added,
size_t * const numTags_added,
@@ -636,7 +636,7 @@ extern "C"
* outputted, this will be `0`.
* @returns A return code.
*/
LOOT_API unsigned int loot_get_plugin_messages(loot_db db,
LOOT_API unsigned int loot_get_plugin_messages(loot_db * const db,
const char * const plugin,
const loot_message ** const messages,
size_t * const numMessages);
@@ -658,7 +658,7 @@ extern "C"
* A pointer to a plugin cleanliness code.
* @returns A return code.
*/
LOOT_API unsigned int loot_get_dirty_info(loot_db db,
LOOT_API unsigned int loot_get_dirty_info(loot_db * const db,
const char * const plugin,
unsigned int * const needsCleaning);
@@ -675,7 +675,7 @@ extern "C"
* written. Otherwise, data will be written.
* @returns A return code.
*/
LOOT_API unsigned int loot_write_minimal_list(loot_db db,
LOOT_API unsigned int loot_write_minimal_list(loot_db * const db,
const char * const outputFile,
const bool overwrite);
+15 -15
View File
@@ -23,7 +23,7 @@
*/
#include "loot/api.h"
#include "_loot_db_int.h"
#include "loot_db.h"
#include "../backend/globals.h"
#include "../backend/plugin_sorter.h"
@@ -160,7 +160,7 @@ LOOT_API unsigned int loot_get_build_id(const char ** const revision) {
// plugins.txt and loadorder.txt (if they both exist) are in sync. If
// dataPath == nullptr then the API will attempt to detect the data path of
// the specified game.
LOOT_API unsigned int loot_create_db(loot_db * const db,
LOOT_API unsigned int loot_create_db(loot_db ** const db,
const unsigned int clientGame,
const char * const gamePath,
const char * const gameLocalPath) {
@@ -199,7 +199,7 @@ LOOT_API unsigned int loot_create_db(loot_db * const db,
if (gameLocalPath != nullptr && !boost::filesystem::is_directory(gameLocalPath))
return c_error(loot_error_invalid_args, "Given local data path \"" + std::string(gameLocalPath) + "\" is not a valid directory.");
*db = new _loot_db_int(clientGame, game_path, game_local_path);
*db = new loot_db(clientGame, game_path, game_local_path);
}
catch (loot::error& e) {
return c_error(e);
@@ -215,7 +215,7 @@ LOOT_API unsigned int loot_create_db(loot_db * const db,
}
// Destroys the given DB, freeing any memory allocated as part of its use.
LOOT_API void loot_destroy_db(loot_db db) {
LOOT_API void loot_destroy_db(loot_db * const db) {
delete db;
}
@@ -227,7 +227,7 @@ LOOT_API void loot_destroy_db(loot_db db) {
// Can be called multiple times. On error, the database is unchanged.
// Paths are case-sensitive if the underlying filesystem is case-sensitive.
// masterlistPath and userlistPath are files.
LOOT_API unsigned int loot_load_lists(loot_db db, const char * const masterlistPath,
LOOT_API unsigned int loot_load_lists(loot_db * const db, const char * const masterlistPath,
const char * const userlistPath) {
if (db == nullptr || masterlistPath == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
@@ -279,7 +279,7 @@ LOOT_API unsigned int loot_load_lists(loot_db db, const char * const masterlistP
// is called. Repeated calls re-evaluate the masterlist from scratch each time,
// ignoring the results of any previous evaluations. Paths are case-sensitive
// if the underlying filesystem is case-sensitive.
LOOT_API unsigned int loot_eval_lists(loot_db db, const unsigned int language) {
LOOT_API unsigned int loot_eval_lists(loot_db * const db, const unsigned int language) {
if (db == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
if (language != loot_lang_any
@@ -318,7 +318,7 @@ LOOT_API unsigned int loot_eval_lists(loot_db db, const unsigned int language) {
// LOOT Functionality Functions
////////////////////////////////////
LOOT_API unsigned int loot_sort_plugins(loot_db db,
LOOT_API unsigned int loot_sort_plugins(loot_db * const db,
const char * const ** const sortedPlugins,
size_t * const numPlugins) {
if (db == nullptr || sortedPlugins == nullptr || numPlugins == nullptr)
@@ -350,7 +350,7 @@ LOOT_API unsigned int loot_sort_plugins(loot_db db,
return loot_ok;
}
LOOT_API unsigned int loot_apply_load_order(loot_db db,
LOOT_API unsigned int loot_apply_load_order(loot_db * const db,
const char * const * const loadOrder,
const size_t numPlugins) {
if (db == nullptr || loadOrder == nullptr)
@@ -366,7 +366,7 @@ LOOT_API unsigned int loot_apply_load_order(loot_db db,
return loot_ok;
}
LOOT_API unsigned int loot_update_masterlist(loot_db db,
LOOT_API unsigned int loot_update_masterlist(loot_db * const db,
const char * const masterlistPath,
const char * const remoteURL,
const char * const remoteBranch,
@@ -389,7 +389,7 @@ LOOT_API unsigned int loot_update_masterlist(loot_db db,
return loot_ok;
}
LOOT_API unsigned int loot_get_masterlist_revision(loot_db db,
LOOT_API unsigned int loot_get_masterlist_revision(loot_db * const db,
const char * const masterlistPath,
const bool getShortID,
const char ** const revisionID,
@@ -441,7 +441,7 @@ LOOT_API unsigned int loot_get_masterlist_revision(loot_db db,
// Returns an array of the Bash Tags encounterred when loading the masterlist
// and userlist, and the number of tags in the returned array. The array and
// its contents are static and should not be freed by the client.
LOOT_API unsigned int loot_get_tag_map(loot_db db, const char * const ** const tagMap, size_t * const numTags) {
LOOT_API unsigned int loot_get_tag_map(loot_db * const db, const char * const ** const tagMap, size_t * const numTags) {
if (db == nullptr || tagMap == nullptr || numTags == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
@@ -488,7 +488,7 @@ LOOT_API unsigned int loot_get_tag_map(loot_db db, const char * const ** const t
// case-insensitive. If no Tags are found for an array, the array pointer (*tagIds)
// will be nullptr. The userlistModified bool is true if the userlist contains Bash Tag
// suggestion message additions.
LOOT_API unsigned int loot_get_plugin_tags(loot_db db, const char * const plugin,
LOOT_API unsigned int loot_get_plugin_tags(loot_db * const db, const char * const plugin,
const unsigned int ** const tagIds_added,
size_t * const numTags_added,
const unsigned int ** const tagIds_removed,
@@ -547,7 +547,7 @@ LOOT_API unsigned int loot_get_plugin_tags(loot_db db, const char * const plugin
// Returns the messages attached to the given plugin. Messages are valid until Load,
// loot_destroy_db or loot_get_plugin_messages are next called. plugin is case-insensitive.
// If no messages are attached, *messages will be nullptr and numMessages will equal 0.
LOOT_API unsigned int loot_get_plugin_messages(loot_db db, const char * const plugin,
LOOT_API unsigned int loot_get_plugin_messages(loot_db * const db, const char * const plugin,
const loot_message ** const messages,
size_t * const numMessages) {
if (db == nullptr || plugin == nullptr || messages == nullptr || numMessages == nullptr)
@@ -575,7 +575,7 @@ LOOT_API unsigned int loot_get_plugin_messages(loot_db db, const char * const pl
return loot_ok;
}
LOOT_API unsigned int loot_get_dirty_info(loot_db db, const char * const plugin, unsigned int * const needsCleaning) {
LOOT_API unsigned int loot_get_dirty_info(loot_db * const db, const char * const plugin, unsigned int * const needsCleaning) {
if (db == nullptr || plugin == nullptr || needsCleaning == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
@@ -610,7 +610,7 @@ LOOT_API unsigned int loot_get_dirty_info(loot_db db, const char * const plugin,
// and/or dirty messages, plus the Tag suggestions and/or messages themselves and their
// conditions, in order to create the Wrye Bash taglist. outputFile is the path to use
// for output. If outputFile already exists, it will only be overwritten if overwrite is true.
LOOT_API unsigned int loot_write_minimal_list(loot_db db, const char * const outputFile, const bool overwrite) {
LOOT_API unsigned int loot_write_minimal_list(loot_db * const db, const char * const outputFile, const bool overwrite) {
if (db == nullptr || outputFile == nullptr)
return c_error(loot_error_invalid_args, "Null pointer passed.");
+3 -3
View File
@@ -31,8 +31,8 @@
#include <vector>
#include <unordered_map>
struct _loot_db_int : public loot::Game {
_loot_db_int(const unsigned int clientGame, const std::string& gamePath, const boost::filesystem::path& gameLocalDataPath)
struct loot_db : public loot::Game {
loot_db(const unsigned int clientGame, const std::string& gamePath, const boost::filesystem::path& gameLocalDataPath)
: Game(clientGame) {
this->SetGamePath(gamePath);
this->Init(false, gameLocalDataPath);
@@ -184,4 +184,4 @@ private:
std::vector<std::string> pluginMessageStrings;
};
#endif
#endif
+1 -1
View File
@@ -122,7 +122,7 @@ protected:
const boost::filesystem::path resourcePath;
loot_db db;
loot_db * db;
};
class OblivionTest : public GameTest {