Added explicit keyword to all constructors.

This commit is contained in:
Felix Ableitner 2013-03-30 16:39:46 +01:00
parent 0c29dac282
commit 602a6a5e66
13 changed files with 61 additions and 14 deletions

View File

@ -21,7 +21,7 @@ class World;
class Game : private sf::NonCopyable {
// Public functions.
public:
Game(sf::RenderWindow& window);
explicit Game(sf::RenderWindow& window);
~Game();
void loop();

View File

@ -20,7 +20,7 @@ class Yaml;
class Character : public Sprite {
// Public functions.
public:
Character(World& world, const Data& data, const Yaml& config);
explicit Character(World& world, const Data& data, const Yaml& config);
virtual ~Character() = 0;
void onDamage(int damage);

View File

@ -37,7 +37,7 @@ public:
*/
class Data {
public:
Data(const sf::Vector2f& position,
explicit Data(const sf::Vector2f& position,
Category category, unsigned short mask,
const sf::Vector2f& direction = sf::Vector2f(0, 0));
const sf::Vector2f& position;
@ -56,7 +56,7 @@ public:
// Public functions.
public:
Sprite(const Data& data, const Yaml& config);
explicit Sprite(const Data& data, const Yaml& config);
virtual ~Sprite() = 0;
sf::Vector2f getPosition() const;

View File

@ -18,7 +18,7 @@ class Yaml;
class Bullet : public Particle {
// Public functions.
public:
Bullet(const sf::Vector2f& position, Sprite& shooter,
explicit Bullet(const sf::Vector2f& position, Sprite& shooter,
sf::Vector2f direction, const Yaml& config);
void onCollide(std::shared_ptr<Sprite> other);

View File

@ -27,7 +27,7 @@ class Particle;
class Weapon : public Emitter {
// Public functions.
public:
Weapon(World& world, Sprite& holder, const Yaml& config);
explicit Weapon(World& world, Sprite& holder, const Yaml& config);
void pullTrigger();
void releaseTrigger();

View File

@ -17,7 +17,7 @@ class Sprite;
class Emitter {
// Public functions.
public:
Emitter(World& world);
explicit Emitter(World& world);
virtual ~Emitter();
// Protected functions.

View File

@ -18,7 +18,7 @@ class Yaml;
class Particle : public Sprite {
// Public functions.
public:
Particle(const Yaml& config, const Data& data);
explicit Particle(const Yaml& config, const Data& data);
virtual ~Particle();
};

View File

@ -15,7 +15,7 @@ class Yaml;
class Corpse : public Sprite {
// Public functions.
public:
Corpse(const sf::Vector2f& position, const Yaml& config);
explicit Corpse(const sf::Vector2f& position, const Yaml& config);
};
#endif /* DG_CORPSE_H_ */

View File

@ -16,7 +16,7 @@ class Yaml;
class Enemy : public Character {
// Public functions.
public:
Enemy(World& world, const sf::Vector2f& position, const Yaml& config);
explicit Enemy(World& world, const sf::Vector2f& position, const Yaml& config);
};
#endif /* DG_ENEMY_H_ */

View File

@ -31,7 +31,7 @@ public:
// Public functions.
public:
Player(World& world, const sf::Vector2f& position, const Yaml& config);
explicit Player(World& world, const sf::Vector2f& position, const Yaml& config);
void setCrosshairPosition(const sf::Vector2f& position);
void pullTrigger();

View File

@ -32,7 +32,7 @@ public:
// Public functions.
public:
TileManager(World& world);
explicit TileManager(World& world);
void insertTile(const TilePosition& position, Type type);
void removeTile(const TilePosition& position);
@ -57,7 +57,7 @@ private:
class TileManager::Tile : public Sprite {
// Public functions.
public:
Tile(Type type, const TilePosition& position);
explicit Tile(Type type, const TilePosition& position);
Type getType() const;
TilePosition getTilePosition() const;

View File

@ -21,7 +21,7 @@
class Yaml {
// Public functions.
public:
Yaml(const std::string& filename);
explicit Yaml(const std::string& filename);
~Yaml();
std::string getFilename() const;

47
source/util/Yaml.inl Normal file
View File

@ -0,0 +1,47 @@
/*
* Yaml.h
*
* Created on: 30.03.2013
* Author: Felix
*/
#include <SFML/System.hpp>
#include "Log.h"
/**
* Stream output operators to specialize Yaml::get for other types.
* Error handling is done in Yaml::get.
*/
namespace {
void operator>>(const YAML::Node& node, sf::Vector2i& vector) {
node[0] >> vector.x;
node[1] >> vector.y;
}
void operator>>(const YAML::Node& node, sf::Vector2f& vector) {
node[0] >> vector.x;
node[1] >> vector.y;
}
}
/**
* Gets a value of a specified type by key. Returns default value on error.
*
* @param key The string by which to select the return value.
* @tparam T The type of the return value.
* @return The value of the specified key.
*/
template <typename T>
T Yaml::get(const std::string& key, const T& defaultValue) const {
try {
const YAML::Node* node = mNode.FindValue(key);
T value;
*node >> value;
return value;
}
catch (YAML::InvalidScalar&) {
LOG_W("Failed to get key " << key << " from " << mFolder << mFilename);
return defaultValue;
}
};