aboutsummaryrefslogtreecommitdiff
path: root/examples/basic/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-06-09 17:10:32 +0200
committerHampusM <hampus@hampusmat.com>2022-06-09 17:10:32 +0200
commita5d218fd1a7e842b7ea4ac7809b0ba89856a5205 (patch)
tree77021d322f45a2b1d17bc79dc6189df1562ba2ea /examples/basic/src
parent58762e6e029d71ed72b094ec2d5831b6cac4e27b (diff)
docs: fix basic example code style
Diffstat (limited to 'examples/basic/src')
-rw-r--r--examples/basic/src/basic_example.cpp2
-rw-r--r--examples/basic/src/bootstrap.cpp2
-rw-r--r--examples/basic/src/bootstrap.hpp2
-rw-r--r--examples/basic/src/enemy.cpp2
-rw-r--r--examples/basic/src/enemy.hpp4
-rw-r--r--examples/basic/src/enemy_creator.cpp9
-rw-r--r--examples/basic/src/enemy_creator.hpp4
-rw-r--r--examples/basic/src/hero.hpp2
-rw-r--r--examples/basic/src/interfaces/enemy.hpp6
-rw-r--r--examples/basic/src/interfaces/enemy_creator.hpp5
-rw-r--r--examples/basic/src/interfaces/hero.hpp1
-rw-r--r--examples/basic/src/interfaces/weapon.hpp3
-rw-r--r--examples/basic/src/sword.cpp2
-rw-r--r--examples/basic/src/sword.hpp2
14 files changed, 28 insertions, 18 deletions
diff --git a/examples/basic/src/basic_example.cpp b/examples/basic/src/basic_example.cpp
index e91235f..2974c09 100644
--- a/examples/basic/src/basic_example.cpp
+++ b/examples/basic/src/basic_example.cpp
@@ -4,7 +4,7 @@
#include <iostream>
-int main()
+auto main() -> int
{
auto container = bootstrap();
diff --git a/examples/basic/src/bootstrap.cpp b/examples/basic/src/bootstrap.cpp
index 7a78aec..ac81bd9 100644
--- a/examples/basic/src/bootstrap.cpp
+++ b/examples/basic/src/bootstrap.cpp
@@ -12,7 +12,7 @@
#include "hero.hpp"
#include "sword.hpp"
-yacppdic::Container bootstrap()
+auto bootstrap() -> yacppdic::Container
{
auto container = yacppdic::Container();
diff --git a/examples/basic/src/bootstrap.hpp b/examples/basic/src/bootstrap.hpp
index 104248f..9febbd9 100644
--- a/examples/basic/src/bootstrap.hpp
+++ b/examples/basic/src/bootstrap.hpp
@@ -2,4 +2,4 @@
#include <yacppdic/container.hpp>
-yacppdic::Container bootstrap();
+auto bootstrap() -> yacppdic::Container;
diff --git a/examples/basic/src/enemy.cpp b/examples/basic/src/enemy.cpp
index 3923794..60bd98b 100644
--- a/examples/basic/src/enemy.cpp
+++ b/examples/basic/src/enemy.cpp
@@ -2,7 +2,7 @@
Enemy::Enemy(int health) noexcept : _health(health) {}
-int Enemy::get_health() const noexcept
+auto Enemy::get_health() const noexcept -> int
{
return _health;
}
diff --git a/examples/basic/src/enemy.hpp b/examples/basic/src/enemy.hpp
index b345f7f..a6fc778 100644
--- a/examples/basic/src/enemy.hpp
+++ b/examples/basic/src/enemy.hpp
@@ -7,9 +7,9 @@
class Enemy : public IEnemy, public yacppdic::AutoWirable<IEnemy, Enemy>
{
public:
- Enemy(int health) noexcept;
+ explicit Enemy(int health) noexcept;
- int get_health() const noexcept override;
+ [[nodiscard]] auto get_health() const noexcept -> int override;
void do_damage(int damage) noexcept override;
diff --git a/examples/basic/src/enemy_creator.cpp b/examples/basic/src/enemy_creator.cpp
index 820ce1b..fd8a809 100644
--- a/examples/basic/src/enemy_creator.cpp
+++ b/examples/basic/src/enemy_creator.cpp
@@ -1,19 +1,22 @@
#include "enemy_creator.hpp"
+#include <utility>
+
+
EnemyCreator::EnemyCreator(
IEnemyFactory small_enemy_factory,
IEnemyFactory big_enemy_factory
) noexcept
- : _small_enemy_factory(small_enemy_factory), _big_enemy_factory(big_enemy_factory)
+ : _small_enemy_factory(std::move(std::move(small_enemy_factory))), _big_enemy_factory(std::move(std::move(big_enemy_factory)))
{
}
-std::unique_ptr<IEnemy> EnemyCreator::create_small_enemy() noexcept
+auto EnemyCreator::create_small_enemy() noexcept -> std::unique_ptr<IEnemy>
{
return _small_enemy_factory();
}
-std::unique_ptr<IEnemy> EnemyCreator::create_big_enemy() noexcept
+auto EnemyCreator::create_big_enemy() noexcept -> std::unique_ptr<IEnemy>
{
return _big_enemy_factory();
}
diff --git a/examples/basic/src/enemy_creator.hpp b/examples/basic/src/enemy_creator.hpp
index a220008..231b7f4 100644
--- a/examples/basic/src/enemy_creator.hpp
+++ b/examples/basic/src/enemy_creator.hpp
@@ -19,9 +19,9 @@ public:
IEnemyFactory big_enemy_factory
) noexcept;
- std::unique_ptr<IEnemy> create_small_enemy() noexcept override;
+ auto create_small_enemy() noexcept -> std::unique_ptr<IEnemy> override;
- std::unique_ptr<IEnemy> create_big_enemy() noexcept override;
+ auto create_big_enemy() noexcept -> std::unique_ptr<IEnemy> override;
private:
IEnemyFactory _small_enemy_factory;
diff --git a/examples/basic/src/hero.hpp b/examples/basic/src/hero.hpp
index e4959d2..e310817 100644
--- a/examples/basic/src/hero.hpp
+++ b/examples/basic/src/hero.hpp
@@ -10,7 +10,7 @@
class Hero : public IHero, public yacppdic::AutoWirable<IHero, Hero, IWeapon>
{
public:
- Hero(std::shared_ptr<IWeapon> weapon) noexcept;
+ explicit Hero(std::shared_ptr<IWeapon> weapon) noexcept;
void fight(IEnemy &enemy) noexcept override;
diff --git a/examples/basic/src/interfaces/enemy.hpp b/examples/basic/src/interfaces/enemy.hpp
index 5f49ca6..5ad7d90 100644
--- a/examples/basic/src/interfaces/enemy.hpp
+++ b/examples/basic/src/interfaces/enemy.hpp
@@ -4,15 +4,19 @@
#include <memory>
+// NOLINTNEXTLINE(modernize-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays)
constexpr char SMALL_ENEMY_TAG[] = "small";
+
+// NOLINTNEXTLINE(modernize-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays)
constexpr char BIG_ENEMY_TAG[] = "big";
+// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
class IEnemy
{
public:
virtual ~IEnemy() noexcept = default;
- virtual int get_health() const noexcept = 0;
+ [[nodiscard]] virtual auto get_health() const noexcept -> int = 0;
virtual void do_damage(int damage) noexcept = 0;
};
diff --git a/examples/basic/src/interfaces/enemy_creator.hpp b/examples/basic/src/interfaces/enemy_creator.hpp
index 820b636..2675fea 100644
--- a/examples/basic/src/interfaces/enemy_creator.hpp
+++ b/examples/basic/src/interfaces/enemy_creator.hpp
@@ -4,12 +4,13 @@
#include <memory>
+// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
class IEnemyCreator
{
public:
virtual ~IEnemyCreator() = default;
- virtual std::unique_ptr<IEnemy> create_small_enemy() noexcept = 0;
+ virtual auto create_small_enemy() noexcept -> std::unique_ptr<IEnemy> = 0;
- virtual std::unique_ptr<IEnemy> create_big_enemy() noexcept = 0;
+ virtual auto create_big_enemy() noexcept -> std::unique_ptr<IEnemy> = 0;
};
diff --git a/examples/basic/src/interfaces/hero.hpp b/examples/basic/src/interfaces/hero.hpp
index 25e18fc..41441d6 100644
--- a/examples/basic/src/interfaces/hero.hpp
+++ b/examples/basic/src/interfaces/hero.hpp
@@ -2,6 +2,7 @@
#include "interfaces/enemy.hpp"
+// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
class IHero
{
public:
diff --git a/examples/basic/src/interfaces/weapon.hpp b/examples/basic/src/interfaces/weapon.hpp
index 7404115..78e4f42 100644
--- a/examples/basic/src/interfaces/weapon.hpp
+++ b/examples/basic/src/interfaces/weapon.hpp
@@ -1,9 +1,10 @@
#pragma once
+// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
class IWeapon
{
public:
virtual ~IWeapon() noexcept = default;
- virtual int get_strength() const noexcept = 0;
+ [[nodiscard]] virtual auto get_strength() const noexcept -> int = 0;
};
diff --git a/examples/basic/src/sword.cpp b/examples/basic/src/sword.cpp
index 5d5ec40..6c8b74e 100644
--- a/examples/basic/src/sword.cpp
+++ b/examples/basic/src/sword.cpp
@@ -1,6 +1,6 @@
#include "sword.hpp"
-int Sword::get_strength() const noexcept
+auto Sword::get_strength() const noexcept -> int
{
return _strength;
}
diff --git a/examples/basic/src/sword.hpp b/examples/basic/src/sword.hpp
index 25695b7..5ee3fef 100644
--- a/examples/basic/src/sword.hpp
+++ b/examples/basic/src/sword.hpp
@@ -7,7 +7,7 @@
class Sword : public IWeapon, public yacppdic::AutoWirable<IWeapon, Sword>
{
public:
- int get_strength() const noexcept override;
+ [[nodiscard]] auto get_strength() const noexcept -> int override;
private:
int _strength = 30;