34#ifndef OR_TOOLS_BASE_CONTAINER_LOGGING_H_
35#define OR_TOOLS_BASE_CONTAINER_LOGGING_H_
44#include "absl/base/port.h"
75 template <
typename ElementT>
76 void Log(std::ostream& out,
const ElementT& element)
const {
93 void LogClosing(std::ostream& out)
const { out <<
"\n]"; }
110 int64_t
MaxElements()
const {
return std::numeric_limits<int64_t>::max(); }
117 explicit LogShortUpToN(int64_t max_elements) : max_elements_(max_elements) {}
121 int64_t max_elements_;
137 int64_t
MaxElements()
const {
return std::numeric_limits<int64_t>::max(); }
145 : max_elements_(max_elements) {}
149 int64_t max_elements_;
164 int64_t
MaxElements()
const {
return std::numeric_limits<int64_t>::max(); }
172template <
typename IteratorT,
typename PolicyT>
174 IteratorT begin, IteratorT
end,
175 const PolicyT& policy) {
177 for (int64_t i = 0; begin !=
end && i < policy.MaxElements(); ++i, ++begin) {
179 policy.LogFirstSeparator(out);
181 policy.LogSeparator(out);
183 policy.Log(out, *begin);
186 policy.LogSeparator(out);
187 policy.LogEllipsis(out);
189 policy.LogClosing(out);
200template <
typename IteratorT,
typename PolicyT>
204 const PolicyT& policy)
205 : begin_(begin), end_(
end), policy_(policy) {}
216 std::stringstream ss;
233 using I =
typename std::underlying_type<E>::type;
234 return out << static_cast<I>(v.e_);
249template <
typename IteratorT,
typename PolicyT>
251 const IteratorT&
end,
252 const PolicyT& policy) {
262template <
typename IteratorT>
264 const IteratorT&
end) {
274template <
typename ContainerT,
typename PolicyT>
276 ->
decltype(
gtl::LogRange(container.begin(), container.end(), policy)) {
277 return gtl::LogRange(container.begin(), container.end(), policy);
286template <
typename ContainerT>
298 static_assert(std::is_enum<E>::value,
"must be an enum");
LogMultilineUpToN(int64_t max_elements)
int64_t MaxElements() const
int64_t MaxElements() const
LogShortUpToN(int64_t max_elements)
friend std::ostream & operator<<(std::ostream &out, const EnumLogger &v)
friend std::ostream & operator<<(std::ostream &out, const RangeLogger &range)
RangeLogger(const IteratorT &begin, const IteratorT &end, const PolicyT &policy)
auto LogContainer(const ContainerT &container, const PolicyT &policy) -> decltype(gtl::LogRange(container.begin(), container.end(), policy))
LogShortUpTo100 LogDefault
The default policy for new code.
detail::EnumLogger< E > LogEnum(E e)
detail::RangeLogger< IteratorT, PolicyT > LogRange(const IteratorT &begin, const IteratorT &end, const PolicyT &policy)
void LogRangeToStream(std::ostream &out, IteratorT begin, IteratorT end, const PolicyT &policy)
std::optional< int64_t > end
const std::optional< Range > & range
int64_t MaxElements() const
int64_t MaxElements() const
int64_t MaxElements() const
int64_t MaxElements() const
void Log(std::ostream &out, const ElementT &element) const
void LogEllipsis(std::ostream &out) const
void LogOpening(std::ostream &out) const
void LogSeparator(std::ostream &out) const
void LogFirstSeparator(std::ostream &out) const
void LogClosing(std::ostream &out) const
void LogSeparator(std::ostream &out) const
void LogClosing(std::ostream &out) const
void LogOpening(std::ostream &out) const
void LogFirstSeparator(std::ostream &out) const
void LogFirstSeparator(std::ostream &out) const
void LogOpening(std::ostream &out) const
void LogClosing(std::ostream &out) const
void LogSeparator(std::ostream &out) const