Aeon Engine c550894
AeonGames Open Source Game Engine
Loading...
Searching...
No Matches
ToString.hpp
1/*
2Copyright (C) 2019,2025,2026 Rodrigo Jose Hernandez Cordoba
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16#ifndef AEONGAMES_TOSTRING_H
17#define AEONGAMES_TOSTRING_H
18
19#include <string>
20#include <sstream>
21
22namespace AeonGames
23{
28 {
29 using std::to_string;
30
36 template<class T>
37 std::string convert_to_string ( T&& t )
38 {
39 return to_string ( std::forward<T> ( t ) );
40 }
41 }
42
47 template<class T>
48 std::string to_string ( T&& t )
49 {
50 return to_string_namespace::convert_to_string ( std::forward<T> ( t ) );
51 }
52
58 template<class T>
59 std::string ToString ( const T& t )
60 {
61 std::ostringstream stream;
62 const uint8_t* pointer = &t;
63 for ( size_t i = 0; i < sizeof ( T ); ++i )
64 {
65 stream << "0x" << std::hex << pointer[i];
66 }
67 return stream.str();
68 }
69
71 template<> std::string ToString ( const int& t )
72 {
73 return std::to_string ( t );
74 }
75
76 template<> std::string ToString ( const long& t )
77 {
78 return std::to_string ( t );
79 }
80
81 template<> std::string ToString ( const long long& t )
82 {
83 return std::to_string ( t );
84 }
85
86 template<> std::string ToString ( const unsigned& t )
87 {
88 return std::to_string ( t );
89 }
90
91 template<> std::string ToString ( const unsigned long& t )
92 {
93 return std::to_string ( t );
94 }
95
96 template<> std::string ToString ( const unsigned long long& t )
97 {
98 return std::to_string ( t );
99 }
100
101 template<> std::string ToString ( const float& t )
102 {
103 return std::to_string ( t );
104 }
105
106 template<> std::string ToString ( const double& t )
107 {
108 return std::to_string ( t );
109 }
110}
111#endif
Internal namespace for ADL-based to_string resolution.
Definition ToString.hpp:28
std::string convert_to_string(T &&t)
Convert a value to string via ADL lookup.
Definition ToString.hpp:37
<- This is here just for the literals
Definition AABB.hpp:31
std::string to_string(T &&t)
Generic to_string using ADL to find the best overload.
Definition ToString.hpp:48
std::string ToString(const T &t)
Convert an arbitrary type to its hex byte string representation.
Definition ToString.hpp:59