40 mutable std::string cache_string_;
56 [[nodiscard]]
virtual std::string
className()
const;
68 [[nodiscard]]
virtual std::string
toString(
bool enter)
const;
74 explicit operator std::string()
const;
82 explicit operator const char*()
const;
91 [[nodiscard]]
const char*
toCString(
bool enter)
const;
113 template<
typename TYPE>
122 template<Pr
intable TYPE>
131 template<EnumType TYPE>
145 template <
typename TYPE>
157 template<
typename TYPE>
171 template<
typename TYPE>
205 struct std::formatter<T> {
212 static constexpr auto parse(format_parse_context& ctx);
220 static auto format(
const T& p, format_context& ctx);
225inline original::printable::~printable() =
default;
234 std::stringstream ss;
235 ss << this->className() <<
"(" << formatString(
this) <<
")";
236 if (enter) ss <<
"\n";
240inline original::printable::operator std::string()
const {
241 return this->toString(
false);
244inline original::printable::operator
const char*()
const {
245 return this->toCString(
false);
250 this->cache_string_ = this->toString(enter);
251 return this->cache_string_.c_str();
254template<
typename TYPE>
257 std::stringstream ss;
258 ss <<
typeid(t).name() <<
"(" << formatString(&t) <<
")";
262template<original::Pr
intable TYPE>
265 std::stringstream ss;
270template <original::EnumType TYPE>
273 return formatEnum(t);
276template <
typename TYPE>
280 std::make_unique<std::string>(formatString<TYPE>(t));
281 return result->c_str();
284template <
typename TYPE>
287 const std::string enum_name =
typeid(t).name();
288 const int enum_value =
static_cast<std::underlying_type_t<TYPE>
>(t);
289 return enum_name +
"(" + std::to_string(enum_value) +
")";
293inline auto original::printable::formatString<std::nullptr_t>(
const std::nullptr_t&) -> std::string
299inline auto original::printable::formatString<std::string>(
const std::string& t) -> std::string
301 return "\"" + t +
"\"";
305inline auto original::printable::formatString<char>(
const char& t) -> std::string
307 return "'" + std::string(1, t) +
"'";
311inline auto original::printable::formatString<bool>(
const bool& t) -> std::string
313 return t ?
"true" :
"false";
316template <
typename TYPE>
322 std::stringstream ss;
328inline auto original::printable::formatString<const char>(
const char*
const &ptr) -> std::string {
329 return formatString<std::string>(ptr);
339constexpr auto std::formatter<T>::parse(std::format_parse_context &ctx) {
345auto std::formatter<T>::format(
const T &p, std::format_context &ctx) {
346 return formatter<std::string>().format(
static_cast<std::string
>(p), ctx);
Base class providing polymorphic string conversion capabilities.
Definition printable.h:39
const char * toCString(bool enter) const
Direct C-string access with formatting control.
Definition printable.h:248
static std::string formatString(const TYPE &t)
Universal value-to-string conversion.
Definition printable.h:263
static std::string formatString(TYPE *const &ptr)
Pointer-specific formatting.
friend std::ostream & operator<<(std::ostream &os, const printable &p)
Stream insertion operator for printable objects.
virtual std::string toString(bool enter) const
Generates formatted string representation.
Definition printable.h:232
virtual std::string className() const
Gets the class name for type identification.
Definition printable.h:227
static const char * formatCString(const TYPE &t)
C-string cache for temporary usage.
static std::string formatEnum(const TYPE &t)
Enum formatting utility.
static std::string formatString(const TYPE &t)
Specialization for printable types.
Checks derivation or type identity using std::derived_from.
Definition types.h:244
Main namespace for the project Original.
Definition algorithms.h:21
std::ostream & operator<<(std::ostream &os, const printable &p)
Stream insertion operator for printable objects.
Definition printable.h:332
Core type system foundations and concept definitions.