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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
# toml++ — Code Style
## Overview
This document describes the code conventions and formatting rules used in the toml++ project, derived from the `.clang-format` configuration and source code patterns.
---
## Formatting Rules (`.clang-format`)
The project uses clang-format with these key settings:
### Indentation
- **IndentWidth**: 4 (tabs are used, tab width 4)
- **UseTab**: `ForContinuationAndIndentation`
- **TabWidth**: 4
- **ContinuationIndentWidth**: 4
- **ConstructorInitializerIndentWidth**: 4
- **AccessModifierOffset**: -4 (access specifiers at class indent level)
- **IndentCaseLabels**: true
- **NamespaceIndentation**: All
### Braces
- **BreakBeforeBraces**: Allman style
- Functions, classes, structs, enums, namespaces, control statements — all open brace on new line:
```cpp
namespace toml
{
class node
{
public:
void method()
{
if (condition)
{
// ...
}
}
};
}
```
### Alignment
- **AlignConsecutiveAssignments**: true
- **AlignConsecutiveDeclarations**: true
- **AlignTrailingComments**: true
- **AlignOperands**: true
- **AlignAfterOpenBracket**: Align
### Line Length
- **ColumnLimit**: 120
### Other Settings
- **AllowShortFunctionsOnASingleLine**: Empty (empty functions on one line)
- **AllowShortIfStatementsOnASingleLine**: Never
- **AllowShortLoopsOnASingleLine**: false
- **AlwaysBreakTemplateDeclarations**: Yes
- **BinPackArguments**: false
- **BinPackParameters**: false
- **PointerAlignment**: Left (`int* ptr`, not `int *ptr`)
- **SpaceAfterTemplateKeyword**: true
- **SortIncludes**: false (manual include ordering)
---
## Naming Conventions
### Macros
All macros use the `TOML_` prefix with `UPPER_SNAKE_CASE`:
```cpp
TOML_HEADER_ONLY
TOML_EXCEPTIONS
TOML_ENABLE_PARSER
TOML_ENABLE_FORMATTERS
TOML_ENABLE_WINDOWS_COMPAT
TOML_UNRELEASED_FEATURES
TOML_LIB_MAJOR
TOML_NAMESPACE_START
TOML_NAMESPACE_END
TOML_EXPORTED_CLASS
TOML_EXPORTED_MEMBER_FUNCTION
TOML_EXPORTED_STATIC_FUNCTION
TOML_EXPORTED_FREE_FUNCTION
```
### Namespaces
- Public API: `toml` namespace (aliased from a versioned namespace `toml::vN`)
- Internal implementation: `toml::impl` (aka `toml::vN::impl`)
- Macro-managed namespace boundaries:
```cpp
TOML_NAMESPACE_START // opens toml::v3
{
// public API
}
TOML_NAMESPACE_END // closes
TOML_IMPL_NAMESPACE_START // opens toml::v3::impl
{
// internal details
}
TOML_IMPL_NAMESPACE_END
```
### Types and Classes
- `snake_case` for all types: `node`, `table`, `array`, `value`, `path`, `path_component`, `parse_result`, `parse_error`, `source_region`, `source_position`, `date_time`, `time_offset`, `node_view`, `key`
- Template parameters: `PascalCase` (`ValueType`, `IsConst`, `ViewedType`, `ElemType`)
### Member Variables
- Private members use trailing underscore: `val_`, `flags_`, `elems_`, `map_`, `inline_`, `source_`, `components_`
- No prefix for public struct fields: `year`, `month`, `day`, `line`, `column`, `begin`, `end`, `path`
### Methods
- `snake_case`: `is_table()`, `as_array()`, `value_or()`, `push_back()`, `emplace_back()`, `is_homogeneous()`, `for_each()`, `parse_file()`, `at_path()`
### Enums
- `snake_case` enum type names: `node_type`, `value_flags`, `format_flags`, `path_component_type`
- `snake_case` enum values: `node_type::string`, `value_flags::format_as_hexadecimal`, `format_flags::indent_sub_tables`
---
## Header Organization
### File Pairs
Most features have a `.hpp` declaration header and a `.inl` implementation file:
```
node.hpp / node.inl
table.hpp / table.inl
array.hpp / array.inl
parser.hpp / parser.inl
formatter.hpp / formatter.inl
```
### Include Guards
Headers use `#pragma once` (no traditional include guards).
### Header Structure
Typical header layout:
```cpp
// license header comment
#pragma once
#include "preprocessor.hpp" // macros and config
#include "forward_declarations.hpp" // forward declarations
// ... other includes
// Header-only mode guard
#if defined(TOML_IMPLEMENTATION) || !TOML_HEADER_ONLY
TOML_NAMESPACE_START
{
// declarations / implementations
}
TOML_NAMESPACE_END
#endif // TOML_IMPLEMENTATION
```
### Export Annotations
Exported symbols use macros for DLL visibility:
```cpp
TOML_EXPORTED_CLASS table : public node
{
TOML_EXPORTED_MEMBER_FUNCTION void clear() noexcept;
TOML_EXPORTED_STATIC_FUNCTION static table parse(...);
};
TOML_EXPORTED_FREE_FUNCTION parse_result parse(std::string_view);
```
---
## Preprocessor Conventions
### Compiler Detection
```cpp
TOML_GCC // GCC
TOML_CLANG // Clang
TOML_MSVC // MSVC
TOML_ICC // Intel C++
TOML_ICC_CL // Intel C++ (MSVC frontend)
```
### Feature Detection
```cpp
TOML_HAS_CHAR8 // char8_t available
TOML_HAS_CUSTOM_OPTIONAL_TYPE // user-provided optional
TOML_INT_CHARCONV // charconv for integers
TOML_FLOAT_CHARCONV // charconv for floats
```
### Warning Management
Extensive `#pragma` blocks suppress known-benign warnings per compiler:
```cpp
TOML_PUSH_WARNINGS
TOML_DISABLE_WARNINGS
// ... code ...
TOML_POP_WARNINGS
TOML_DISABLE_ARITHMETIC_WARNINGS
TOML_DISABLE_SPAM_WARNINGS
```
---
## Conditional Compilation Patterns
Major features are conditionally compiled:
```cpp
#if TOML_ENABLE_PARSER
// parser code
#endif
#if TOML_ENABLE_FORMATTERS
// formatter code
#endif
#if TOML_ENABLE_WINDOWS_COMPAT
// wchar_t / wstring overloads
#endif
#if TOML_EXCEPTIONS
// exception-based error handling
#else
// return-code error handling
#endif
```
---
## Documentation Conventions
- Source comments use `//` style (not `/* */`)
- Doxygen is used for API documentation (the public `toml.hpp` single-header has `///` comments)
- Internal implementation headers have minimal comments — the code is expected to be self-documenting
---
## Build System Conventions
- Primary build: **Meson** (`meson.build`, `meson_options.txt`)
- Secondary: **CMake** (`CMakeLists.txt`)
- All configuration macros can be set via build system options or via `#define` before including the header
- Meson option names mirror the macro names: `is_header_only` → `TOML_HEADER_ONLY`
---
## Related Documentation
- [architecture.md](architecture.md) — Project structure and design
- [building.md](building.md) — Build system details
- [testing.md](testing.md) — Testing conventions
|