Skip to content

Commit a4b100c

Browse files
authored
Fix not being able to include multiple flatdata schemas if they use the same multivector bit width (#224)
* Move __builtin into the same namespace as the archive using it Signed-off-by: Christian Vetter <[email protected]> * Adjust README Signed-off-by: Christian Vetter <[email protected]>
1 parent a28f971 commit a4b100c

File tree

17 files changed

+629
-318
lines changed

17 files changed

+629
-318
lines changed

flatdata-cpp/test/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ flatdata_generate_source(generate_flatdata_test_code
44
${CMAKE_CURRENT_SOURCE_DIR}/test_structures.flatdata
55
${CMAKE_CURRENT_BINARY_DIR}/generated/test_structures.hpp)
66

7+
flatdata_generate_source(generate_flatdata_test_code2
8+
${CMAKE_CURRENT_SOURCE_DIR}/test_structures2.flatdata
9+
${CMAKE_CURRENT_BINARY_DIR}/generated/test_structures2.hpp)
10+
711
flatdata_generate_source(generate_flatdata_test_case_ranges
812
${CMAKE_CURRENT_SOURCE_DIR}/../../test_cases/archives/ranges.flatdata
913
${CMAKE_CURRENT_BINARY_DIR}/generated/ranges.hpp)
1014

1115
add_executable(flatdata_test ${TEST_FLATDATA_SOURCES})
12-
add_dependencies(flatdata_test generate_flatdata_test_code generate_flatdata_test_case_ranges)
16+
add_dependencies(flatdata_test generate_flatdata_test_code generate_flatdata_test_code2 generate_flatdata_test_case_ranges)
1317

1418
target_include_directories(flatdata_test
1519
PRIVATE ${Boost_INCLUDE_DIRS}

flatdata-cpp/test/GeneratedArchiveTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#include "test_structures.hpp"
77

8+
// include to make sure we can compile if we have two identical multivector resources in different
9+
// namespaces
10+
#include "test_structures2.hpp"
11+
812
#include <flatdata/FileResourceStorage.h>
913
#include <flatdata/MemoryResourceStorage.h>
1014
#include <boost/filesystem.hpp>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace test_structures2 {
2+
3+
struct AStruct {
4+
value : u64 : 8;
5+
}
6+
7+
// A 1:1 copy of the same multivector as in test-structures, makes sure we do not have clashes in builtins
8+
archive SimpleResources {
9+
multivector_resource: multivector< 33, AStruct >;
10+
}
11+
12+
} // namespace test_structures2

flatdata-generator/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The `flatdata` generator works in several stages which are clearly separated fro
5656

5757
- **Add builtin structures** if any of the resources require them. For
5858
example, `multivector< N, ... >` requires
59-
`_builtin.multivector.IndexTypeN` to be available.
59+
`_builtin.multivector.IndexTypeN` to be available in the parent namespace.
6060
- **Add constant references** to all archives so that constants are
6161
available for schema resolution.
6262

flatdata-generator/flatdata/generator/tree/builder.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def _build_node_tree(definition):
113113

114114

115115
def _append_builtin_structures(root):
116-
for node in root.iterate(Multivector):
117-
namespace = _ensure_namespace(root, "._builtin.multivector")
116+
multivectors = list(root.iterate(Multivector))
117+
for node in multivectors:
118+
namespace = _ensure_namespace(root, node.parent.parent.path + "._builtin.multivector")
118119
for builtin in node.builtins:
119120
found = namespace.get_relative(builtin.name)
120121
if found is None:
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using DataType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
1+
using DataType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
22
const DataType& data( ) const;
33

4-
using OptionalDataType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
4+
using OptionalDataType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
55
const boost::optional< OptionalDataType >& optional_data( ) const;
66

7-
using DataU64IndexType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
7+
using DataU64IndexType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
88
const DataU64IndexType& data_u64_index( ) const;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using DataType = flatdata::MultiVector< ::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
2-
using DataReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
1+
using DataType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
2+
using DataReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType8, ::n::S, ::n::T >;
33
DataType start_data( );
44

5-
using OptionalDataType = flatdata::MultiVector< ::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
6-
using OptionalDataReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
5+
using OptionalDataType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
6+
using OptionalDataReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType16, ::n::S, ::n::T >;
77
OptionalDataType start_optional_data( );
88

9-
using DataU64IndexType = flatdata::MultiVector< ::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
10-
using DataU64IndexReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
9+
using DataU64IndexType = flatdata::MultiVector< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
10+
using DataU64IndexReaderType = flatdata::MultiArrayView< ::n::_builtin::multivector::IndexType64, ::n::S, ::n::T >;
1111
DataU64IndexType start_data_u64_index( );

flatdata-generator/tests/generators/cpp_expectations/archives/namespaces.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ class XBuilder : public flatdata::ArchiveBuilder
244244

245245
} // namespace m
246246

