-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys_log.cpp
62 lines (43 loc) · 1.25 KB
/
sys_log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "sys_log.h"
#include "point.h"
#include "vector.h"
#include "entity_map.h"
#include "comp_keys.h"
#include <boost/variant.hpp>
using namespace cse;
namespace {
inline std::ostream& operator<<(std::ostream& os, const Point2D& p) {
os << p.x << "," << p.y;
return os;
}
inline std::ostream& operator<<(std::ostream& os, const Vector2D& p) {
os << p.x << "," << p.y;
return os;
}
class LogToStdout : public boost::static_visitor<void> {
public:
LogToStdout(int indent=0) : indent_(indent) {}
template<typename T>
void operator()( const T& t ) const {
for ( int i = 0; i < indent_; ++i )
std::cout << " ";
std::cout << t;
}
int indent_;
};
} // namespace {
void cse::LogStdout( CompVal& val ) {
boost::apply_visitor( LogToStdout(), val );
}
void cse::LogSystem( const EntityMap& em ) {
using namespace std;
for ( auto e : em ) {
cout << "entity: " << e.first << "\n";
auto & comps = e.second;
for ( auto & c : comps ) {
cout << " key: " << c.first << " value: ";
boost::apply_visitor( LogToStdout(3), c.second );
cout << endl;
}
}
}