Rheolef  7.2
an efficient C++ finite element environment
 
Loading...
Searching...
No Matches
pretty_name.cc
Go to the documentation of this file.
1
21
22#include "rheolef/pretty_name.h"
23
24#include <cxxabi.h>
25#include <cstdlib>
26
27// inspirated from: http://stackoverflow.com/questions/2885597/c-template-name-pretty-print
28// If you've got minor improvements, put them in or in a comment.
29// If you've got a quite different version you can always put it in another answer.
30// @aaa - Georg Fritzsche May 22 at 3:21
31
32namespace rheolef {
33
34std::string
35indent (std::string str, const std::string &indent = " ")
36{
37 std::string indent_ = std::string("\n");
38 size_t token = 0;
39
40 bool one_line = false;
41 while ((token = str.find_first_of("<>,", token)) != std::string::npos) {
42 size_t size = str.size();
43 size_t close, open, comma;
44
45 switch(str[token]) {
46 case '<':
47 close = str.find(">", token+1);
48 open = str.find("<", token+1);
49 comma = str.find(",", token+1);
50 one_line = !(close > open) && !(comma < close);
51
52 if (one_line) break;
53 indent_.append(indent);
54
55 case ',':
56 str.insert(token + 1, indent_);
57 break;
58
59 case '>':
60 if (!one_line) {
61 indent_.erase(indent_.size() - indent.size());
62 str.insert(token, indent_);
63 }
64 one_line = false;
65 }
66
67 token += 1 + str.size() - size;
68
69 const size_t nw = str.find_first_not_of(" ", token);
70 if(nw != std::string::npos) {
71 str.erase(token, nw-token);
72 }
73 }
74
75 return str;
76}
77std::string
78typeid_name (const char* name, bool do_indent)
79{
80// #ifdef HAVE_CXA_DEMANGLE
81 size_t size;
82 int status;
83 char *buf = abi::__cxa_demangle (name, NULL, &size, &status);
84 if (status != 0) throw status;
85 std::string string(buf);
86 free(buf);
87 if (do_indent) return indent(string); else return string;
88// #else
89// return name;
90// #endif
91}
92
93} // namespace rheolef
This file is part of Rheolef.
std::string typeid_name(const char *name, bool do_indent)
std::string indent(std::string str, const std::string &indent=" ")