Skip to content

Commit 88dbc6d

Browse files
committed
More work on complex object support
1 parent 05aea44 commit 88dbc6d

File tree

81 files changed

+860
-576
lines changed

Some content is hidden

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

81 files changed

+860
-576
lines changed

Src/FastData.Generator.CPlusPlus.Tests/FastData.Generator.CPlusPlus.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99
<ProjectReference Include="..\FastData.InternalShared\FastData.InternalShared.csproj" />
1010
</ItemGroup>
1111

12+
<ItemGroup>
13+
<Folder Include="Features\" />
14+
</ItemGroup>
15+
1216
</Project>

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

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,31 @@
22
using Genbox.FastData.Generator.CPlusPlus.Internal.Framework;
33
using Genbox.FastData.Generator.Extensions;
44
using Genbox.FastData.Generator.Framework;
5+
using Genbox.FastData.InternalShared;
6+
using Genbox.FastData.InternalShared.TestClasses;
7+
using Genbox.FastData.InternalShared.TestClasses.TheoryData;
58
using static Genbox.FastData.Generator.Helpers.FormatHelper;
69
using static Genbox.FastData.InternalShared.Helpers.TestHelper;
710

811
namespace Genbox.FastData.Generator.CPlusPlus.Tests;
912

1013
public class FeatureTests(CPlusPlusContext context) : IClassFixture<CPlusPlusContext>
1114
{
12-
[Fact]
13-
public async Task StructSupportTest()
15+
[Theory]
16+
[ClassData(typeof(SimpleTestVectorTheoryData))]
17+
public async Task ObjectSupportTest<T>(TestVector<T> vector)
1418
{
15-
int[] values = [1, 2, 3];
16-
const string id = nameof(StructSupportTest);
17-
18-
string genSource = FastDataGenerator.GenerateKeyed(values, [
19+
Person[] values =
20+
[
1921
new Person { Age = 1, Name = "Bob", Other = new Person { Name = "Anna", Age = 4 } },
2022
new Person { Age = 2, Name = "Billy" },
2123
new Person { Age = 3, Name = "Bibi" },
22-
], new FastDataConfig { StructureType = StructureType.Array }, CPlusPlusCodeGenerator.Create(new CPlusPlusCodeGeneratorConfig(id)));
24+
];
25+
26+
GeneratorSpec spec = Generate(id => CPlusPlusCodeGenerator.Create(new CPlusPlusCodeGeneratorConfig(id)), vector, values);
2327

24-
await Verify(genSource)
25-
.UseFileName(id)
28+
await Verify(spec.Source)
29+
.UseFileName(spec.Identifier)
2630
.UseDirectory("Features")
2731
.DisableDiff();
2832

@@ -33,20 +37,21 @@ await Verify(genSource)
3337
#include <string>
3438
#include <iostream>
3539
36-
{{genSource}}
40+
{{spec.Source}}
3741
38-
int main(int argc, char* argv[])
42+
int main()
3943
{
40-
{{FormatList(values, x => $"""
41-
if (!{id}::contains({map.ToValueLabel(x)}))
42-
return false;
43-
""", "\n")}}
44+
const Person* res;
45+
{{FormatList(vector.Keys, x => $"""
46+
if (!{spec.Identifier}::try_lookup({map.ToValueLabel(x)}, res))
47+
return 0;
48+
""", "\n")}}
4449
4550
return 1;
4651
}
4752
""";
4853

49-
string executable = context.Compiler.Compile(id, testSource);
54+
string executable = context.Compiler.Compile(spec.Identifier, testSource);
5055
Assert.Equal(1, RunProcess(executable));
5156
}
5257

Src/FastData.Generator.CPlusPlus.Tests/Features/StructSupportTest.verified.txt renamed to Src/FastData.Generator.CPlusPlus.Tests/Features/ArrayStructure_Int32_3.verified.txt

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1-
// This file is auto-generated. Do not edit manually.
1+

2+
struct Person {
3+
const int32_t Age;
4+
const std::u32string_view Name;
5+
const Person* Other;
6+
7+
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
8+
};
9+
10+
// This file is auto-generated. Do not edit manually.
211
// Structure: Array
312
#pragma once
413
#include <array>
514
#include <cstdint>
615
#include <limits>
716
#include <string_view>
817

9-
class StructSupportTest final
18+
class ArrayStructure_Int32_3 final
1019
{
1120
static constexpr std::array<int32_t, 3> keys = {
1221
1, 2, 3
@@ -26,18 +35,10 @@ public:
2635
}
2736
return false;
2837
}
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;
38+
static std::array<Person*, 3> values;
3839

3940
[[nodiscard]]
40-
static bool try_lookup(const int32_t key, Person*& value) noexcept
41+
static bool try_lookup(const int32_t key, const Person*& value) noexcept
4142
{
4243
if (key < 1 || key > 3)
4344
return false;
@@ -50,6 +51,8 @@ struct Person {
5051
return true;
5152
}
5253
}
54+
55+
value = nullptr;
5356
return false;
5457
}
5558

@@ -58,13 +61,13 @@ struct Person {
5861
static constexpr int32_t max_key = 3;
5962

6063
public:
61-
StructSupportTest() = delete;
62-
StructSupportTest(const StructSupportTest&) = delete;
63-
StructSupportTest& operator=(const StructSupportTest&) = delete;
64-
StructSupportTest(StructSupportTest&&) = delete;
65-
StructSupportTest& operator=(StructSupportTest&&) = delete;
64+
ArrayStructure_Int32_3() = delete;
65+
ArrayStructure_Int32_3(const ArrayStructure_Int32_3&) = delete;
66+
ArrayStructure_Int32_3& operator=(const ArrayStructure_Int32_3&) = delete;
67+
ArrayStructure_Int32_3(ArrayStructure_Int32_3&&) = delete;
68+
ArrayStructure_Int32_3& operator=(ArrayStructure_Int32_3&&) = delete;
6669
};
67-
std::array<StructSupportTest::Person*, 3> StructSupportTest::values = {
70+
std::array<Person*, 3> ArrayStructure_Int32_3::values = {
6871
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
6972
new Person(2, U"Billy", nullptr),
7073
new Person(3, U"Bibi", nullptr),
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+

2+
struct Person {
3+
const int32_t Age;
4+
const std::u32string_view Name;
5+
const Person* Other;
6+
7+
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
8+
};
9+
10+
// This file is auto-generated. Do not edit manually.
11+
// Structure: BinarySearch
12+
#pragma once
13+
#include <array>
14+
#include <cstdint>
15+
#include <limits>
16+
#include <string_view>
17+
18+
class BinarySearchStructure_Int32_3 final
19+
{
20+
static constexpr std::array<int32_t, 3> keys = {
21+
1, 2, 3
22+
};
23+
24+
public:
25+
[[nodiscard]]
26+
static bool contains(const int32_t key) noexcept
27+
{
28+
if (key < 1 || key > 3)
29+
return false;
30+
31+
size_t lo = 0;
32+
size_t hi = 2;
33+
while (lo <= hi)
34+
{
35+
const size_t mid = lo + ((hi - lo) >> 1);
36+
37+
if (keys[mid] == key)
38+
return true;
39+
40+
if (keys[mid] < key)
41+
lo = mid + 1;
42+
else
43+
hi = mid - 1;
44+
}
45+
46+
return false;
47+
}
48+
static std::array<Person*, 3> values;
49+
50+
[[nodiscard]]
51+
static bool try_lookup(const int32_t key, const Person*& value) noexcept
52+
{
53+
if (key < 1 || key > 3)
54+
return false;
55+
56+
size_t lo = 0;
57+
size_t hi = 2;
58+
while (lo <= hi)
59+
{
60+
const size_t mid = lo + ((hi - lo) >> 1);
61+
62+
if (keys[mid] == key)
63+
{
64+
value = values[mid];
65+
return true;
66+
}
67+
68+
if (keys[mid] < key)
69+
lo = mid + 1;
70+
else
71+
hi = mid - 1;
72+
}
73+
74+
value = nullptr;
75+
return false;
76+
}
77+
78+
static constexpr size_t item_count = 3;
79+
static constexpr int32_t min_key = 1;
80+
static constexpr int32_t max_key = 3;
81+
82+
public:
83+
BinarySearchStructure_Int32_3() = delete;
84+
BinarySearchStructure_Int32_3(const BinarySearchStructure_Int32_3&) = delete;
85+
BinarySearchStructure_Int32_3& operator=(const BinarySearchStructure_Int32_3&) = delete;
86+
BinarySearchStructure_Int32_3(BinarySearchStructure_Int32_3&&) = delete;
87+
BinarySearchStructure_Int32_3& operator=(BinarySearchStructure_Int32_3&&) = delete;
88+
};
89+
std::array<Person*, 3> BinarySearchStructure_Int32_3::values = {
90+
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
91+
new Person(2, U"Billy", nullptr),
92+
new Person(3, U"Bibi", nullptr),
93+
94+
};
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+

2+
struct Person {
3+
const int32_t Age;
4+
const std::u32string_view Name;
5+
const Person* Other;
6+
7+
Person(const int32_t age, const std::u32string_view name, const Person* other) : Age(age), Name(name), Other(other) { }
8+
};
9+
10+
// This file is auto-generated. Do not edit manually.
11+
// Structure: Conditional
12+
#pragma once
13+
#include <array>
14+
#include <cstdint>
15+
#include <limits>
16+
#include <string_view>
17+
18+
class ConditionalStructure_Int32_3 final
19+
{
20+
public:
21+
[[nodiscard]]
22+
static bool contains(const int32_t key) noexcept
23+
{
24+
25+
26+
if (key == 1 || key == 2 || key == 3)
27+
return true;
28+
29+
return false;
30+
}
31+
static std::array<Person*, 3> values;
32+
33+
[[nodiscard]]
34+
static bool try_lookup(const int32_t key, const Person*& value) noexcept
35+
{
36+
37+
38+
if (key == 1)
39+
{
40+
value = values[0];
41+
return true;
42+
}
43+
if (key == 2)
44+
{
45+
value = values[1];
46+
return true;
47+
}
48+
if (key == 3)
49+
{
50+
value = values[2];
51+
return true;
52+
}
53+
54+
55+
value = nullptr;
56+
return false;
57+
}
58+
59+
static constexpr size_t item_count = 3;
60+
static constexpr int32_t min_key = 1;
61+
static constexpr int32_t max_key = 3;
62+
63+
public:
64+
ConditionalStructure_Int32_3() = delete;
65+
ConditionalStructure_Int32_3(const ConditionalStructure_Int32_3&) = delete;
66+
ConditionalStructure_Int32_3& operator=(const ConditionalStructure_Int32_3&) = delete;
67+
ConditionalStructure_Int32_3(ConditionalStructure_Int32_3&&) = delete;
68+
ConditionalStructure_Int32_3& operator=(ConditionalStructure_Int32_3&&) = delete;
69+
};
70+
std::array<Person*, 3> ConditionalStructure_Int32_3::values = {
71+
new Person(1, U"Bob", new Person(4, U"Anna", nullptr)),
72+
new Person(2, U"Billy", nullptr),
73+
new Person(3, U"Bibi", nullptr),
74+
75+
};

0 commit comments

Comments
 (0)