Skip to content

Commit

Permalink
Format C++ files using clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Nov 13, 2017
1 parent 42cacca commit 701e063
Show file tree
Hide file tree
Showing 93 changed files with 3,560 additions and 2,543 deletions.
15 changes: 15 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
Language: Cpp
BasedOnStyle: Google

AccessModifierOffset: -2
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: false
BinPackArguments: false
BinPackParameters: false
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true
FixNamespaceComments: false
SpaceAfterTemplateKeyword: false
Standard: Cpp11
...
15 changes: 3 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ When you do make a pull request, please do so from a branch which doesn't have t

## Code Style

LOOT's JavaScript uses a slightly tweaked version of the Airbnb style, and can be automatically linted by ESLint, so isn't covered here.
The LOOT API code style is based on the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). Formatting style is codified in the repository's `.clang-format` file, but is not enforced.

### C++ Code Style

The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html) is used as the base, with deviations as listed below.

#### C++ Features
### C++ Features

* Static variables may contain non-POD types.
* Reference arguments don't need to be `const` (ie. they can be used for output variables).
Expand All @@ -36,12 +32,7 @@ The [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html)
* There's no restriction on which Boost libraries can be used.
* Specialising `std::hash` is allowed.

#### Naming
### Naming

* Constant, enumerator and variable names should use `camelCase` or `underscore_separators`, but they should be consistent within the same scope.
* Function names should use `PascalCase` or `camelCase`, but they should be consistent within the same scope.

#### Formatting

* Line length doesn't matter.
* `public`, `protected` and `private` keywords should not be indented within a class declaration.
53 changes: 31 additions & 22 deletions include/loot/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,46 @@
#define LOOT_API_H

#include <functional>
#include <string>
#include <memory>
#include <string>

#include "loot/api_decorator.h"
#include "loot/game_interface.h"
#include "loot/exception/error_categories.h"
#include "loot/enum/game_type.h"
#include "loot/enum/log_level.h"
#include "loot/exception/condition_syntax_error.h"
#include "loot/exception/cyclic_interaction_error.h"
#include "loot/exception/error_categories.h"
#include "loot/exception/file_access_error.h"
#include "loot/exception/git_state_error.h"
#include "loot/enum/game_type.h"
#include "loot/enum/log_level.h"
#include "loot/game_interface.h"
#include "loot/loot_version.h"

namespace loot {
/**@}*/
/**********************************************************************//**
* @name Logging Functions
*************************************************************************/
/**********************************************************************/ /**
* @name
*Logging
*Functions
*************************************************************************/
/**@{*/

/**
* @brief Set the callback function that is called when logging.
* @details If this function is not called, the default behaviour is to
* @details If this function is not called, the default behaviour is to
* print messages to the console.
* @param callback
* The function called when logging. The first parameter is the
* level of the message being logged, and the second is the message.
*/
LOOT_API void SetLoggingCallback(std::function<void(LogLevel, const char*)> callback);
LOOT_API void SetLoggingCallback(
std::function<void(LogLevel, const char*)> callback);

/**@}*/
/**********************************************************************//**
* @name Version Functions
*************************************************************************/
/**********************************************************************/ /**
* @name
*Version
*Functions
*************************************************************************/
/**@{*/

/**
Expand All @@ -81,9 +86,12 @@ LOOT_API bool IsCompatible(const unsigned int major,
const unsigned int patch);

/**@}*/
/**********************************************************************//**
* @name Lifecycle Management Functions
*************************************************************************/
/**********************************************************************/ /**
* @name
*Lifecycle
*Management
*Functions
*************************************************************************/
/**@{*/

/**
Expand All @@ -108,15 +116,16 @@ LOOT_API void InitialiseLocale(const std::string& id);
* sibling Data folder and by searching for the game's Registry entry.
* @param game_local_path
* The relative or absolute path to the game's folder in
* `%%LOCALAPPDATA%` or an empty string. If an empty string, the API will
* attempt to look up the path that `%%LOCALAPPDATA%` corresponds to.
* This parameter is provided so that systems lacking that environmental
* `%%LOCALAPPDATA%` or an empty string. If an empty string, the API
* will attempt to look up the path that `%%LOCALAPPDATA%` corresponds to. This
* parameter is provided so that systems lacking that environmental
* variable (eg. Linux) can still use the API.
* @returns The new game handle.
*/
LOOT_API std::shared_ptr<GameInterface> CreateGameHandle(const GameType game,
const std::string& game_path = "",
const std::string& game_local_path = "");
LOOT_API std::shared_ptr<GameInterface> CreateGameHandle(
const GameType game,
const std::string& game_path = "",
const std::string& game_local_path = "");
}

#endif
16 changes: 8 additions & 8 deletions include/loot/api_decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
that use this header do not need to define anything to import the symbols
properly. */
#if defined(_WIN32)
# ifdef LOOT_STATIC
# define LOOT_API
# elif defined LOOT_EXPORT
# define LOOT_API __declspec(dllexport)
# else
# define LOOT_API __declspec(dllimport)
# endif
#ifdef LOOT_STATIC
#define LOOT_API
#elif defined LOOT_EXPORT
#define LOOT_API __declspec(dllexport)
#else
# define LOOT_API
#define LOOT_API __declspec(dllimport)
#endif
#else
#define LOOT_API
#endif

