Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
nested_namespace.cpp
Go to the documentation of this file.
2
3namespace joedb
4{
5 static const std::string scope_delimiter{"::"};
6
7 ////////////////////////////////////////////////////////////////////////////
8 std::vector<std::string> split_namespace(const std::string &s)
9 ////////////////////////////////////////////////////////////////////////////
10 {
11 std::vector<std::string> result;
12
13 size_t current = 0;
14 size_t next = 0;
15
16 while ((next = s.find(scope_delimiter, current)) != std::string::npos)
17 {
18 result.emplace_back(s.substr(current, next - current));
19 current = next + scope_delimiter.size();
20 }
21
22 result.emplace_back(s.substr(current, s.size() - current));
23
24 return result;
25 }
26
27 ////////////////////////////////////////////////////////////////////////////
29 ////////////////////////////////////////////////////////////////////////////
30 (
31 std::ostream &out,
32 const std::vector<std::string> &n,
33 const char *delimiter
34 )
35 {
36 out << namespace_string(n, delimiter);
37 }
38
39 ////////////////////////////////////////////////////////////////////////////
40 std::string namespace_string
41 ////////////////////////////////////////////////////////////////////////////
42 (
43 const std::vector<std::string> &n,
44 const char *delimiter
45 )
46 {
47 std::string result;
48
49 for (size_t i = 0;;)
50 {
51 result += n[i];
52 if (++i < n.size())
53 result += delimiter;
54 else
55 break;
56 }
57
58 return result;
59 }
60
61 ////////////////////////////////////////////////////////////////////////////
62 void namespace_open(std::ostream &out, const std::vector<std::string> &n)
63 ////////////////////////////////////////////////////////////////////////////
64 {
65 out << "namespace ";
66 namespace_write(out, n);
67 out << "\n{";
68 }
69
70 ////////////////////////////////////////////////////////////////////////////
71 void namespace_close(std::ostream &out, const std::vector<std::string> &n)
72 ////////////////////////////////////////////////////////////////////////////
73 {
74 out << "}\n";
75 }
76
77 ////////////////////////////////////////////////////////////////////////////
79 ////////////////////////////////////////////////////////////////////////////
80 (
81 std::ostream &out,
82 const char *name,
83 const std::vector<std::string> &n
84 )
85 {
86 std::string id = namespace_string(n, "_") + '_' + name + "_declared\n";
87 out << "#ifndef " << id;
88 out << "#define " << id;
89 }
90}
void namespace_open(std::ostream &out, const std::vector< std::string > &n)
void namespace_close(std::ostream &out, const std::vector< std::string > &n)
void namespace_write(std::ostream &out, const std::vector< std::string > &n, const char *delimiter)
void namespace_include_guard(std::ostream &out, const char *name, const std::vector< std::string > &n)
std::string namespace_string(const std::vector< std::string > &n, const char *delimiter)
std::vector< std::string > split_namespace(const std::string &s)
Definition Blob.h:7