Skip to content

Commit

Permalink
Merge pull request #8 from LBNL-ETA/UpdateExternalProject
Browse files Browse the repository at this point in the history
Update external project
  • Loading branch information
vidanovic authored Aug 23, 2024
2 parents 8b9da4f + b43f436 commit 94c1e92
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 65 deletions.
22 changes: 11 additions & 11 deletions CMakeLists-xmlParser.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
cmake_minimum_required( VERSION 2.8.7 )
cmake_minimum_required(VERSION 3.11)

set(xmlParser_INCLUDE_DIRS "${CMAKE_BINARY_DIR}/xmlParser-src/include")
include(FetchContent)

include_directories(${xmlParser_INCLUDE_DIRS})
FetchContent_Declare(
XMLParser
GIT_REPOSITORY https://github.com/LBNL-ETA/XMLParser.git
GIT_TAG v1.0.0
)

configure_file(CMakeLists-xmlParser.txt.in ${CMAKE_BINARY_DIR}/xmlParser-download/CMakeLists.txt)
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/xmlParser-download)
execute_process(COMMAND ${CMAKE_COMMAND} --build .
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/xmlParser-download)

add_subdirectory(${CMAKE_BINARY_DIR}/xmlParser-src "${CMAKE_CURRENT_BINARY_DIR}/xmlParser-src")
set(xmlParser_LIB "${CMAKE_SHARED_LIBRARY_PREFIX}xmlParser${CMAKE_SHARED_LIBRARY_SUFFIX}")
FetchContent_MakeAvailable(XMLParser)

# Assuming the target name is xmlParser
target_include_directories(xmlParser SYSTEM PUBLIC ${xmlParser_INCLUDE_DIRS})
19 changes: 0 additions & 19 deletions CMakeLists-xmlParser.txt.in

This file was deleted.

10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project( FileParse CXX )
project(FileParse CXX)

set(LIB_MAJOR_VERSION "1")
set(LIB_MINOR_VERSION "1")
Expand Down Expand Up @@ -35,16 +35,16 @@ include(CMakeLists-xmlParser.txt)
add_subdirectory(include/fileParse)

target_include_directories(${LIB_NAME}
PUBLIC
$<INSTALL_INTERFACE:include>
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

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

if(BUILD_FileParse_tests)
enable_testing()
add_subdirectory( test )
add_subdirectory(test)
endif()
2 changes: 1 addition & 1 deletion include/fileParse/Array.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Array.hxx
/// File: Array.hxx
/// @brief Provides functionality to serialize and deserialize std::array and
/// std::optional<std::array> types in the FileParse namespace.

Expand Down
3 changes: 2 additions & 1 deletion include/fileParse/Base.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Base.hxx
/// File: Base.hxx
/// @brief Provides a set of functions and templates for parsing and manipulating XML-like data
/// structures.

Expand All @@ -9,6 +9,7 @@
#include <map>
#include <unordered_map>
#include <array>
#include <vector>

#include "Formatter.hxx"

Expand Down
2 changes: 1 addition & 1 deletion include/fileParse/Common.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Common.hxx
/// File: Common.hxx
/// @brief Provides a set of functions and templates for parsing and manipulating XML-like data
/// structures.

Expand Down
2 changes: 1 addition & 1 deletion include/fileParse/Enum.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Enum.hxx
/// File: Enum.hxx
/// @brief Provides templates for serializing and deserializing enumeration types
/// using NodeAdapter in the FileParse namespace. It includes functionality
/// to convert enumeration types to and from their string representations
Expand Down
5 changes: 4 additions & 1 deletion include/fileParse/Formatter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ namespace FileParse
}
// Remove the decimal point if it's directly before 'e' or 'E'
auto dotEPos = str.find_first_of(".eE", lastNonZero);
if(dotEPos != std::string::npos && str[dotEPos + 1] == 'e' || str[dotEPos + 1] == 'E')
if (dotEPos != std::string::npos &&
(dotEPos + 1 < str.size()) &&
(str[dotEPos + 1] == 'e' || str[dotEPos + 1] == 'E'))
{
str.erase(dotEPos, 1);
}

}
else
{
Expand Down
6 changes: 5 additions & 1 deletion include/fileParse/INodeAdapter.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_INodeAdapter.hxx
/// File: INodeAdapter.hxx
/// @brief Defines the INodeAdapter interface which provides a set of functions
/// for node manipulation and data extraction, used by a general parser.

Expand Down Expand Up @@ -48,4 +48,8 @@ public:

/// Adds text content to the current node.
virtual void addText(std::string_view text) = 0;

// Adds content of the entire node structure with child into string (the same content
// that will be in the file).
[[nodiscard]] virtual std::string getContent() const = 0;
};
2 changes: 1 addition & 1 deletion include/fileParse/Map.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Map.hxx
/// File: Map.hxx
/// @brief: Provides serialization and deserialization functionalities for maps and enum maps
/// in the FileParse namespace, including utility functions for handling child nodes
/// and converting enum types to and from string representations.
Expand Down
2 changes: 1 addition & 1 deletion include/fileParse/Optional.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Optional.hxx
/// File: Optional.hxx
/// @brief Provides functionality to serialize optional data types
/// in the FileParse namespace.

