Skip to content

Commit a8c691e

Browse files
committed
Change descriptors to use polymorphism and unique_ptr instead of variant to avoid incomplete types
1 parent 31af103 commit a8c691e

File tree

11 files changed

+417
-256
lines changed

11 files changed

+417
-256
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ if (PSAPI_BUILD_PYTHON)
2424
endif()
2525

2626

27+
2728
# Build setup
2829
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2930
set (CMAKE_CXX_STANDARD 20)

PhotoshopAPI/src/Core/Struct/DescriptorStructure.cpp

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ namespace Descriptors
199199
}
200200
else if (osTypeEnum == Impl::OSTypes::String)
201201
{
202-
return construct_descriptor<UnicodeString_Wrapper>(key, ostype);
202+
return construct_descriptor<UnicodeString_Wrapper>(document, key, ostype);
203203
}
204204
else
205205
{
@@ -271,15 +271,15 @@ namespace Descriptors
271271
{
272272
return;
273273
}
274-
m_DescriptorItems.push_back(item);
274+
m_DescriptorItems.push_back(std::move(item));
275275
}
276276

277277

278278
// ---------------------------------------------------------------------------------------------------------------------
279279
// ---------------------------------------------------------------------------------------------------------------------
280280
void KeyValueMixin::insert(std::string key, std::unique_ptr<DescriptorBase> value) noexcept
281281
{
282-
insert(std::make_pair(key, value));
282+
insert(std::make_pair(key, std::move(value)));
283283
}
284284

285285
// ---------------------------------------------------------------------------------------------------------------------
@@ -328,15 +328,15 @@ namespace Descriptors
328328
valueRef = std::move(item.second);
329329
return;
330330
}
331-
m_DescriptorItems.push_back(item);
331+
m_DescriptorItems.push_back(std::move(item));
332332
}
333333

334334

335335
// ---------------------------------------------------------------------------------------------------------------------
336336
// ---------------------------------------------------------------------------------------------------------------------
337337
void KeyValueMixin::insert_or_assign(std::string key, std::unique_ptr<DescriptorBase> value) noexcept
338338
{
339-
insert_or_assign(std::make_pair(key, value));
339+
insert_or_assign(std::make_pair(key, std::move(value)));
340340
}
341341

342342

@@ -397,6 +397,18 @@ namespace Descriptors
397397
}
398398

399399

400+
// ---------------------------------------------------------------------------------------------------------------------
401+
// ---------------------------------------------------------------------------------------------------------------------
402+
KeyValueMixin& KeyValueMixin::operator=(KeyValueMixin&& other) noexcept
403+
{
404+
405+
if (this != &other)
406+
{
407+
this->m_DescriptorItems = std::move(other.m_DescriptorItems);
408+
}
409+
return *this;
410+
}
411+
400412
// ---------------------------------------------------------------------------------------------------------------------
401413
// ---------------------------------------------------------------------------------------------------------------------
402414
Property::Property(std::string key, std::vector<char> osKey, std::string name, std::string classID, std::string keyID)
@@ -1134,10 +1146,10 @@ namespace Descriptors
11341146

11351147
// ---------------------------------------------------------------------------------------------------------------------
11361148
// ---------------------------------------------------------------------------------------------------------------------
1137-
List::List(std::string key, std::vector<char> osKey, std::vector<DescriptorVariant> items)
1149+
List::List(std::string key, std::vector<char> osKey, std::vector<std::unique_ptr<DescriptorBase>> items)
11381150
: DescriptorBase(key, osKey)
11391151
{
1140-
m_Items = items;
1152+
m_Items = std::move(items);
11411153
}
11421154

11431155

@@ -1444,7 +1456,7 @@ namespace Descriptors
14441456
// ---------------------------------------------------------------------------------------------------------------------
14451457
bool double_Wrapper::operator==(const double_Wrapper& other) const
14461458
{
1447-
return this->m_Value == other.m_Value
1459+
return this->m_Value == other.m_Value;
14481460
}
14491461

14501462

@@ -1458,22 +1470,34 @@ namespace Descriptors
14581470
};
14591471
}
14601472

1473+
1474+
// ---------------------------------------------------------------------------------------------------------------------
1475+
// ---------------------------------------------------------------------------------------------------------------------
1476+
double_Wrapper::double_Wrapper(double value)
1477+
{
1478+
m_Value = value; DescriptorBase::m_OSKey = Impl::descriptorKeys.at(Impl::OSTypes::Double);
1479+
}
14611480

