This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
ToString.hpp
113 lines (86 loc) · 3.26 KB
/
ToString.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/////////////////////////////////////////////////////////////////////////////////
//
// Thor C++ Library
// Copyright (c) 2011-2012 Jan Haller
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
/////////////////////////////////////////////////////////////////////////////////
/// @file
/// @brief String representation of basic SFML types
#ifndef THOR_TOSTRING_HPP
#define THOR_TOSTRING_HPP
// Note: Don't include specific headers to avoid unneeded dependencies. If one wants to
// output a certain object, he/she has already included the corresponding header anyway.
#include <Thor/Config.hpp>
#include <Aurora/Tools/Exceptions.hpp>
#include <sstream>
namespace sf
{
class Color;
template <typename T>
class Vector2;
template <typename T>
class Vector3;
template <typename T>
class Rect;
} // namespace sf
namespace thor
{
template <typename T>
struct PolarVector2;
/// @addtogroup Graphics
/// @{
/// @brief Returns a std::string representation of sf::Color.
/// @details Format: (r,g,b,a)
std::string THOR_API toString(const sf::Color& color);
/// @brief Returns a std::string representation of sf::Vector2<T>.
/// @details Format: (x,y)
template <typename T>
std::string toString(const sf::Vector2<T>& vector);
/// @brief Returns a std::string representation of sf::Vector3<T>.
/// @details Format: (x,y,z)
template <typename T>
std::string toString(const sf::Vector3<T>& vector);
/// @brief Returns a std::string representation of sf::Rect<T>.
/// @details Format: (left,top;width,height)
template <typename T>
std::string toString(const sf::Rect<T>& rect);
/// @brief Returns the string representation of thor::PolarVector<T>.
/// @details Format: (r,phi°) - ° represents the degree symbol (small circle)
template <typename T>
std::string toString(const PolarVector2<T>& vector);
/// @brief %Exception class for failed string conversions.
/// @details Is used if a string cannot be meaningfully converted to a value or vice versa.
class StringConversionException : public aurora::Exception
{
// ---------------------------------------------------------------------------------------------------------------------------
// Public member functions
public:
/// @brief Constructor
/// @param message The exception message (how the error occurred).
explicit StringConversionException(const std::string& message)
: aurora::Exception(message)
{
}
};
/// @}
} // namespace thor
#include <Thor/Graphics/Detail/ToString.inl>
#endif // THOR_TOSTRING_HPP