Skip to content

Commit

Permalink
Consistent C++ styling (FreeOpcUa#243)
Browse files Browse the repository at this point in the history
* Additional C++ styling guidelines and script

* Style overhaul per new guidelines
  • Loading branch information
mdcb authored and oroulet committed May 30, 2017
1 parent 66acd64 commit 25ff396
Show file tree
Hide file tree
Showing 332 changed files with 122,843 additions and 111,784 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ docker build .
C++ style
* 2 spaces not tab
* CamelCase
* local variables start with small letter
* gobal/member variables starts with capital letters.
* Local variables start with small letter
* Global/member variables starts with capital letters
* Use provided automatic formatter ([Artistic Style](http://astyle.sourceforge.net)) by invoking ``./restyle``

python code and API should follows PEP8 (many places should be fixed)

Expand Down
13 changes: 13 additions & 0 deletions astylerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--break-blocks
--break-blocks=all
--add-brackets
--add-one-line-brackets
--suffix=none
--indent=spaces=2
--convert-tabs
-A7
--align-pointer=middle
--align-reference=middle
--pad-header
--pad-oper
--unpad-paren
52 changes: 26 additions & 26 deletions include/opc/common/addons_core/addon.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@
namespace Common
{

class Addon : private Common::Interface
{
public:
DEFINE_CLASS_POINTERS(Addon)

public:
/// @brief initialize addon.
/// @note Calls when all addons dependencies resolved.
/// suppose that addon fully ready for work.
virtual void Initialize(AddonsManager& manager, const AddonParameters& parameters) = 0;

/// @brief Stopping addon work.
/// After calling this method addon should throw exception on any calls.
virtual void Stop() = 0;
};

// @brief factory of addon.
class AddonFactory : private Common::Interface
{
public:
DEFINE_CLASS_POINTERS(AddonFactory)

public:
/// @brief Create instance of addon.
virtual Addon::UniquePtr CreateAddon() = 0;
};
class Addon : private Common::Interface
{
public:
DEFINE_CLASS_POINTERS(Addon)

public:
/// @brief initialize addon.
/// @note Calls when all addons dependencies resolved.
/// suppose that addon fully ready for work.
virtual void Initialize(AddonsManager & manager, const AddonParameters & parameters) = 0;

/// @brief Stopping addon work.
/// After calling this method addon should throw exception on any calls.
virtual void Stop() = 0;
};

// @brief factory of addon.
class AddonFactory : private Common::Interface
{
public:
DEFINE_CLASS_POINTERS(AddonFactory)

public:
/// @brief Create instance of addon.
virtual Addon::UniquePtr CreateAddon() = 0;
};

} // namespace Common

Expand Down
136 changes: 68 additions & 68 deletions include/opc/common/addons_core/addon_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,89 +20,89 @@

namespace Common
{
typedef std::string AddonId;
typedef std::string AddonId;

class Addon;
class AddonFactory;
class Addon;
class AddonFactory;

struct AddonInformation
{
AddonId Id;
std::shared_ptr<AddonFactory> Factory;
std::vector<AddonId> Dependencies;
AddonParameters Parameters;
};
struct AddonInformation
{
AddonId Id;
std::shared_ptr<AddonFactory> Factory;
std::vector<AddonId> Dependencies;
AddonParameters Parameters;
};

class AddonsManager : private Interface
class AddonsManager : private Interface
{
public:
DEFINE_CLASS_POINTERS(AddonsManager)

public:
/// @brief register new addon.
/// @param addonConfiguration configuration of new addon.
/// @throws if addon already redistered. If manager started thows if not all dependencies resolved.
/// If manager already started addon will be immediately created and initialized.
virtual void Register(const AddonInformation & caddonConfiguration) = 0;

/// @brief unregister addon
/// @param id id of unregistering addon
/// @throws if addon not found
/// For unregistering addon will be called method Addon::Stop() and addon data will be removed.
virtual void Unregister(const AddonId & id) = 0;

/// @brief getting addon by id
/// @param id id of the required addon
/// @return addon instance
/// @throws if addon is not registered or not initialized yet.

virtual std::shared_ptr<Addon> GetAddon(const AddonId & id) const = 0;

virtual std::shared_ptr<Addon> GetAddon(const char id[]) const
{
public:
DEFINE_CLASS_POINTERS(AddonsManager)

public:
/// @brief register new addon.
/// @param addonConfiguration configuration of new addon.
/// @throws if addon already redistered. If manager started thows if not all dependencies resolved.
/// If manager already started addon will be immediately created and initialized.
virtual void Register(const AddonInformation& caddonConfiguration) = 0;

/// @brief unregister addon
/// @param id id of unregistering addon
/// @throws if addon not found
/// For unregistering addon will be called method Addon::Stop() and addon data will be removed.
virtual void Unregister(const AddonId& id) = 0;

/// @brief getting addon by id
/// @param id id of the required addon
/// @return addon instance
/// @throws if addon is not registered or not initialized yet.

virtual std::shared_ptr<Addon> GetAddon(const AddonId& id) const = 0;

virtual std::shared_ptr<Addon> GetAddon(const char id[]) const
{
return GetAddon(AddonId(id));
}

/// @brief Get instance of addon
/// @return instance of addon casted to specified type
/// @throws if unable to cast addon, unable to find addon, or in casr of error
template <class AddonClass>
typename std::shared_ptr<AddonClass> GetAddon(const AddonId& id) const;
return GetAddon(AddonId(id));
}

/// @brief Get instance of addon
/// @return instance of addon casted to specified type
/// @throws if unable to cast addon, unable to find addon, or in casr of error
template <class AddonClass>
typename std::shared_ptr<AddonClass> GetAddon(const AddonId & id) const;

// template <class AddonClass>
// typename std::shared_ptr<AddonClass> GetAddon(const char* id) const;

template <class AddonClass>
typename std::shared_ptr<AddonClass> GetAddon(const char id[]) const;
template <class AddonClass>
typename std::shared_ptr<AddonClass> GetAddon(const char id[]) const;


/// @brief starting work.
/// creates all addons and initializes them.
/// @throws if not all addons dependencies can be resolved.
virtual void Start(/*const AddonsConfiguration& config*/) = 0;
/// @brief starting work.
/// creates all addons and initializes them.
/// @throws if not all addons dependencies can be resolved.
virtual void Start(/*const AddonsConfiguration& config*/) = 0;

// @brief Stopping all addons;
virtual void Stop() = 0;
};
// @brief Stopping all addons;
virtual void Stop() = 0;
};


/// @brief Get instance of addons core
/// @throws in case of error
/// @note Only one instance of addons manager can be at one time.
/// When all smart pointers are gone addons manager deletes.
AddonsManager::UniquePtr CreateAddonsManager();
/// @brief Get instance of addons core
/// @throws in case of error
/// @note Only one instance of addons manager can be at one time.
/// When all smart pointers are gone addons manager deletes.
AddonsManager::UniquePtr CreateAddonsManager();

template <class AddonClass>
typename std::shared_ptr<AddonClass> AddonsManager::GetAddon(const AddonId& id) const
{
return std::dynamic_pointer_cast<AddonClass>(GetAddon(id));
}
template <class AddonClass>
typename std::shared_ptr<AddonClass> AddonsManager::GetAddon(const AddonId & id) const
{
return std::dynamic_pointer_cast<AddonClass>(GetAddon(id));
}

template <class AddonClass>
typename std::shared_ptr<AddonClass> AddonsManager::GetAddon(const char id[]) const
{
return std::dynamic_pointer_cast<AddonClass>(GetAddon(AddonId(id)));
}
template <class AddonClass>
typename std::shared_ptr<AddonClass> AddonsManager::GetAddon(const char id[]) const
{
return std::dynamic_pointer_cast<AddonClass>(GetAddon(AddonId(id)));
}


} // namespace Common
Expand Down
62 changes: 31 additions & 31 deletions include/opc/common/addons_core/addon_parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// @license GNU LGPL
///
/// Distributed under the GNU LGPL License
/// (See accompanying file LICENSE or copy at
/// (See accompanying file LICENSE or copy at
/// http://www.gnu.org/licenses/lgpl.html)
///

Expand All @@ -18,44 +18,44 @@
namespace Common
{

struct Parameter
struct Parameter
{
std::string Name;
std::string Value;

Parameter()
{
std::string Name;
std::string Value;
}

Parameter()
{
}
Parameter(const std::string & name, const std::string & value)
: Name(name)
, Value(value)
{
}
};

Parameter(const std::string& name, const std::string& value)
: Name(name)
, Value(value)
{
}
};
struct ParametersGroup
{
std::string Name;
std::vector<Parameter> Parameters;
std::vector<ParametersGroup> Groups;

struct ParametersGroup
ParametersGroup()
{
std::string Name;
std::vector<Parameter> Parameters;
std::vector<ParametersGroup> Groups;
}

ParametersGroup()
{
}

ParametersGroup(const std::string& name)
: Name(name)
{
}
};
ParametersGroup(const std::string & name)
: Name(name)
{
}
};


struct AddonParameters
{
std::vector<ParametersGroup> Groups;
std::vector<Parameter> Parameters;
};
struct AddonParameters
{
std::vector<ParametersGroup> Groups;
std::vector<Parameter> Parameters;
};

}