247+
namespace a {
247248
namespace _builtin {
248249
namespace multivector {
249250

@@ -299,7 +300,7 @@ union IndexType32Template
299300
typedef IndexType32Template< flatdata::Reader > IndexType32;
300301
typedef IndexType32Template< flatdata::Writer > IndexType32Mutator;
301302

302-
}} // namespace _builtin.multivector
303+
}}} // namespace a._builtin.multivector
303304

304305
namespace a {
305306

@@ -328,7 +329,7 @@ class A : public flatdata::Archive
328329
using ListType = flatdata::ArrayView< ::m::S >;
329330
const ListType& list( ) const;
330331

331-
using MultiType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType32, ::n::S >;
332+
using MultiType = flatdata::MultiArrayView< ::a::_builtin::multivector::IndexType32, ::n::S >;
332333
const MultiType& multi( ) const;
333334

334335
using InnerType = ::n::X;
@@ -374,8 +375,8 @@ class ABuilder : public flatdata::ArchiveBuilder
374375
ListType start_list( );
375376
bool set_list( ListReaderType data );
376377

377-
using MultiType = flatdata::MultiVector< ::_builtin::multivector::IndexType32, ::n::S >;
378-
using MultiReaderType = flatdata::MultiArrayView< ::_builtin::multivector::IndexType32, ::n::S >;
378+
using MultiType = flatdata::MultiVector< ::a::_builtin::multivector::IndexType32, ::n::S >;
379+
using MultiReaderType = flatdata::MultiArrayView< ::a::_builtin::multivector::IndexType32, ::n::S >;
379380
MultiType start_multi( );
380381

381382

@@ -887,6 +888,7 @@ XBuilder::set_payload( PayloadReaderType data )
887888

888889
} // namespace m
889890

891+
namespace a {
890892
namespace _builtin {
891893
namespace multivector {
892894
namespace internal
@@ -994,7 +996,7 @@ std::string IndexType32Template< Member >::describe( size_t /*unused*/ ) const
994996
}
995997
return ss.str( );
996998
}
997-
}} // namespace _builtin.multivector
999+
}}} // namespace a._builtin.multivector
9981000