Expand Down
2 changes: 1 addition & 1 deletion include/fileParse/Set.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Set.hxx
/// File: Set.hxx
/// @brief Provides serialization and deserialization functionalities for sets and enum sets
/// in the FileParse namespace.

Expand Down
2 changes: 1 addition & 1 deletion include/fileParse/StringConversion.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_StringConversion.hxx
/// File: StringConversion.hxx
/// @brief Provides functionality to convert strings to various basic data types
/// in the FileParse namespace.

Expand Down
2 changes: 1 addition & 1 deletion include/fileParse/Variant.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Variant.hxx
/// File: Variant.hxx
/// @brief Provides functionality to serialize and deserialize std::variant and
/// std::optional<std::variant> types in the FileParse namespace.

Expand Down
2 changes: 1 addition & 1 deletion include/fileParse/Vector.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_Vector.hxx
/// File: Vector.hxx
/// @brief Provides functionality to serialize and deserialize std::vector and
/// std::optional<std::vector> types in the FileParse namespace.

Expand Down
18 changes: 17 additions & 1 deletion include/fileParse/XMLNodeAdapter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,17 @@ std::string XMLNodeAdapter::getCurrentTag() const
return pimpl_->node_.getName();
}

std::string XMLNodeAdapter::getContent() const
{
return pimpl_->node_.createXMLString();
}

XMLNodeAdapter createTopNode(std::string_view topNodeName)
{
return XMLNodeAdapter(XMLParser::XMLNode::createXMLTopNode(topNodeName.data()));
}

std::optional<XMLNodeAdapter> getTopNode(std::string_view fileName, std::string_view topNodeName)
std::optional<XMLNodeAdapter> getTopNodeFromFile(std::string_view fileName, std::string_view topNodeName)
{
if(auto node{XMLParser::XMLNode::openFileHelper(fileName.data(), topNodeName.data())};
!node.isEmpty())
Expand All @@ -119,3 +124,14 @@ std::optional<XMLNodeAdapter> getTopNode(std::string_view fileName, std::string_
}
return std::nullopt;
}

std::optional<XMLNodeAdapter> getTopNodeFromString(std::string_view xml,
std::string_view topNodeName)
{
if(auto node{XMLParser::XMLNode::parseString(xml.data(), topNodeName.data())};
!node.isEmpty())
{
return XMLNodeAdapter(node);
}
return std::nullopt;
}
9 changes: 7 additions & 2 deletions include/fileParse/XMLNodeAdapter.hxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// File: FP_XMLNodeAdapter.hxx
/// File: XMLNodeAdapter.hxx
/// @brief Provides a node adapter for XML parsing and serialization
/// using an internal implementation of XMLNode.

