Joedb 10.2.1
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(std::string_view 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 out.flush();
76 }
77
78 ////////////////////////////////////////////////////////////////////////////
80 ////////////////////////////////////////////////////////////////////////////
81 (
82 std::ostream &out,
83 const char *name,
84 const std::vector<std::string> &n
85 )
86 {
87 std::string id = namespace_string(n, "_") + '_' + name + "_declared\n";
88 out << "#ifndef " << id;
89 out << "#define " << id;
90 }
91
92 ////////////////////////////////////////////////////////////////////////////
93 void namespace_include_guard_close(std::ostream &out)
94 ////////////////////////////////////////////////////////////////////////////
95 {
96 out << "\n#endif\n";
97 out.flush();
98 }
99}
std::vector< std::string > split_namespace(std::string_view s)
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_open(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)
void namespace_include_guard_close(std::ostream &out)