Skip to content

Commit e9222b8

Browse files
authored
Merge pull request #7 from LBNL-ETA/DirectoryRestructure
Directory restructure
2 parents 523f6b3 + 6590df8 commit e9222b8

37 files changed

+182
-205
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ endif()
3232

3333
include(CMakeLists-xmlParser.txt)
3434

35-
add_subdirectory(src)
35+
add_subdirectory(include/fileParse)
3636

3737
target_include_directories(${LIB_NAME}
3838
PUBLIC
3939
$<INSTALL_INTERFACE:include>
4040
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
4141
PRIVATE
42-
${CMAKE_CURRENT_SOURCE_DIR}/src
42+
${CMAKE_CURRENT_SOURCE_DIR}/include
4343
)
4444

4545
Option(BUILD_FileParse_tests "Build FileParse tests." ON)

src/FP_Array.hxx renamed to include/fileParse/Array.hxx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <functional>
1111
#include <stdexcept>
1212

13-
#include "FP_Common.hxx"
13+
#include "Common.hxx"
1414

1515
namespace FileParse
1616
{
@@ -52,13 +52,14 @@ namespace FileParse
5252

5353
if(auto currentNode{findParentOfLastTag(node, arr.nodeNames)}; currentNode.has_value())
5454
{
55-
auto minimum{
56-
std::min(arr.data.size(), static_cast<size_t>(currentNode.value().nChildNode()))};
55+
const auto childNodes{currentNode.value().getChildNodesByName(arr.nodeNames.back())};
56+
57+
// std::array is fixed and cannot be resized, so we need to limit the number of elements
58+
auto minimum{std::min(arr.data.size(), childNodes.size())};
5759
for(int i = 0; i < minimum; ++i)
5860
{
59-
NodeAdapter activeNode = currentNode.value().getChildNode(arr.nodeNames.back(), i);
6061
T item;
61-
activeNode >> item;
62+
childNodes[i] >> item;
6263
arr.data[i] = item;
6364
}
6465
}

src/FP_Base.hxx renamed to include/fileParse/Base.hxx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <unordered_map>
1111
#include <array>
1212

13-
#include "FP_Formatter.hxx"
13+
#include "Formatter.hxx"
1414

1515
namespace FileParse
1616
{
@@ -151,15 +151,16 @@ namespace FileParse
151151
std::optional<NodeAdapter> findParentOfLastTag(NodeAdapter node,
152152
const std::vector<std::string> & nodeNames)
153153
{
154-
NodeAdapter currentNode = node;
154+
std::optional<NodeAdapter> currentNode = node;
155155

156156
for(size_t i = 0; i < nodeNames.size() - 1; ++i)
157157
{
158-
currentNode = currentNode.getChildNode(nodeNames[i], 0);
159-
if(currentNode.isEmpty())
158+
if(!currentNode)
160159
{
161160
return std::nullopt;
162161
}
162+
163+
currentNode = currentNode->getFirstChildByName(nodeNames[i]);
163164
}
164165

165166
return currentNode;
@@ -348,9 +349,9 @@ namespace FileParse
348349
inline std::enable_if_t<is_valid_map<MapType>::value, const NodeAdapter &>
349350
operator>>(const NodeAdapter & node, MapType & map)
350351
{
351-
for(int i = 0; i < node.nChildNode(); ++i)
352+
const auto & childNodes{node.getChildNodes()};
353+
for(const auto & childNode : childNodes)
352354
{
353-
auto childNode = node.getChildNode(i);
354355
std::string key = childNode.getCurrentTag();
355356

356357
typename MapType::mapped_type val;

src/CMakeLists.txt renamed to include/fileParse/CMakeLists.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
set( CMAKE_INCLUDE_CURRENT_DIR_IN_INTERFACE ON )
22

33
add_library( ${LIB_NAME}
4-
FP_Base.hxx
5-
FP_Formatter.hxx
6-
FP_Formatter.cxx
7-
FP_Common.hxx
8-
FP_Enum.hxx
9-
FP_Map.hxx
10-
FP_Optional.hxx
11-
FP_Set.hxx
12-
FP_StringConversion.hxx
13-
FP_Variant.hxx
14-
FP_Vector.hxx
15-
FP_XMLNodeAdapter.cxx
16-
FP_XMLNodeAdapter.hxx)
4+
Base.hxx
5+
Formatter.hxx
6+
Formatter.cxx
7+
Common.hxx
8+
Enum.hxx
9+
Map.hxx
10+
Optional.hxx
11+
Set.hxx
12+
StringConversion.hxx
13+
Variant.hxx
14+
Vector.hxx
15+
XMLNodeAdapter.cxx
16+
XMLNodeAdapter.hxx)
1717

1818
if(NOT "${fPIC}")
1919
set(fPIC ON)

src/FP_Common.hxx renamed to include/fileParse/Common.hxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <string>
88
#include <vector>
99

10-
#include "FP_Base.hxx"
10+
#include "Base.hxx"
1111

1212
namespace FileParse
1313
{
@@ -81,10 +81,10 @@ namespace FileParse
8181
{
8282
for(const auto & nodeName : child.nodeNames)
8383
{
84-
auto childNode = node.getChildNode(nodeName, 0);
85-
if(!childNode.isEmpty())
84+
auto childNode{node.getFirstChildByName(nodeName)};
85+
if(childNode.has_value())
8686
{
87-
childNode >> child.data;
87+
childNode.value() >> child.data;
8888
}
8989
}
9090
return node;
File renamed without changes.

src/FP_Formatter.cxx renamed to include/fileParse/Formatter.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "FP_Formatter.hxx"
1+
#include "Formatter.hxx"
22

33
namespace FileParse
44
{
File renamed without changes.

src/FP_INodeAdapter.hxx renamed to include/fileParse/INodeAdapter.hxx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <string>
88
#include <vector>
9+
#include <optional>
910

1011
/// Interface INodeAdapter provides a set of virtual functions for node manipulation
1112
/// and data extraction in a tree-like structure.
@@ -22,23 +23,19 @@ public:
2223
/// Gets the tag of the current node.
2324
[[nodiscard]] virtual std::string getCurrentTag() const = 0;
2425

25-
/// Checks if the current tag matches the provided name.
26-
[[nodiscard]] virtual bool isCurrentTag(std::string_view name) const = 0;
27-
2826
/// Gets the text content of the current node.
2927
[[nodiscard]] virtual std::string getText() const = 0;
3028

31-
/// Counts the number of child nodes of the current node.
32-
[[nodiscard]] virtual int nChildNode() const = 0;
33-
34-
/// Gets the child node at the specified index.
35-
[[nodiscard]] virtual AdapterType getChildNode(int i) const = 0;
36-
3729
// Gets all child nodes of the current node.
3830
[[nodiscard]] virtual std::vector<AdapterType> getChildNodes() const = 0;
3931

40-
/// Gets the child node with the specified name at the specified index.
41-
[[nodiscard]] virtual AdapterType getChildNode(std::string_view name, int i) const = 0;
32+
/// If child with given name exists, it will return the first child node with the given name.
33+
[[nodiscard]] virtual std::optional<AdapterType>
34+
getFirstChildByName(std::string_view name) const = 0;
35+
36+
/// Gets the child nodes with the specified name.
37+
[[nodiscard]] virtual std::vector<AdapterType> getChildNodesByName(std::string_view name) const
38+
= 0;
4239

4340
/// Counts the number of child nodes with the specified name.
4441
[[nodiscard]] virtual int nChildNode(std::string_view name) const = 0;

src/FP_Map.hxx renamed to include/fileParse/Map.hxx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <functional>
99

10-
#include "FP_Common.hxx"
11-
#include "FP_StringConversion.hxx"
10+
#include "Common.hxx"
11+
#include "StringConversion.hxx"
1212

1313
namespace FileParse
1414
{
@@ -100,13 +100,9 @@ namespace FileParse
100100
std::string_view childNodeName,
101101
MapType & map)
102102
{
103-
int childCount = node.nChildNode(childNodeName.data());
104-
for(int i = 0; i < childCount; ++i)
103+
const auto childNodes{node.getChildNodesByName(childNodeName.data())};
104+
for(const auto & childNode : childNodes)
105105
{
106-
auto childNode = node.getChildNode(childNodeName.data(), i);
107-
108-
// Assuming key and value types have default constructors and
109-
// have the appropriate `>>` operators overloaded.
110106
typename MapType::key_type key;
111107
typename MapType::mapped_type value;
112108

@@ -159,10 +155,9 @@ namespace FileParse
159155
inline std::enable_if_t<is_valid_map<MapType>::value, const NodeAdapter &> deserializeEnumMap(
160156
const NodeAdapter & node, MapType & map, std::function<EnumType(std::string_view)> converter)
161157
{
162-
int totalNodes = node.nChildNode();
163-
for(int i = 0; i < totalNodes; ++i)
158+
const auto & childNodes{node.getChildNodes()};
159+
for(const auto & childNode : childNodes)
164160
{
165-
NodeAdapter childNode = node.getChildNode(i);
166161
if(!childNode.isEmpty())
167162
{
168163
const auto text = childNode.getText();

src/FP_Optional.hxx renamed to include/fileParse/Optional.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <optional>
88

9-
#include "FP_Common.hxx"
9+
#include "Common.hxx"
1010

1111
namespace FileParse
1212
{

src/FP_Set.hxx renamed to include/fileParse/Set.hxx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <functional>
99
#include <stdexcept>
1010

11-
#include "FP_Common.hxx"
11+
#include "Common.hxx"
1212

1313
namespace FileParse
1414
{
@@ -51,11 +51,11 @@ namespace FileParse
5151

5252
if(auto currentNode{findParentOfLastTag(node, vec.nodeNames)}; currentNode.has_value())
5353
{
54-
for(int i = 0; i < currentNode.value().nChildNode(vec.nodeNames.back()); ++i)
54+
const auto childNodes{currentNode.value().getChildNodesByName(vec.nodeNames.back())};
55+
for(const auto & childNode : childNodes)
5556
{
56-
NodeAdapter activeNode = currentNode.value().getChildNode(vec.nodeNames.back(), i);
5757
T item;
58-
activeNode >> item;
58+
childNode >> item;
5959
vec.data.insert(item);
6060
}
6161
}
@@ -164,15 +164,11 @@ namespace FileParse
164164

165165
if(auto currentNode{findParentOfLastTag(node, tags)}; currentNode.has_value())
166166
{
167-
int totalNodes = currentNode.value().nChildNode(tags.back());
168-
for(int i = 0; i < totalNodes; ++i)
167+
const auto childNodes{currentNode.value().getChildNodesByName(tags.back())};
168+
for(const auto & childNode : childNodes)
169169
{
170-
NodeAdapter childNode = currentNode.value().getChildNode(tags.back(), i);
171-
if(!childNode.isEmpty())
172-
{
173-
const auto text = childNode.getText();
174-
vec.insert(converter(text));
175-
}
170+
const auto text = childNode.getText();
171+
vec.insert(converter(text));
176172
}
177173
}
178174

File renamed without changes.

src/FP_Variant.hxx renamed to include/fileParse/Variant.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <variant>
88

9-
#include "FP_Common.hxx"
9+
#include "Common.hxx"
1010

1111
namespace FileParse
1212
{

src/FP_Vector.hxx renamed to include/fileParse/Vector.hxx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <functional>
1010
#include <stdexcept>
1111

12-
#include "FP_Common.hxx"
12+
#include "Common.hxx"
1313

1414
namespace FileParse
1515
{
@@ -55,13 +55,12 @@ namespace FileParse
5555

5656
if(auto currentNode{findParentOfLastTag(node, vec.nodeNames)}; currentNode.has_value())
5757
{
58-
int childCount = currentNode.value().nChildNode(vec.nodeNames.back());
59-
vec.data.reserve(childCount);
60-
for(int i = 0; i < childCount; ++i)
58+
const auto childNodes{currentNode.value().getChildNodesByName(vec.nodeNames.back())};
59+
vec.data.reserve(childNodes.size());
60+
for(const auto & childNode : childNodes)
6161
{
62-
NodeAdapter activeNode = currentNode.value().getChildNode(vec.nodeNames.back(), i);
6362
T item;
64-
activeNode >> item;
63+
childNode >> item;
6564
vec.data.push_back(item);
6665
}
6766
}
@@ -95,7 +94,8 @@ namespace FileParse
9594
/// @tparam NodeAdapter The type of the node adapter.
9695
/// @tparam T The type of elements in the vector.
9796
/// @param node The node to serialize the optional vector into.
98-
/// @param opt_vec The Child object containing the optional vector and node hierarchy information.
97+
/// @param opt_vec The Child object containing the optional vector and node hierarchy
98+
/// information.
9999
/// @return Reference to the updated node.
100100
template<typename NodeAdapter, typename T>
101101
inline NodeAdapter & operator<<(NodeAdapter & node,
@@ -170,15 +170,12 @@ namespace FileParse
170170

171171
if(auto currentNode{findParentOfLastTag(node, tags)}; currentNode.has_value())
172172
{
173-
int totalNodes = currentNode.value().nChildNode(tags.back());
174-
for(int i = 0; i < totalNodes; ++i)
173+
const auto childNodes{currentNode.value().getChildNodesByName(tags.back())};
174+
vec.reserve(childNodes.size());
175+
for(const auto & childNode : childNodes)
175176
{
176-
NodeAdapter childNode = currentNode.value().getChildNode(tags.back(), i);
177-
if(!childNode.isEmpty())
178-
{
179-
const auto text = childNode.getText();
180-
vec.emplace_back(converter(text));
181-
}
177+
const auto text = childNode.getText();
178+
vec.emplace_back(converter(text));
182179
}
183180
}
184181

0 commit comments

Comments
 (0)