pupene  0.2.0
debug.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "debug-pupper.h"
4 #include "pup.h"
5 #include <string>
6 #include <sstream>
7 
8 /** \file
9  * Introspection utilities.
10  *
11  * @see DebugPupper
12  */
13 namespace pupene {
14  /**
15  * Wraps existing `pupper` in a DebugPupper. Adheres to the
16  * [PupPolicy] of wrapped pupper.
17  */
18  template <typename Pupper>
19  DebugPupper<Pupper> debug_pupper(Pupper& pupper,
20  std::ostream& out) {
21 
22  return DebugPupper<Pupper>{pupper, out};
23  }
24 
25  /**
26  * DebugPupper wrapping a NullPupper.
27  */
28  DebugPupper<NullPupper> debug_pupper(std::ostream& out = std::cout);
29 
30  /** Returns a string representation of `object`. */
31  template <typename T>
32  std::string to_debug(T& object) {
33  std::ostringstream out;
34 
35  auto pupper = debug_pupper(out);
36  fns::pup(pupper, object, {});
37  out.flush();
38 
39  return out.str();
40  }
41 
42  /** Returns a string representation of `object`. */
43  template <typename T>
44  std::string to_debug(const T& object) {
45  return to_debug(const_cast<T&>(object));
46  }
47 }
This pupper wraps another pupper, logging each call to Wrapped::begin(), Wrapped::pup() and wrapped::...
Definition: debug-pupper.h:61
Definition: debug.cpp:4
DebugPupper< Pupper > debug_pupper(Pupper &pupper, std::ostream &out)
Wraps existing pupper in a DebugPupper.
Definition: debug.h:19
Does nothing by itself.
Definition: null-pupper.h:15
std::string to_debug(T &object)
Returns a string representation of object.
Definition: debug.h:32
DebugPupper< NullPupper > debug_pupper(std::ostream &out)
DebugPupper wrapping a NullPupper.
Definition: debug.cpp:5
std::string to_debug(const T &object)
Returns a string representation of object.
Definition: debug.h:44