Skip to content

Commit 3dc6454

Browse files
committed
Add support for complex object trees
1 parent db9ae72 commit 3dc6454

File tree

379 files changed

+1199
-1144
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

379 files changed

+1199
-1144
lines changed

Src/FastData.Generator.CPlusPlus.Tests/FeatureTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ public async Task StructSupportTest()
1616
const string id = nameof(StructSupportTest);
1717

1818
string genSource = FastDataGenerator.GenerateKeyed(values, [
19-
new X { Age = 1, Name = "Bob" },
20-
new X { Age = 2, Name = "Billy" },
21-
new X { Age = 3, Name = "Bibi" },
19+
new Person { Age = 1, Name = "Bob", Other = new Person { Name = "Anna", Age = 4 } },
20+
new Person { Age = 2, Name = "Billy" },
21+
new Person { Age = 3, Name = "Bibi" },
2222
], new FastDataConfig { StructureType = StructureType.Array }, CPlusPlusCodeGenerator.Create(new CPlusPlusCodeGeneratorConfig(id)));
2323

2424
await Verify(genSource)
@@ -50,9 +50,10 @@ int main(int argc, char* argv[])
5050
Assert.Equal(1, RunProcess(executable));
5151
}
5252

53-
internal struct X
53+
internal class Person
5454
{
5555
public int Age { get; set; }
5656
public string Name { get; set; }
57+
public Person Other { get; set; }
5758
}
5859
}

Src/FastData.Generator.CPlusPlus.Tests/Features/StructSupportTest.verified.txt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,54 @@
88