9991001
namespace a {
10001002
namespace internal
@@ -1238,7 +1240,7 @@ ABuilder::set_list( ListReaderType data )
12381240
inline auto ABuilder::start_multi( ) -> MultiType
12391241
{
12401242
check_created( );
1241-
return storage( ).create_multi_vector< ::_builtin::multivector::IndexType32, ::n::S >( "multi", internal::A__multi__schema__ );
1243+
return storage( ).create_multi_vector< ::a::_builtin::multivector::IndexType32, ::n::S >( "multi", internal::A__multi__schema__ );
12421244
}
12431245

12441246
inline auto

flatdata-generator/tests/generators/dot_expectations/archives/multivector.dot

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ subgraph cluster__n_A_data
1818
fillcolor="#C4E6F8";
1919

2020

21-
_n_A_data__builtin_multivector_IndexType8 [label=<
21+
_n_A_data_n__builtin_multivector_IndexType8 [label=<
2222
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
2323
<tr>
2424
<td bgcolor="#257FAD">
2525
<b><font color="#EBF8FF">IndexType8</font></b>
2626
</td>
2727
</tr>
2828
<tr>
29-
<td bgcolor="#EBF8FF" port="port__n_A_data__builtin_multivector_IndexType8_value">
29+
<td bgcolor="#EBF8FF" port="port__n_A_data_n__builtin_multivector_IndexType8_value">
3030
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">8</font>
3131
</td>
3232
</tr>
@@ -71,15 +71,15 @@ subgraph cluster__n_A_optional_data
7171
fillcolor="#C4E6F8";
7272

7373

74-
_n_A_optional_data__builtin_multivector_IndexType16 [label=<
74+
_n_A_optional_data_n__builtin_multivector_IndexType16 [label=<
7575
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
7676
<tr>
7777
<td bgcolor="#257FAD">
7878
<b><font color="#EBF8FF">IndexType16</font></b>
7979
</td>
8080
</tr>
8181
<tr>
82-
<td bgcolor="#EBF8FF" port="port__n_A_optional_data__builtin_multivector_IndexType16_value">
82+
<td bgcolor="#EBF8FF" port="port__n_A_optional_data_n__builtin_multivector_IndexType16_value">
8383
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">16</font>
8484
</td>
8585
</tr>
@@ -124,15 +124,15 @@ subgraph cluster__n_A_data_u64_index
124124
fillcolor="#C4E6F8";
125125

126126

127-
_n_A_data_u64_index__builtin_multivector_IndexType64 [label=<
127+
_n_A_data_u64_index_n__builtin_multivector_IndexType64 [label=<
128128
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
129129
<tr>
130130
<td bgcolor="#257FAD">
131131
<b><font color="#EBF8FF">IndexType64</font></b>
132132
</td>
133133
</tr>
134134
<tr>
135-
<td bgcolor="#EBF8FF" port="port__n_A_data_u64_index__builtin_multivector_IndexType64_value">
135+
<td bgcolor="#EBF8FF" port="port__n_A_data_u64_index_n__builtin_multivector_IndexType64_value">
136136
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">64</font>
137137
</td>
138138
</tr>
@@ -170,15 +170,13 @@ _n_A_data_u64_index_n_T [label=<
170170
}
171171

172172
}
173-
}
174-
175-
subgraph cluster___builtin
173+
subgraph cluster__n__builtin
176174
{
177175
penwidth=0;
178176
fontcolor="#516D7B";
179177
fillcolor="#F7F7F7";
180178
label=<<b>_builtin</b>>
181-
subgraph cluster___builtin_multivector
179+
subgraph cluster__n__builtin_multivector
182180
{
183181
penwidth=0;
184182
fontcolor="#516D7B";

flatdata-generator/tests/generators/dot_expectations/archives/namespaces.dot

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ subgraph cluster__a_A_multi
122122
fillcolor="#C4E6F8";
123123

124124

125-
_a_A_multi__builtin_multivector_IndexType32 [label=<
125+
_a_A_multi_a__builtin_multivector_IndexType32 [label=<
126126
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
127127
<tr>
128128
<td bgcolor="#257FAD">
129129
<b><font color="#EBF8FF">IndexType32</font></b>
130130
</td>
131131
</tr>
132132
<tr>
133-
<td bgcolor="#EBF8FF" port="port__a_A_multi__builtin_multivector_IndexType32_value">
133+
<td bgcolor="#EBF8FF" port="port__a_A_multi_a__builtin_multivector_IndexType32_value">
134134
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
135135
</td>
136136
</tr>
@@ -166,15 +166,13 @@ _a_A_inner [style=invisible, fixedsize="true", width="0", height="0", label=""];
166166
}
167167

168168
}
169-
}
170-
171-
subgraph cluster___builtin
169+
subgraph cluster__a__builtin
172170
{
173171
penwidth=0;
174172
fontcolor="#516D7B";
175173
fillcolor="#F7F7F7";
176174
label=<<b>_builtin</b>>
177-
subgraph cluster___builtin_multivector
175+
subgraph cluster__a__builtin_multivector
178176
{
179177
penwidth=0;
180178
fontcolor="#516D7B";

flatdata-generator/tests/generators/dot_expectations/archives/references.dot

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ subgraph cluster__n_A_multilist2
2424
fillcolor="#C4E6F8";
2525

2626

27-
_n_A_multilist2__builtin_multivector_IndexType32 [label=<
27+
_n_A_multilist2_n__builtin_multivector_IndexType32 [label=<
2828
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
2929
<tr>
3030
<td bgcolor="#257FAD">
3131
<b><font color="#EBF8FF">IndexType32</font></b>
3232
</td>
3333
</tr>
3434
<tr>
35-
<td bgcolor="#EBF8FF" port="port__n_A_multilist2__builtin_multivector_IndexType32_value">
35+
<td bgcolor="#EBF8FF" port="port__n_A_multilist2_n__builtin_multivector_IndexType32_value">
3636
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
3737
</td>
3838
</tr>
@@ -117,15 +117,15 @@ subgraph cluster__n_A_multirefs
117117
fillcolor="#C4E6F8";
118118

119119

120-
_n_A_multirefs__builtin_multivector_IndexType32 [label=<
120+
_n_A_multirefs_n__builtin_multivector_IndexType32 [label=<
121121
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
122122
<tr>
123123
<td bgcolor="#257FAD">
124124
<b><font color="#EBF8FF">IndexType32</font></b>
125125
</td>
126126
</tr>
127127
<tr>
128-
<td bgcolor="#EBF8FF" port="port__n_A_multirefs__builtin_multivector_IndexType32_value">
128+
<td bgcolor="#EBF8FF" port="port__n_A_multirefs_n__builtin_multivector_IndexType32_value">
129129
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
130130
</td>
131131
</tr>
@@ -189,15 +189,15 @@ _n_A_all_lists_n_S [label=<
189189
</tr>
190190
</table>>];
191191

192-
_n_A_all_lists__builtin_multivector_IndexType32 [label=<
192+
_n_A_all_lists_n__builtin_multivector_IndexType32 [label=<
193193
<table border="0" cellborder="0" cellspacing="1" cellpadding="1" color="#516D7B">
194194
<tr>
195195
<td bgcolor="#257FAD">
196196
<b><font color="#EBF8FF">IndexType32</font></b>
197197
</td>
198198
</tr>
199199
<tr>
200-
<td bgcolor="#EBF8FF" port="port__n_A_all_lists__builtin_multivector_IndexType32_value">
200+
<td bgcolor="#EBF8FF" port="port__n_A_all_lists_n__builtin_multivector_IndexType32_value">
201201
<b><font color="#516D7B">value</font></b>:<font color="#568C3B">u64</font>:<font color="#D22D72">32</font>
202202
</td>
203203
</tr>
@@ -221,15 +221,13 @@ _n_A_all_lists_n_S [label=<
221221
}
222222

223223
}
224-
}
225-
226-
subgraph cluster___builtin
224+
subgraph cluster__n__builtin
227225
{
228226
penwidth=0;
229227
fontcolor="#516D7B";
230228
fillcolor="#F7F7F7";
231229
label=<<b>_builtin</b>>
232-
subgraph cluster___builtin_multivector
230+
subgraph cluster__n__builtin_multivector
233231
{
234232
penwidth=0;
235233
fontcolor="#516D7B";
@@ -239,6 +237,7 @@ subgraph cluster___builtin_multivector
239237

240238
}
241239

240+
}
242241

243242

244243

@@ -258,7 +257,7 @@ subgraph cluster___builtin_multivector
258257

259258

260259

261-
_n_A_refs_n_R:port__n_A_refs_n_R_ref2 -> _n_A_multilist2__builtin_multivector_IndexType32 [lhead=cluster__n_A_multilist2];
260+
_n_A_refs_n_R:port__n_A_refs_n_R_ref2 -> _n_A_multilist2_n__builtin_multivector_IndexType32 [lhead=cluster__n_A_multilist2];
262261

263262

264263

0 commit comments

Comments
 (0)