Hippo is short for Hierarchical Information as Pretty-Printed Objects.
It is a header-only library for C++17 that makes it easy to display the contents of nested data structures in an intelligent and legible manner.
To get started, take a look at the released documentation on Read the Docs, or view the latest documentation of the master branch here.
- Out-of-the-box printers for all builtin types and most standard library types
- Printers for user-defined types created via reflection macros (
class
/struct
andenum
/enum class
) - All types, even polymorphic types, can be printed without modifying the type
- Configurable indentation level and output text column count
Custom class types can be made printable with the reflection helper macros HIPPO_CLASS_BEGIN
, HIPPO_MEMBER
, and HIPPO_CLASS_END
.
#include "hippo/hippo.h"
#include "hippo/std/map.h"
#include <iostream>
struct Foo {
int a;
int b;
};
struct Bar {
std::map<int, Foo> foos;
};
// Make Foo printable
HIPPO_CLASS_BEGIN(Foo)
HIPPO_MEMBER(a)
HIPPO_MEMBER(b)
HIPPO_CLASS_END()
// Make Bar printable
HIPPO_CLASS_BEGIN(Bar)
HIPPO_MEMBER(foos)
HIPPO_CLASS_END()
int main() {
Bar bar;
bar.foos[1] = Foo{0, 0};
bar.foos[2] = Foo{1, 2};
hippo::configuration config;
config.indent = 2; // 2 spaces per indentation
std::cout << "Expanded:" << std::endl;
config.width = 0; // keep output as narrow as possible
hippo::print_to(std::cout, bar, config);
std::cout << "Condensed:" << std::endl;
config.width = 80; // try to keep output under 80 chars
hippo::print_to(std::cout, bar, config);
return 0;
}
When run, this program produces:
Expanded:
Bar {
foos: std::map [
(
key: 1,
value: Foo {
a: 0,
b: 0
}
),
(
key: 2,
value: Foo {
a: 1,
b: 2
}
)
]
}
Condensed:
Bar {
foos: std::map [
( key: 1, value: Foo { a: 0, b: 0 } ),
( key: 2, value: Foo { a: 1, b: 2 } )
]
}
"hippo" by Ed Harrison licensed under CC BY 3.0