Skip to content

Commit adc2165

Browse files
committed
Factor RTTI type name pretty printing out of dump.cc.
It's useful in impedance module as well.
1 parent 37dfdf6 commit adc2165

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

dump.cc

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
#include <typeinfo>
21
#include <string>
32
#include <sstream>
43

54
#include "dump.hh"
5+
#include "util.hh"
66

77
using namespace std;
88

9-
std::string graphml_dumper::type(struct prod *p)
10-
{
11-
ostringstream os;
12-
os << typeid(*p).name();
13-
string s = os.str();
14-
while(s[0] <= '9')
15-
s.erase(s.begin());
16-
return s;
17-
}
18-
199
std::string graphml_dumper::id(struct prod *p)
2010
{
2111
ostringstream os;
22-
os << type(p) << "_" << p;
12+
os << pretty_type(p) << "_" << p;
2313
return os.str();
2414
}
2515

@@ -47,7 +37,7 @@ void graphml_dumper::visit(struct prod *p)
4737
{
4838
o << "<node id=\"" << id(p) << "\">";
4939
o << "<data key=\"retries\">" << p->retries << "</data>";
50-
o << "<data key=\"label\">" << type(p) << "</data>";
40+
o << "<data key=\"label\">" << pretty_type(p) << "</data>";
5141
o << "<data key=\"scope\">" << p->scope << "</data>";
5242
o << "</node>" << endl;
5343
if (p->pprod) {

impedance.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void report()
4949
{
5050
cerr << "impedance report: " << endl;
5151
for (auto pair : occurances_in_failed_query) {
52-
cerr << " " << pair.first << ": " <<
52+
cerr << " " << pretty_type(pair.first) << ": " <<
5353
pair.second << "/" << occurances_in_ok_query[pair.first]
5454
<< " (bad/ok)";
5555
if (!matched(pair.first))

impedance.hh

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <typeinfo>
99
#include <map>
1010
#include "prod.hh"
11+
#include "util.hh"
1112
#include "log.hh"
1213

1314
struct impedance_visitor : prod_visitor {

util.hh

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef UTIL_HH
2+
#define UTIL_HH
3+
#include <typeinfo>
4+
#include <string>
5+
#include <sstream>
6+
7+
using namespace std;
8+
9+
inline std::string pretty_type(const char *raw)
10+
{
11+
ostringstream os;
12+
os << raw;
13+
string s = os.str();
14+
while(s[0] <= '9')
15+
s.erase(s.begin());
16+
return s;
17+
}
18+
19+
inline std::string pretty_type(struct prod *p)
20+
{
21+
return pretty_type(typeid(*p).name());
22+
}
23+
24+
#endif

0 commit comments

Comments
 (0)