File indexing completed on 2025-01-18 09:54:48
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010 #include <iomanip>
0011 #include <iostream>
0012 #include <sstream>
0013 #include <string>
0014 #include <type_traits>
0015
0016 #include "corecel/Assert.hh"
0017
0018 #include "../ScopedStreamFormat.hh"
0019
0020 namespace celeritas
0021 {
0022 template<class T>
0023 struct ReprTraits;
0024
0025 namespace detail
0026 {
0027
0028
0029
0030
0031
0032
0033 template<class T>
0034 struct Repr
0035 {
0036 T const& obj;
0037 char const* name = nullptr;
0038 };
0039
0040
0041
0042
0043
0044 template<class T>
0045 std::ostream& operator<<(std::ostream& os, Repr<T> const& s)
0046 {
0047 ScopedStreamFormat save_fmt(&os);
0048 ReprTraits<T>::init(os);
0049 if (s.name)
0050 {
0051 ReprTraits<T>::print_type(os, s.name);
0052 os << '{';
0053 }
0054 ReprTraits<T>::print_value(os, s.obj);
0055 if (s.name)
0056 {
0057 os << '}';
0058 }
0059 return os;
0060 }
0061
0062
0063
0064
0065
0066 template<class T>
0067 std::string to_string(Repr<T> const& s)
0068 {
0069 std::ostringstream os;
0070 os << s;
0071 return os.str();
0072 }
0073
0074
0075
0076
0077 void repr_char(std::ostream& os, char value);
0078
0079 std::string char_to_hex_string(unsigned char value);
0080
0081 void print_simple_type(std::ostream& os, char const* type, char const* name);
0082
0083 template<class T>
0084 inline void
0085 print_container_type(std::ostream& os, char const* type, char const* name)
0086 {
0087 os << type << '<';
0088 ReprTraits<T>::print_type(os);
0089 os << '>';
0090 if (name)
0091 {
0092 os << ' ' << name;
0093 }
0094 }
0095
0096
0097 }
0098 }