#include #include #include #include #include #if !defined( __OpenBSD__) #error this file only works with OpenBSD #endif struct Base { int x; std::string text; }; template< class T> void output( const T& x, std::ostream& out, int nesting) { out << std::string( 4*nesting, ' ') << x << "\n"; } template< class T> void outputcmm_reflect( T& data, const std::type_info& static_type, const char* name, std::ostream& out, int nesting) { out << std::string( 4*nesting, ' ') << name << " (" << static_type.name() << "):\n"; output( data, out, nesting+1); } @cmm_memberreflectfn void output( const Base& b, std::ostream& out, int nesting); @cmm_memberreflectfn void output( timespec& s, std::ostream& out, int nesting); @cmm_memberreflectfn void output( struct stat& s, std::ostream& out, int nesting); @cmm_memberreflectfn void output( FILE& s, std::ostream& out, int nesting); @cmm_memberreflectfn void output( __sbuf& s, std::ostream& out, int nesting); int main() { Base b; b.x = 42; b.text = "forty-two"; output( b, std::cout, 1); std::cout << "\n"; struct stat s; if ( stat( ".", &s)) { std::cerr << "stat() failed\n"; } std::cout << "s =\n"; output ( s, std::cout, 1); std::cout << "\n"; FILE* f = fopen( "/dev/null", "r"); if ( !f) { std::cerr << "fopen failed\n"; } else { std::cout << "FILE f is:\n"; output( *f, std::cout, 1); std::cout << "\n"; } return 0; }