#endif
66 changes: 35 additions & 31 deletions include/loot/database_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ class DatabaseInterface {
* character hash will be outputted.
* @returns The revision data.
*/
virtual MasterlistInfo GetMasterlistRevision(const std::string& masterlist_path,
const bool get_short_id) const = 0;
virtual MasterlistInfo GetMasterlistRevision(
const std::string& masterlist_path,
const bool get_short_id) const = 0;

/**
* Check if the given masterlist is the latest available for a given branch.
Expand Down Expand Up @@ -176,7 +177,8 @@ class DatabaseInterface {
* @returns A vector of messages supplied in the metadata lists but not
* attached to any particular plugin.
*/
virtual std::vector<Message> GetGeneralMessages(bool evaluateConditions = false) const = 0;
virtual std::vector<Message> GetGeneralMessages(
bool evaluateConditions = false) const = 0;

/**
* @}
Expand All @@ -200,32 +202,34 @@ class DatabaseInterface {
* If the plugin has no metadata, PluginMetadata.IsNameOnly()
* will return true.
*/
virtual PluginMetadata GetPluginMetadata(const std::string& plugin,
bool includeUserMetadata = true,
bool evaluateConditions = false) const = 0;

/**
* @brief Get a plugin's metadata loaded from the given userlist.
* @param plugin
* The filename of the plugin to look up user-added metadata for.
* @param evaluateConditions
* If true, any metadata conditions are evaluated before the metadata
* is returned, otherwise unevaluated metadata is returned. Evaluating
* plugin metadata conditions does not clear the condition cache.
* @returns A PluginMetadata object containing the plugin's user-added
* metadata. If the plugin has no metadata,
* PluginMetadata.IsNameOnly() will return true.
*/
virtual PluginMetadata GetPluginUserMetadata(const std::string& plugin,
bool evaluateConditions = false) const = 0;

/**
* @brief Sets a plugin's user metadata, overwriting any existing user
* metadata.
* @param pluginMetadata
* The user metadata you want to set, with plugin.Name() being the
* filename of the plugin the metadata is for.
*/
virtual PluginMetadata GetPluginMetadata(
const std::string& plugin,
bool includeUserMetadata = true,
bool evaluateConditions = false) const = 0;

/**
* @brief Get a plugin's metadata loaded from the given userlist.
* @param plugin
* The filename of the plugin to look up user-added metadata for.
* @param evaluateConditions
* If true, any metadata conditions are evaluated before the metadata
* is returned, otherwise unevaluated metadata is returned. Evaluating
* plugin metadata conditions does not clear the condition cache.
* @returns A PluginMetadata object containing the plugin's user-added
* metadata. If the plugin has no metadata,
* PluginMetadata.IsNameOnly() will return true.
*/
virtual PluginMetadata GetPluginUserMetadata(
const std::string& plugin,
bool evaluateConditions = false) const = 0;

/**
* @brief Sets a plugin's user metadata, overwriting any existing user
* metadata.
* @param pluginMetadata
* The user metadata you want to set, with plugin.Name() being the
* filename of the plugin the metadata is for.
*/
virtual void SetPluginUserMetadata(const PluginMetadata& pluginMetadata) = 0;

/**
Expand All @@ -238,8 +242,8 @@ class DatabaseInterface {
virtual void DiscardPluginUserMetadata(const std::string& plugin) = 0;

/**
* @brief Discards all loaded user metadata for all plugins, and any user-added
* general messages and known bash tags.
* @brief Discards all loaded user metadata for all plugins, and any
* user-added general messages and known bash tags.
*/
virtual void DiscardAllUserMetadata() = 0;

Expand Down
1 change: 0 additions & 1 deletion include/loot/enum/game_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ along with LOOT. If not, see
#ifndef LOOT_GAME_TYPE
#define LOOT_GAME_TYPE


/**
* The namespace used by the LOOT API.
*/
Expand Down
26 changes: 12 additions & 14 deletions include/loot/exception/cyclic_interaction_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,36 +41,34 @@ class CyclicInteractionError : public std::runtime_error {
* @param backCycle A string describing the path from lastPlugin to
* firstPlugin.
*/
CyclicInteractionError(const std::string& firstPlugin, const std::string& lastPlugin, const std::string& backCycle) :
std::runtime_error("Cyclic interaction detected between plugins \"" + firstPlugin + "\" and \"" + lastPlugin + "\". Back cycle: " + backCycle),
firstPlugin_(firstPlugin),
lastPlugin_(lastPlugin),
backCycle_(backCycle) {}
CyclicInteractionError(const std::string& firstPlugin,
const std::string& lastPlugin,
const std::string& backCycle) :
std::runtime_error("Cyclic interaction detected between plugins \"" +
firstPlugin + "\" and \"" + lastPlugin +
"\". Back cycle: " + backCycle),
firstPlugin_(firstPlugin),
lastPlugin_(lastPlugin),
backCycle_(backCycle) {}

/**
* Get the first plugin in the chosen forward path of the cycle.
* @return A plugin filename.
*/
std::string getFirstPlugin() {
return firstPlugin_;
}
std::string getFirstPlugin() { return firstPlugin_; }

/**
* Get the first plugin in the chosen forward path of the cycle.
* @return A plugin filename.
*/
std::string getLastPlugin() {
return lastPlugin_;
}
std::string getLastPlugin() { return lastPlugin_; }

/**
* Get a description of the reverse path from the chosen last plugin to the
* chosen first plugin of the cycle.
* @return A string describing a path between two plugins in the plugin graph.
*/
std::string getBackCycle() {
return backCycle_;
}
std::string getBackCycle() { return backCycle_; }

private:
const std::string firstPlugin_;
Expand Down
Loading

0 comments on commit 701e063

Please sign in to comment.