Skip to content

Commit

Permalink
Apply clang-format Llvm on C++ code
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausKlein committed Sep 7, 2024
1 parent e466baf commit 08ffc28
Show file tree
Hide file tree
Showing 101 changed files with 637 additions and 826 deletions.
48 changes: 28 additions & 20 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,31 @@ IndentWidth: 4
UseTab: Never
---
Language: Cpp
BasedOnStyle: WebKit
# XXX ColumnLimit: 123
AccessModifierOffset: -4
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
DerivePointerAlignment: false
IndentWidth: 4
InsertBraces: true
InsertNewlineAtEOF: true
NamespaceIndentation: None
PointerAlignment: Right
SpacesBeforeTrailingComments: 1
UseTab: Never
#
AlignTrailingComments:
# XXX Kind: Never
Kind: Always
OverEmptyLines: 1
BasedOnStyle: Llvm

# ColumnLimit: 80
# AccessModifierOffset: -2
# AllowShortIfStatementsOnASingleLine: false
# AllowShortFunctionsOnASingleLine: Inline
# ConstructorInitializerIndentWidth: 4
# ContinuationIndentWidth: 4
# DerivePointerAlignment: false
# #
# # TODO: TBD 4 instead of 2? CK
# # XXX IndentWidth: 4
# InsertBraces: true
# InsertNewlineAtEOF: true
# NamespaceIndentation: None
# PointerAlignment: Right
# SpacesBeforeTrailingComments: 1
# UseTab: Never

# TODO: TBD Keep original style? CK
# AlignTrailingComments:
# Kind: Always
# OverEmptyLines: 0

# TODO: TBD Keep original style? CK
# BreakBeforeBraces: Custom
# BraceWrapping:
# AfterNamespace: true
5 changes: 1 addition & 4 deletions chapter01/policy_example/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
int main(int, char **)
{
return 0;
}
int main(int, char **) { return 0; }
7 changes: 3 additions & 4 deletions chapter01/simple_executable/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <iostream>

