Skip to content

Commit b3cc1b7

Browse files
Merge pull request #23
Clear containers before populating them with values
2 parents 8a668e8 + 60fe44a commit b3cc1b7

File tree

7 files changed

+42
-6
lines changed

7 files changed

+42
-6
lines changed

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.18)
2-
project(figcone VERSION 3.1.0)
2+
project(figcone VERSION 3.2.0)
33
include(external/seal_lake)
44

55
SealLake_IsInstallEnabled(INSTALL_FIGCONE_TREE)
@@ -101,7 +101,7 @@ if (FIGCONE_USE_ALL OR FIGCONE_USE_JSON OR FIGCONE_USE_YAML OR FIGCONE_USE_TOML
101101
figcone::figcone_formats
102102
)
103103
SealLake_AddDependencies(
104-
figcone_formats 1.1.0
104+
figcone_formats 1.2.0
105105
)
106106
endif ()
107107

formats/CMakeLists.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project(figcone_formats VERSION 1.1.0)
1+
project(figcone_formats VERSION 1.2.0)
22

33
option(FIGCONE_USE_ALL "Enable all supported config formats" ON)
44
option(FIGCONE_USE_JSON "Enable JSON config format" OFF)
@@ -64,9 +64,9 @@ endif()
6464

6565
if(FIGCONE_USE_ALL OR FIGCONE_USE_XML)
6666
SealLake_Import(
67-
figcone_xml 1.1.0
67+
figcone_xml 1.2.0
6868
GIT_REPOSITORY https://github.com/kamchatka-volcano/figcone_xml.git
69-
GIT_TAG v1.1.0
69+
GIT_TAG v1.2.0
7070
)
7171
SealLake_Copy(
7272
WILDCARDS ${figcone_xml_SOURCE_DIR}/include/figcone_xml/*

include/figcone/detail/dict.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ class Dict : public INode {
3838
{
3939
hasValue_ = true;
4040
position_ = node.position();
41+
dictMap_ = TMap{};
4142
if (!node.isItem())
4243
throw ConfigError{"Dictionary '" + name_ + "': config node can't be a list.", node.position()};
4344
if constexpr (sfun::is_optional_v<TMap>)
4445
dictMap_.emplace();
45-
maybeOptValue(dictMap_).clear();
4646

4747
for (const auto& paramName : node.asItem().paramNames()) {
4848
const auto& paramValue = node.asItem().param(paramName);

include/figcone/detail/nodelist.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class NodeList : public detail::INode {
4242
{
4343
hasValue_ = true;
4444
position_ = nodeList.position();
45+
nodeList_ = TCfgList{};
4546
if (!nodeList.isList())
4647
throw ConfigError{"Node list '" + name_ + "': config node must be a list.", nodeList.position()};
4748
if constexpr (sfun::is_optional<TCfgList>::value)

include/figcone/detail/paramlist.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class ParamList : public IParam {
3838
{
3939
position_ = paramList.position();
4040
hasValue_ = true;
41+
paramListValue_ = TParamList{};
4142
if constexpr (sfun::is_optional_v<TParamList>)
4243
paramListValue_.emplace();
4344

tests/test_paramlist.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,21 @@ TEST(TestParamList, DefaultValue)
406406
EXPECT_EQ(cfg.testIntList.at(2), 3);
407407
}
408408

409+
TEST(TestParamList, OverwriteDefaultValue)
410+
{
411+
///testStrList = []
412+
///
413+
auto tree = figcone::makeTreeRoot();
414+
tree->asItem().addParamList("testStrList", std::vector<std::string>{}, {1, 1});
415+
tree->asItem().addParamList("testIntList", std::vector<std::string>{"42", "43"}, {1, 1});
416+
auto parser = TreeProvider{std::move(tree)};
417+
auto cfgReader = figcone::ConfigReader{figcone::NameFormat::CamelCase};
418+
auto cfg = cfgReader.read<CfgStr>("", parser);
419+
420+
ASSERT_EQ(cfg.testStrList.size(), 0);
421+
ASSERT_EQ(cfg.testIntList.size(), 2);
422+
EXPECT_EQ(cfg.testIntList.at(0), 42);
423+
EXPECT_EQ(cfg.testIntList.at(1), 43);
424+
}
425+
409426
} //namespace test_paramlist

tests_static_refl/test_paramlist_cpp20.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,21 @@ TEST(StaticReflTestParamList, DefaultValue)
266266
EXPECT_EQ(cfg.testIntList.at(2), 3);
267267
}
268268

269+
TEST(TestParamList, OverwriteDefaultValue)
270+
{
271+
///testStrList = []
272+
///
273+
auto tree = figcone::makeTreeRoot();
274+
tree->asItem().addParamList("testStrList", std::vector<std::string>{}, {1, 1});
275+
tree->asItem().addParamList("testIntList", std::vector<std::string>{"42", "43"}, {1, 1});
276+
auto parser = TreeProvider{std::move(tree)};
277+
auto cfgReader = figcone::ConfigReader{figcone::NameFormat::CamelCase};
278+
auto cfg = cfgReader.read<CfgStr>("", parser);
279+
280+
ASSERT_EQ(cfg.testStrList.size(), 0);
281+
ASSERT_EQ(cfg.testIntList.size(), 2);
282+
EXPECT_EQ(cfg.testIntList.at(0), 42);
283+
EXPECT_EQ(cfg.testIntList.at(1), 43);
284+
}
285+
269286
} //namespace test_paramlist

0 commit comments

Comments
 (0)