Expand Down Expand Up @@ -74,6 +74,8 @@ public:
/// @return The number of characters written.
[[nodiscard]] int writeToFile(std::string_view outString) const;

[[nodiscard]] std::string getContent() const override;

private:
struct Impl;
std::shared_ptr<Impl> pimpl_; ///< Pointer to the implementation details.
Expand All @@ -88,5 +90,8 @@ private:
/// @param fileName The name of the file containing the XML data.
/// @param topNodeName The name of the top node to retrieve.
/// @return An optional containing the top node adapter if successful, std::nullopt otherwise.
[[nodiscard]] std::optional<XMLNodeAdapter> getTopNode(std::string_view fileName,
[[nodiscard]] std::optional<XMLNodeAdapter> getTopNodeFromFile(std::string_view fileName,
std::string_view topNodeName);

[[nodiscard]] std::optional<XMLNodeAdapter> getTopNodeFromString(std::string_view xml,
std::string_view topNodeName);
6 changes: 6 additions & 0 deletions test/helper/MockNodeAdapter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ namespace Helper
return *node_;
}

// Not implemented yet since it is not used
std::string MockNodeAdapter::getContent() const
{
return "";
}

MockNode & addChildNode(MockNode & parentNode, std::string_view tag, std::string_view text)
{
MockNode node;
Expand Down
2 changes: 2 additions & 0 deletions test/helper/MockNodeAdapter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace Helper

[[nodiscard]] MockNode getNode() const;

std::string getContent() const override;

private:
MockNode * node_{nullptr};
};
Expand Down
2 changes: 1 addition & 1 deletion test/helper/files/BaseElementXML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

BaseElement base;
if(xmlNode.has_value())
Expand Down
2 changes: 1 addition & 1 deletion test/helper/files/EnumElementXML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

EnumElement enumEl;
if(xmlNode.has_value())
Expand Down
12 changes: 6 additions & 6 deletions test/helper/files/MapElementXML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

MapElementString element;
if(xmlNode.has_value())
Expand All @@ -179,7 +179,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

MapElementOptionalString element;
if(xmlNode.has_value())
Expand All @@ -205,7 +205,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

MapElementEnum element;
if(xmlNode.has_value())
Expand All @@ -230,7 +230,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

MapElementDouble element;
if(xmlNode.has_value())
Expand All @@ -256,7 +256,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

MapElementEnumDouble element;
if(xmlNode.has_value())
Expand All @@ -283,7 +283,7 @@ namespace Helper
using FileParse::Child;
using FileParse::operator>>;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

CMAElement element;
if(xmlNode.has_value())
Expand Down
6 changes: 3 additions & 3 deletions test/helper/files/SetElementXML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

SetElementDouble element;
if(xmlNode.has_value())
Expand All @@ -132,7 +132,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

SetElementOptionalDouble element;
if(xmlNode.has_value())
Expand All @@ -159,7 +159,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

SetElementEnum element;
if(xmlNode.has_value())
Expand Down
2 changes: 1 addition & 1 deletion test/helper/files/VariantElementXML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

VariantsAll element;
if(xmlNode.has_value())
Expand Down
6 changes: 3 additions & 3 deletions test/helper/files/VectorElementXML.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

VectorElement element;
if(xmlNode.has_value())
Expand All @@ -133,7 +133,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

OptionalVectorElement element;
if(xmlNode.has_value())
Expand All @@ -159,7 +159,7 @@ namespace Helper
{
using FileParse::Child;

auto xmlNode{getTopNode(fileName, "Test")};
auto xmlNode{getTopNodeFromFile(fileName, "Test")};

EnumVectorElement element;
if(xmlNode.has_value())
Expand Down

0 comments on commit 94c1e92

Please sign in to comment.