int main(int, char **)
{
std::cout << "Welcome to CMake Best Practices\n";
return 0;
int main(int, char **) {
std::cout << "Welcome to CMake Best Practices\n";
return 0;
}
48 changes: 23 additions & 25 deletions chapter02/component1/include/framework/components/component1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,36 @@

#include <framework/components/component_interface.hpp>

namespace framework {
namespace components {
namespace framework::components {

/**
* @brief Component 1 interface
*/
class component1 : public component_interface {
public:
/**
* @brief Construct a new component1 object
*/
component1();
/**
* @brief Construct a new component1 object
*/
component1();

/**
* @brief Destroy the component1 object
*/
virtual ~component1() override;
/**
* @brief Destroy the component1 object
*/
virtual ~component1() override;

/**
* @brief Do some work
*
* @return true on success, false on failure
*/
virtual bool do_stuff() const override;
/**
* @brief Do some work
*
* @return true on success, false on failure
*/
virtual bool do_stuff() const override;

/**
* @brief Do other stuff
*
* @param param Argument
* @return int Stuffs completed
*/
virtual int do_other_stuff(int param) override;
/**
* @brief Do other stuff
*
* @param param Argument
* @return int Stuffs completed
*/
virtual int do_other_stuff(int param) override;
}; // class component1
} // namespace components
} // namespace framework
} // namespace framework::components
26 changes: 8 additions & 18 deletions chapter02/component1/src/component1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,17 @@

#include <iostream>

namespace framework {
namespace components {
namespace framework::components {

component1::component1()
{
std::cout << "Component 1 is constructed" << std::endl;
component1::component1() {
std::cout << "Component 1 is constructed" << std::endl;
}

component1::~component1()
{
std::cout << "Component 1 is destructed" << std::endl;
component1::~component1() {
std::cout << "Component 1 is destructed" << std::endl;
}

bool component1::do_stuff() const
{
return false;
}
bool component1::do_stuff() const { return false; }

int component1::do_other_stuff(int param)
{
return param;
}
} // namespace components
} // namespace framework
int component1::do_other_stuff(int param) { return param; }
} // namespace framework::components
48 changes: 23 additions & 25 deletions chapter02/component2/include/framework/components/component2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,36 @@

#include <framework/components/component_interface.hpp>

namespace framework {
namespace components {
namespace framework::components {

/**
* @brief Component 1 interface
*/
class component2 : public component_interface {
public:
/**
* @brief Construct a new component1 object
*/
component2();
/**
* @brief Construct a new component1 object
*/
component2();

/**
* @brief Destroy the component1 object
*/
virtual ~component2() override;
/**
* @brief Destroy the component1 object
*/
virtual ~component2() override;

/**
* @brief Do some work
*
* @return true on success, false on failure
*/
virtual bool do_stuff() const override;
/**
* @brief Do some work
*
* @return true on success, false on failure
*/
virtual bool do_stuff() const override;

/**
* @brief Do other stuff
*
* @param param Argument
* @return int Stuffs completed
*/
virtual int do_other_stuff(int param) override;
/**
* @brief Do other stuff
*
* @param param Argument
* @return int Stuffs completed
*/
virtual int do_other_stuff(int param) override;
}; // class component2
} // namespace components
} // namespace framework
} // namespace framework::components
26 changes: 8 additions & 18 deletions chapter02/component2/src/component2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,17 @@
#include <cmath>
#include <iostream>

namespace framework {
namespace components {
namespace framework::components {

component2::component2()
{
std::cout << "Component 2 is constructed" << std::endl;
component2::component2() {
std::cout << "Component 2 is constructed" << std::endl;
}

component2::~component2()
{
std::cout << "Component 2 is destructed" << std::endl;
component2::~component2() {
std::cout << "Component 2 is destructed" << std::endl;
}

bool component2::do_stuff() const
{
return true;
}
bool component2::do_stuff() const { return true; }

int component2::do_other_stuff(int param)
{
return std::sqrt(param) * 2;
}
} // namespace components
} // namespace framework
int component2::do_other_stuff(int param) { return std::sqrt(param) * 2; }
} // namespace framework::components
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,30 @@

#pragma once

namespace framework {
namespace components {
namespace framework::components {
/**
* @brief Component interface
*/
class component_interface {
public:
/**
* @brief Destroy the component1 object
*/
virtual ~component_interface() = default;
/**
* @brief Destroy the component1 object
*/
virtual ~component_interface() = default;

/**
* @brief Do some work
*
* @return true on success, false on failure
*/
virtual bool do_stuff() const = 0;
/**
* @brief Do some work
*
* @return true on success, false on failure
*/
virtual bool do_stuff() const = 0;

/**
* @brief Do other stuff
*
* @param param Argument
* @return int Stuffs completed
*/
virtual int do_other_stuff(int param) = 0;
/**
* @brief Do other stuff
*
* @param param Argument
* @return int Stuffs completed
*/
virtual int do_other_stuff(int param) = 0;
}; // class component_interface
} // namespace components
} // namespace framework
} // namespace framework::components
39 changes: 18 additions & 21 deletions chapter02/driver_app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
/**
* @brief Component type
*/
enum class component_type : std::uint8_t { component1,
component2 };
enum class component_type : std::uint8_t { component1, component2 };

/**
* @brief Make component
Expand All @@ -30,33 +29,31 @@ enum class component_type : std::uint8_t { component1,
* throws.
*/
std::unique_ptr<framework::components::component_interface>
component_factory(component_type ct) noexcept(false)
{
switch (ct) {
case component_type::component1:
return std::unique_ptr<framework::components::component1>(
new framework::components::component1());
case component_type::component2:
return std::unique_ptr<framework::components::component2>(
new framework::components::component2());
}
throw std::runtime_error { "Invalid component type" };
component_factory(component_type ct) noexcept(false) {
switch (ct) {
case component_type::component1:
return std::unique_ptr<framework::components::component1>(
new framework::components::component1());
case component_type::component2:
return std::unique_ptr<framework::components::component2>(
new framework::components::component2());
}
throw std::runtime_error{"Invalid component type"};
}

/**
* @brief Main entry point of the application
*
* @return int Application exit code
*/
int main(void)
{
int main(void) {

auto component_1 = component_factory(component_type::component1);
auto component_2 = component_factory(component_type::component2);
auto component_1 = component_factory(component_type::component1);
auto component_2 = component_factory(component_type::component2);

if (component_1->do_stuff() || component_2->do_stuff()) {
std::cout << "One of the component(s) did stuff" << std::endl;
}
if (component_1->do_stuff() || component_2->do_stuff()) {
std::cout << "One of the component(s) did stuff" << std::endl;
}

return component_1->do_other_stuff(1) + component_2->do_other_stuff(3);
return component_1->do_other_stuff(1) + component_2->do_other_stuff(3);
}
7 changes: 3 additions & 4 deletions chapter02/simple_example/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <iostream>

int main(int, char **)
{
std::cout << "Welcome to CMake Best Practices\n";
return 0;
int main(int, char **) {
std::cout << "Welcome to CMake Best Practices\n";
return 0;
}
Loading

0 comments on commit 08ffc28

Please sign in to comment.