25#ifndef LSST_GAUSS2D_OBJECT_H
26#define LSST_GAUSS2D_OBJECT_H
31namespace lsst::gauss2d {
46 static constexpr std::string_view NULL_STR_GENERAL =
"None";
47 static constexpr std::string_view PY_NAMESPACE_SEPARATOR =
".";
49 static std::string_view null_str(
const std::string_view &namespace_separator) {
69 virtual std::string
repr(
bool name_keywords =
false,
73 virtual std::string
str()
const = 0;
75 friend std::ostream &operator<<(std::ostream &out,
const Object &obj) {
82std::string repr_ptr(T ptr,
bool name_keywords, std::string_view namespace_separator) {
83 return ptr ? ptr->repr(name_keywords, namespace_separator)
84 : std::string(Object::null_str(namespace_separator));
88std::string repr_iter_ptr(
const T &container,
bool name_keywords =
false,
90 std::string str =
"[";
91 for (
auto &obj : container) {
92 str += repr_ptr(obj, name_keywords, namespace_separator) +
", ";
94 auto size_str = str.size();
95 if (size_str > 1) str = str.substr(0, size_str - 2);
100template <
bool is_wrapper,
typename T>
101std::string repr_iter_ref(
const T &container,
bool name_keywords =
false,
103 std::string str =
"[";
104 for (
const auto &obj : container) {
105 if constexpr (is_wrapper) {
106 str += obj.get().repr(name_keywords, namespace_separator);
108 str += obj.repr(name_keywords, namespace_separator);
112 auto size_str = str.size();
113 if (size_str > 1) str = str.substr(0, size_str - 2);
117template <
bool is_wrapper,
typename T>
118std::string repr_map_ref(
const T &container,
bool name_keywords =
false,
120 std::string str =
"{";
121 for (
const auto &[obj, value] : container) {
122 if constexpr (is_wrapper) {
123 str += obj.get().repr(name_keywords, namespace_separator) +
": " + std::to_string(value) +
", ";
125 str += obj.repr(name_keywords, namespace_separator) +
": " + std::to_string(value) +
", ";
128 return str.substr(0, str.size() - 2 * (container.size() > 0)) +
"}";
132std::string str_ptr(T ptr) {
133 return ptr ? ptr->str() : std::string(Object::NULL_STR_GENERAL);
137std::string str_iter_ptr(
const T &container) {
138 std::string str =
"[";
139 for (
const auto &obj : container) {
140 str += str_ptr(obj) +
", ";
142 auto size_str = str.size();
143 if (size_str > 1) str = str.substr(0, size_str - 2);
147template <
bool is_wrapper,
typename T>
148std::string str_iter_ref(
const T &container) {
149 std::string str =
"[";
150 for (
const auto &obj : container) {
151 if constexpr (is_wrapper) {
152 str += obj.get().str();
158 auto size_str = str.size();
159 if (size_str > 1) str = str.substr(0, size_str - 2);
163template <
bool is_wrapper,
typename T>
164std::string str_map_ref(
const T &container) {
165 std::string str =
"{";
166 for (
const auto &[obj, value] : container) {
167 if constexpr (is_wrapper) {
168 str += obj.get().str() +
": " + std::to_string(value) +
", ";
170 str += obj.str() +
": " + std::to_string(value) +
", ";
173 return str.substr(0, str.size() - 2 * (container.size() > 0)) +
"}";
177void stream_iter_ref(
const T &container, std::ostream &stream) {
179 for (
const auto &obj : container) stream << obj <<
",";
static constexpr std::string_view CC_NAMESPACE_SEPARATOR
The C++ namespace separator.
Definition object.h:45
virtual std::string repr(bool name_keywords=false, std::string_view namespace_separator=CC_NAMESPACE_SEPARATOR) const =0
virtual std::string str() const =0
Return a brief, human-readable string representation of this.