1481+
14621482
// ---------------------------------------------------------------------------------------------------------------------
14631483
// ---------------------------------------------------------------------------------------------------------------------
14641484
void int32_t_Wrapper::read(File& document)
14651485
{
14661486
m_Value = ReadBinaryData<int32_t>(document);
14671487
}
14681488

1489+
// ---------------------------------------------------------------------------------------------------------------------
1490+
// ---------------------------------------------------------------------------------------------------------------------
14691491
void int32_t_Wrapper::write(File& document) const
14701492
{
14711493
WriteBinaryData<int32_t>(document, m_Value);
14721494
}
14731495

1496+
// ---------------------------------------------------------------------------------------------------------------------
1497+
// ---------------------------------------------------------------------------------------------------------------------
14741498
bool int32_t_Wrapper::operator==(const int32_t_Wrapper& other) const
14751499
{
1476-
return this->m_Value == other.m_Value
1500+
return this->m_Value == other.m_Value;
14771501
}
14781502

14791503
json_ordered int32_t_Wrapper::to_json() const
@@ -1484,6 +1508,11 @@ namespace Descriptors
14841508
};
14851509
}
14861510

1511+
int32_t_Wrapper::int32_t_Wrapper(int32_t value)
1512+
{
1513+
m_Value = value; DescriptorBase::m_OSKey = Impl::descriptorKeys.at(Impl::OSTypes::Integer);
1514+
}
1515+
14871516
void int64_t_Wrapper::read(File& document)
14881517
{
14891518
m_Value = ReadBinaryData<int64_t>(document);
@@ -1496,17 +1525,22 @@ namespace Descriptors
14961525

14971526
bool int64_t_Wrapper::operator==(const int64_t_Wrapper& other) const
14981527
{
1499-
return this->m_Value == other.m_Value
1528+
return this->m_Value == other.m_Value;
15001529
}
15011530

15021531
json_ordered int64_t_Wrapper::to_json() const
15031532
{
15041533
return {
15051534
{"implementation", { {"_data_type", "int64_t"} }},
1506-
{ "value", value }
1535+
{ "value", m_Value }
15071536
};
15081537
}
15091538

1539+
int64_t_Wrapper::int64_t_Wrapper(int64_t value)
1540+
{
1541+
m_Value = value; DescriptorBase::m_OSKey = Impl::descriptorKeys.at(Impl::OSTypes::LargeInteger);
1542+
}
1543+
15101544
void bool_Wrapper::read(File& document)
15111545
{
15121546
m_Value = ReadBinaryData<bool>(document);
@@ -1519,18 +1553,23 @@ namespace Descriptors
15191553

15201554
bool bool_Wrapper::operator==(const bool_Wrapper& other) const
15211555
{
1522-
return this->m_Value == other.m_Value
1556+
return this->m_Value == other.m_Value;
15231557
}
15241558

15251559
json_ordered bool_Wrapper::to_json() const
15261560
{
15271561
return
15281562
{
15291563
{"implementation", { {"_data_type", "bool"} }},
1530-
{ "value", value }
1564+
{ "value", m_Value }
15311565
};
15321566
}
15331567

1568+
bool_Wrapper::bool_Wrapper(bool value)
1569+
{
1570+
m_Value = value; DescriptorBase::m_OSKey = Impl::descriptorKeys.at(Impl::OSTypes::Boolean);
1571+
}
1572+
15341573
void UnicodeString_Wrapper::read(File& document)
15351574
{
15361575
m_Value.read(document, 1u);
@@ -1543,18 +1582,23 @@ namespace Descriptors
15431582

15441583
bool UnicodeString_Wrapper::operator==(const UnicodeString_Wrapper& other) const
15451584
{
1546-
return this->m_Value == other.m_Value
1585+
return this->m_Value == other.m_Value;
15471586
}
15481587

15491588
json_ordered UnicodeString_Wrapper::to_json() const
15501589
{
15511590
return
15521591
{
15531592
{"implementation", { {"_data_type", "UnicodeString"} }},
1554-
{ "value", value.getString()}
1593+
{ "value", m_Value.getString()}
15551594
};
15561595
}
15571596

1597+
UnicodeString_Wrapper::UnicodeString_Wrapper(UnicodeString value)
1598+
{
1599+
m_Value = value; DescriptorBase::m_OSKey = Impl::descriptorKeys.at(Impl::OSTypes::String);
1600+
}
1601+
15581602
}
15591603

15601604
PSAPI_NAMESPACE_END

0 commit comments

Comments
 (0)