99
class StructSupportTest final
1010
{
11-
struct X {
12-
const int32_t Age;
13-
const std::u32string_view Name;
14-
15-
X(int32_t age, std::u32string_view name) : Age(age), Name(name) { }
16-
};
17-
static std::array<X, 3> values;
18-
19-
static constexpr std::array<int32_t, 3> keys = {
11+
static constexpr std::array<int32_t, 3> keys = {
2012
1, 2, 3
21-
};
13+
};
2214

2315
public:
2416
[[nodiscard]]
25-
static bool try_lookup(const int32_t key, X*& value) noexcept
17+
static bool contains(const int32_t key) noexcept
2618
{
2719
if (key < 1 || key > 3)
2820
return false;
2921

3022
for (size_t i = 0; i < 3; i++)
3123
{
3224
if (keys[i] == key)
33-
{
34-
value = &values[i];
35-
return true;
36-
}
25+
return true;
3726
}
3827
return false;
3928
}
29+
struct Person {
30+
const int32_t Age;
31+
const std::u32string_view Name;
32+
const Person* Other;
33+
34+
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
35+
};
36+
37+
static std::array<StructSupportTest::Person*, 3> values;
4038

4139
[[nodiscard]]
42-
static bool contains(const int32_t key) noexcept
40+
static bool try_lookup(const int32_t key, Person*& value) noexcept
4341
{
4442
if (key < 1 || key > 3)
4543
return false;
4644

4745
for (size_t i = 0; i < 3; i++)
4846
{
4947
if (keys[i] == key)
50-
return true;
48+
{
49+
value = values[i];
50+
return true;
51+
}
5152
}
5253
return false;
5354
}
5455

5556
static constexpr size_t item_count = 3;
56-
static constexpr int32_t min_value = 1;
57-
static constexpr int32_t max_value = 3;
57+
static constexpr int32_t min_key = 1;
58+
static constexpr int32_t max_key = 3;
5859

5960
public:
6061
StructSupportTest() = delete;
@@ -63,6 +64,9 @@ public:
6364
StructSupportTest(StructSupportTest&&) = delete;
6465
StructSupportTest& operator=(StructSupportTest&&) = delete;
6566
};
66-
std::array<StructSupportTest::X, 3> StructSupportTest::values = {
67-
X(1, U"Bob"), X(2, U"Billy"), X(3, U"Bibi")
67+
std::array<StructSupportTest::Person*, 3> StructSupportTest::values = {
68+
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
69+
new Person(2, U"Billy", nullptr),
70+
new Person(3, U"Bibi", nullptr),
71+
6872
};

Src/FastData.Generator.CPlusPlus.Tests/Vectors/ArrayStructure_Byte_3.verified.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,46 @@
88

99
class ArrayStructure_Byte_3 final
1010
{
11-
12-
static std::array<uint8_t, 3> values;
13-
14-
static constexpr std::array<uint8_t, 3> keys = {
11+
static constexpr std::array<uint8_t, 3> keys = {
1512
0, 1, std::numeric_limits<uint8_t>::max()
16-
};
13+
};
1714

1815
public:
1916
[[nodiscard]]
20-
static bool try_lookup(const uint8_t key, uint8_t*& value) noexcept
17+
static bool contains(const uint8_t key) noexcept
2118
{
2219
if (key < 0 || key > std::numeric_limits<uint8_t>::max())
2320
return false;
2421

2522
for (size_t i = 0; i < 3; i++)
2623
{
2724
if (keys[i] == key)
28-
{
29-
value = &values[i];
30-
return true;
31-
}
25+
return true;
3226
}
3327
return false;
3428
}
29+
static std::array<uint8_t, 3> values;
3530

3631
[[nodiscard]]
37-
static bool contains(const uint8_t key) noexcept
32+
static bool try_lookup(const uint8_t key, uint8_t value) noexcept
3833
{
3934
if (key < 0 || key > std::numeric_limits<uint8_t>::max())
4035
return false;
4136

4237
for (size_t i = 0; i < 3; i++)
4338
{
4439
if (keys[i] == key)
45-
return true;
40+
{
41+
value = values[i];
42+
return true;
43+
}
4644
}
4745
return false;
4846
}
4947

5048
static constexpr size_t item_count = 3;
51-
static constexpr uint8_t min_value = 0;
52-
static constexpr uint8_t max_value = std::numeric_limits<uint8_t>::max();
49+
static constexpr uint8_t min_key = 0;
50+
static constexpr uint8_t max_key = std::numeric_limits<uint8_t>::max();
5351

5452
public:
5553
ArrayStructure_Byte_3() = delete;

Src/FastData.Generator.CPlusPlus.Tests/Vectors/ArrayStructure_Char_3.verified.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,46 @@
88

99
class ArrayStructure_Char_3 final
1010
{
11-
12-
static std::array<uint8_t, 3> values;
13-
14-
static constexpr std::array<char, 3> keys = {
11+
static constexpr std::array<char, 3> keys = {
1512
0, 97, 127
16-
};
13+
};
1714

1815
public:
1916
[[nodiscard]]
20-
static bool try_lookup(const char key, uint8_t*& value) noexcept
17+
static bool contains(const char key) noexcept
2118
{
2219
if (key < 0 || key > 127)
2320
return false;
2421

2522
for (size_t i = 0; i < 3; i++)
2623
{
2724
if (keys[i] == key)
28-
{
29-
value = &values[i];
30-
return true;
31-
}
25+
return true;
3226
}
3327
return false;
3428
}
29+
static std::array<uint8_t, 3> values;
3530

3631
[[nodiscard]]
37-
static bool contains(const char key) noexcept
32+
static bool try_lookup(const char key, uint8_t value) noexcept
3833
{
3934
if (key < 0 || key > 127)
4035
return false;
4136

4237
for (size_t i = 0; i < 3; i++)
4338
{
4439
if (keys[i] == key)
45-
return true;
40+
{
41+
value = values[i];
42+
return true;
43+
}
4644
}
4745
return false;
4846
}
4947

5048
static constexpr size_t item_count = 3;
51-
static constexpr char min_value = 0;
52-
static constexpr char max_value = 127;
49+
static constexpr char min_key = 0;
50+
static constexpr char max_key = 127;
5351

5452
public:
5553
ArrayStructure_Char_3() = delete;

Src/FastData.Generator.CPlusPlus.Tests/Vectors/ArrayStructure_Double_4.verified.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,46 @@
88

99
class ArrayStructure_Double_4 final
1010
{
11-
12-
static std::array<uint8_t, 4> values;
13-
14-
static constexpr std::array<double, 4> keys = {
11+
static constexpr std::array<double, 4> keys = {
1512
std::numeric_limits<double>::lowest(), 0.0, 1.0, std::numeric_limits<double>::max()
16-
};
13+
};
1714

1815
public:
1916
[[nodiscard]]
20-
static bool try_lookup(const double key, uint8_t*& value) noexcept
17+
static bool contains(const double key) noexcept
2118
{
2219
if (key < std::numeric_limits<double>::lowest() || key > std::numeric_limits<double>::max())
2320
return false;
2421

2522
for (size_t i = 0; i < 4; i++)
2623
{
2724
if (keys[i] == key)
28-
{
29-
value = &values[i];
30-
return true;
31-
}
25+
return true;
3226
}
3327
return false;
3428
}
29+
static std::array<uint8_t, 4> values;
3530

3631
[[nodiscard]]
37-
static bool contains(const double key) noexcept
32+
static bool try_lookup(const double key, uint8_t value) noexcept
3833
{
3934
if (key < std::numeric_limits<double>::lowest() || key > std::numeric_limits<double>::max())
4035
return false;
4136

4237
for (size_t i = 0; i < 4; i++)
4338
{
4439
if (keys[i] == key)
45-
return true;
40+
{
41+
value = values[i];
42+
return true;
43+
}
4644
}
4745
return false;
4846
}
4947

5048
static constexpr size_t item_count = 4;
51-
static constexpr double min_value = std::numeric_limits<double>::lowest();
52-
static constexpr double max_value = std::numeric_limits<double>::max();
49+
static constexpr double min_key = std::numeric_limits<double>::lowest();
50+
static constexpr double max_key = std::numeric_limits<double>::max();
5351

5452
public:
5553
ArrayStructure_Double_4() = delete;

Src/FastData.Generator.CPlusPlus.Tests/Vectors/ArrayStructure_Int16_5.verified.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,46 @@
88

99
class ArrayStructure_Int16_5 final
1010
{
11-
12-
static std::array<uint8_t, 5> values;
13-
14-
static constexpr std::array<int16_t, 5> keys = {
11+
static constexpr std::array<int16_t, 5> keys = {
1512
std::numeric_limits<int16_t>::lowest(), -1, 0, 1, std::numeric_limits<int16_t>::max()
16-
};
13+
};
1714

1815
public:
1916
[[nodiscard]]
20-
static bool try_lookup(const int16_t key, uint8_t*& value) noexcept
17+
static bool contains(const int16_t key) noexcept
2118
{
2219
if (key < std::numeric_limits<int16_t>::lowest() || key > std::numeric_limits<int16_t>::max())
2320
return false;
2421

2522
for (size_t i = 0; i < 5; i++)
2623
{
2724
if (keys[i] == key)
28-
{
29-
value = &values[i];
30-
return true;
31-
}
25+
return true;
3226
}
3327
return false;
3428
}
29+
static std::array<uint8_t, 5> values;
3530

3631
[[nodiscard]]
37-
static bool contains(const int16_t key) noexcept
32+
static bool try_lookup(const int16_t key, uint8_t value) noexcept
3833
{
3934
if (key < std::numeric_limits<int16_t>::lowest() || key > std::numeric_limits<int16_t>::max())
4035
return false;
4136

4237
for (size_t i = 0; i < 5; i++)
4338
{
4439
if (keys[i] == key)
45-
return true;
40+
{
41+
value = values[i];
42+
return true;
43+
}
4644
}
4745
return false;
4846
}
4947

5048
static constexpr size_t item_count = 5;
51-
static constexpr int16_t min_value = std::numeric_limits<int16_t>::lowest();
52-
static constexpr int16_t max_value = std::numeric_limits<int16_t>::max();
49+
static constexpr int16_t min_key = std::numeric_limits<int16_t>::lowest();
50+
static constexpr int16_t max_key = std::numeric_limits<int16_t>::max();
5351

5452
public:
5553
ArrayStructure_Int16_5() = delete;

0 commit comments

Comments
 (0)