Skip to content

Commit 913ad31

Browse files
committed
refactor(graphics:sfml): move templated method to header file as requested
1 parent 050bdb5 commit 913ad31

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

graphics/sfml/src/window/Renderer.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,3 @@ Vector2f Renderer::_entityPixelsPosition(const Vector2i &position) {
133133
static_cast<float>(pixels.y)
134134
};
135135
}
136-
137-
template<class From, class To>
138-
std::shared_ptr<To> Renderer::_castOrThrow(std::shared_ptr<From> from) {
139-
std::shared_ptr<To> to = std::dynamic_pointer_cast<To>(from);
140-
if (!to) {
141-
throw WindowException(
142-
"Failed to cast shared pointer of:" + std::string(typeid(from).name()) + " to " + typeid(to).name(),
143-
"SFML Library Renderer::_castOrThrow"
144-
);
145-
}
146-
return to;
147-
}

graphics/sfml/src/window/Renderer.hpp

+25-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "shared/graphics/ITexture.hpp"
1212
#include "shared/graphics/types/TextureProps.hpp"
1313
#include "shared/graphics/types/TextProps.hpp"
14+
#include "common/exceptions/WindowException.hpp"
1415

1516
namespace arcade::graphics::sfml::window {
1617
class Renderer;
@@ -42,9 +43,6 @@ class arcade::graphics::sfml::window::Renderer {
4243
sf::Text _text;
4344
sf::Sprite _sprite;
4445

45-
template<class From, class To>
46-
static std::shared_ptr<To> _castOrThrow(std::shared_ptr<From> from);
47-
4846
/**
4947
* @brief Reset the text properties
5048
* @param text Text to reset
@@ -76,10 +74,10 @@ class arcade::graphics::sfml::window::Renderer {
7674
);
7775

7876
/**
79-
* @brief Align the text
80-
* @param align Text alignment
81-
* @param entitySize Entity size
82-
*/
77+
* @brief Align the text
78+
* @param align Text alignment
79+
* @param entitySize Entity size
80+
*/
8381
void _textAlign(const shared::graphics::TextAlign &align, const shared::types::Vector2i &entitySize);
8482

8583
/**
@@ -92,4 +90,23 @@ class arcade::graphics::sfml::window::Renderer {
9290
* @param props Texture properties
9391
*/
9492
void _setTextureRectAndScale(const shared::graphics::TextureProps &props);
95-
};
93+
94+
/**
95+
* @brief Cast a shared pointer from a type to another
96+
* @tparam From Type from which to cast
97+
* @tparam To Type to which cast
98+
* @param from Value to cast
99+
* @return Casted value
100+
*/
101+
template<class From, class To>
102+
static std::shared_ptr<To> _castOrThrow(std::shared_ptr<From> from) {
103+
std::shared_ptr<To> to = std::dynamic_pointer_cast<To>(from);
104+
if (!to) {
105+
throw common::exceptions::WindowException(
106+
"Failed to cast shared pointer of:" + std::string(typeid(from).name()) + " to " + typeid(to).name(),
107+
"SFML Library Renderer::_castOrThrow"
108+
);
109+
}
110+
return to;
111+
};
112+
};

0 commit comments

Comments
 (0)