Expand Down
34 changes: 17 additions & 17 deletions include/opc/common/addons_core/config_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,28 @@
namespace Common
{

struct ModuleConfiguration
{
AddonId Id;
std::vector<AddonId> Dependencies;
std::string Path;
AddonParameters Parameters;
};
struct ModuleConfiguration
{
AddonId Id;
std::vector<AddonId> Dependencies;
std::string Path;
AddonParameters Parameters;
};

typedef std::vector<Common::ModuleConfiguration> ModulesConfiguration;
typedef std::vector<Common::ModuleConfiguration> ModulesConfiguration;

struct Configuration
{
Common::AddonParameters Parameters;
std::vector<ModuleConfiguration> Modules;
};
struct Configuration
{
Common::AddonParameters Parameters;
std::vector<ModuleConfiguration> Modules;
};

Common::AddonInformation GetAddonInfomation(const ModuleConfiguration& config);
Common::AddonInformation GetAddonInfomation(const ModuleConfiguration & config);

Configuration ParseConfiguration(const std::string& configPath);
void SaveConfiguration(const ModulesConfiguration& configuration, const std::string& configPath);
Configuration ParseConfiguration(const std::string & configPath);
void SaveConfiguration(const ModulesConfiguration & configuration, const std::string & configPath);

Configuration ParseConfigurationFiles(const std::string& directory);
Configuration ParseConfigurationFiles(const std::string & directory);

}

6 changes: 3 additions & 3 deletions include/opc/common/addons_core/dynamic_addon.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// @license GNU LGPL
///
/// Distributed under the GNU LGPL License
/// (See accompanying file LICENSE or copy at
/// (See accompanying file LICENSE or copy at
/// http://www.gnu.org/licenses/lgpl.html)
///

Expand All @@ -13,9 +13,9 @@

#include <opc/common/addons_core/addon.h>

extern "C" Common::Addon* CreateAddon();
extern "C" Common::Addon * CreateAddon();

typedef Common::Addon* (*CreateAddonFunc)();
typedef Common::Addon * (*CreateAddonFunc)();

#endif // OPC_CORE_DYNAMIC_ADDON_H

Loading

0 comments on commit 25ff396

Please sign in to comment.