Skip to content

Commit

Permalink
stubbed out yaml parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
K20shores committed Feb 7, 2024
1 parent 622017e commit 2060be0
Show file tree
Hide file tree
Showing 111 changed files with 291 additions and 107 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ jobs:
# all available versions of xcode: https://github.com/actions/runner-images/blob/main/images/macos/macos-13-Readme.md#xcode
xcode: ['15.0']
build_type: [Debug, Release]
enable_json: [OFF, ON]
enable_yaml: [OFF, ON]
env:
DEVELOPER_DIR: /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer

steps:
- uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D ENABLE_JSON=${{ matrix.enable_json }} -D ENABLE_YAML=${{ matrix.enable_yaml }}

- name: Build
run: cmake --build build --parallel 10
Expand All @@ -41,6 +43,8 @@ jobs:
- { cpp: g++-12, c: gcc-12}
- { cpp: clang++, c: clang}
build_type: [Debug, Release]
enable_json: [OFF, ON]
enable_yaml: [OFF, ON]
env:
CC: ${{ matrix.compiler.c }}
CXX: ${{ matrix.compiler.cpp }}
Expand All @@ -49,7 +53,7 @@ jobs:
- uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D ENABLE_JSON=${{ matrix.enable_json }} -D ENABLE_YAML=${{ matrix.enable_yaml }}

- name: Build
run: cmake --build build --parallel 10
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
strategy:
matrix:
build_type: [Debug, Release]
enable_json: [OFF, ON]
enable_yaml: [OFF, ON]
env:
CC: gcc
CXX: g++
Expand All @@ -21,7 +23,7 @@ jobs:
uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D ENABLE_JSON=${{ matrix.enable_json }} -D ENABLE_YAML=${{ matrix.enable_yaml }}

- name: Build
run: cmake --build build --parallel 10
Expand All @@ -37,6 +39,8 @@ jobs:
strategy:
matrix:
build_type: [Debug, Release]
enable_json: [OFF, ON]
enable_yaml: [OFF, ON]
env:
CC: clang
CXX: clang++
Expand All @@ -45,7 +49,7 @@ jobs:
uses: actions/checkout@v3

- name: Run Cmake
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
run: cmake -S . -B build -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D ENABLE_JSON=${{ matrix.enable_json }} -D ENABLE_YAML=${{ matrix.enable_yaml }}

- name: Build
run: cmake --build build --verbose
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ jobs:
matrix:
build_type: [Release]
architecture: [Win32, x64]
enable_json: [OFF, ON]
enable_yaml: [OFF, ON]

steps:
- uses: actions/checkout@v3
- name: Run CMake
run: cmake -S . -B build -A ${{ matrix.architecture }} -D CMAKE_BUILD_TYPE=${{ matrix.build_type }}
run: cmake -S . -B build -A ${{ matrix.architecture }} -D CMAKE_BUILD_TYPE=${{ matrix.build_type }} -D ENABLE_JSON=${{ matrix.enable_json }} -D ENABLE_YAML=${{ matrix.enable_yaml }}
- name: Build
- name: Build
run: cmake --build build --config ${{ matrix.build_type }} --parallel 10
- name: Run tests
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${PROJECT_SOURCE_DIR}/cmake")

option(ENABLE_TESTS "Build the tests" ON)
option(ENABLE_JSON "Include JSON support" ON)
option(ENABLE_YAML "Include YAML support" ON)

################################################################################
# Dependencies
Expand Down
23 changes: 18 additions & 5 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,21 @@ endif()
################################################################################
# nlohmann::json

FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
)
FetchContent_MakeAvailable(json)
if(ENABLE_JSON)
FetchContent_Declare(json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
)
FetchContent_MakeAvailable(json)
endif()

################################################################################
# yaml-cpp

if(ENABLE_YAML)
FetchContent_Declare(yaml
GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git
GIT_TAG 0.8.0
)
FetchContent_MakeAvailable(yaml)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fstream>
#include <iostream>
#include <nlohmann/json.hpp>
#include <open_atmos/mechanism_configuration/parse_status.hpp>
#include <open_atmos/types.hpp>
#include <string>
#include <unordered_map>
Expand All @@ -18,28 +19,6 @@ namespace open_atmos
{
namespace mechanism_configuration
{
enum class ConfigParseStatus
{
Success,
None,
InvalidKey,
UnknownKey,
InvalidFilePath,
ObjectTypeNotFound,
RequiredKeyNotFound,
MutuallyExclusiveOption,
InvalidVersion,
DuplicateSpeciesDetected,
DuplicatePhasesDetected,
PhaseRequiresUnknownSpecies,
ReactionRequiresUnknownSpecies,
UnknownPhase,
RequestedAerosolSpeciesNotIncludedInAerosolPhase,
TooManyReactionComponents,
InvalidIonPair
};
std::string configParseStatusToString(const ConfigParseStatus &status);

class JsonParser
{
public:
Expand Down
36 changes: 36 additions & 0 deletions include/open_atmos/mechanism_configuration/parse_status.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research, University of Illinois at Urbana-Champaign
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <string>

namespace open_atmos
{
namespace mechanism_configuration
{
enum class ConfigParseStatus
{
Success,
None,
InvalidKey,
UnknownKey,
InvalidFilePath,
ObjectTypeNotFound,
RequiredKeyNotFound,
MutuallyExclusiveOption,
InvalidVersion,
DuplicateSpeciesDetected,
DuplicatePhasesDetected,
PhaseRequiresUnknownSpecies,
ReactionRequiresUnknownSpecies,
UnknownPhase,
RequestedAerosolSpeciesNotIncludedInAerosolPhase,
TooManyReactionComponents,
InvalidIonPair
};
std::string configParseStatusToString(const ConfigParseStatus &status);

} // namespace mechanism_configuration
} // namespace open_atmos
41 changes: 41 additions & 0 deletions include/open_atmos/mechanism_configuration/yaml_parser.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research, University of Illinois at Urbana-Champaign
//
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include <filesystem>
#include <fstream>
#include <iostream>
#include <open_atmos/mechanism_configuration/parse_status.hpp>
#include <yaml-cpp/yaml.h>
#include <open_atmos/types.hpp>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

namespace open_atmos
{
namespace mechanism_configuration
{
class YamlParser
{
public:
/// @brief Reads a configuration from a YAML node
/// @param node a YAML node
/// @return A pair containing the parsing status and mechanism
std::pair<ConfigParseStatus, types::Mechanism> Parse(const YAML::Node& node);

/// @brief Reads a configuration from a file path
/// @param file_path A path to single YAML configuration
/// @return A pair containing the parsing status and mechanism
std::pair<ConfigParseStatus, types::Mechanism> Parse(const std::filesystem::path& file_path);

/// @brief Reads a configuration from a file path
/// @param file_path A path to single YAML configuration
/// @return A pair containing the parsing status and mechanism
std::pair<ConfigParseStatus, types::Mechanism> Parse(const std::string& file_path);
};
} // namespace mechanism_configuration
} // namespace open_atmos
8 changes: 7 additions & 1 deletion packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ install(
)


install(TARGETS nlohmann_json EXPORT mechanism_configuration_Exports)
install(
TARGETS
nlohmann_json
yaml-cpp
EXPORT
mechanism_configuration_Exports
)

# install the cmake config files
set(cmake_config_install_location ${INSTALL_PREFIX}/cmake)
Expand Down
26 changes: 24 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ target_compile_features(mechanism_configuration PUBLIC cxx_std_17)

target_sources(mechanism_configuration
PRIVATE
parser.cpp
parse_status.cpp
)

target_include_directories(mechanism_configuration
Expand All @@ -18,4 +18,26 @@ target_include_directories(mechanism_configuration
$<INSTALL_INTERFACE:include>
)

target_link_libraries(mechanism_configuration PUBLIC nlohmann_json::nlohmann_json)
if(ENABLE_JSON)
target_sources(mechanism_configuration
PRIVATE
json_parser.cpp
)

target_link_libraries(mechanism_configuration
PUBLIC
nlohmann_json::nlohmann_json
)
endif()

if(ENABLE_YAML)
target_sources(mechanism_configuration
PRIVATE
yaml_parser.cpp
)

target_link_libraries(mechanism_configuration
PUBLIC
yaml-cpp::yaml-cpp
)
endif()
26 changes: 1 addition & 25 deletions src/parser.cpp → src/json_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <map>
#include <open_atmos/constants.hpp>
#include <open_atmos/mechanism_configuration/parser.hpp>
#include <open_atmos/mechanism_configuration/json_parser.hpp>
#include <open_atmos/mechanism_configuration/validation.hpp>
#include <open_atmos/mechanism_configuration/version.hpp>

Expand Down Expand Up @@ -1406,30 +1406,6 @@ namespace open_atmos
{
namespace mechanism_configuration
{
std::string configParseStatusToString(const ConfigParseStatus& status)
{
switch (status)
{
case ConfigParseStatus::Success: return "Success";
case ConfigParseStatus::None: return "None";
case ConfigParseStatus::InvalidKey: return "InvalidKey";
case ConfigParseStatus::UnknownKey: return "UnknownKey";
case ConfigParseStatus::InvalidFilePath: return "InvalidFilePath";
case ConfigParseStatus::ObjectTypeNotFound: return "ObjectTypeNotFound";
case ConfigParseStatus::RequiredKeyNotFound: return "RequiredKeyNotFound";
case ConfigParseStatus::MutuallyExclusiveOption: return "MutuallyExclusiveOption";
case ConfigParseStatus::DuplicateSpeciesDetected: return "DuplicateSpeciesDetected";
case ConfigParseStatus::DuplicatePhasesDetected: return "DuplicatePhasesDetected";
case ConfigParseStatus::PhaseRequiresUnknownSpecies: return "PhaseRequiresUnknownSpecies";
case ConfigParseStatus::ReactionRequiresUnknownSpecies: return "ReactionRequiresUnknownSpecies";
case ConfigParseStatus::UnknownPhase: return "UnknownPhase";
case ConfigParseStatus::RequestedAerosolSpeciesNotIncludedInAerosolPhase: return "RequestedAerosolSpeciesNotIncludedInAerosolPhase";
case ConfigParseStatus::TooManyReactionComponents: return "TooManyReactionComponents";
case ConfigParseStatus::InvalidIonPair: return "InvalidIonPair";
default: return "Unknown";
}
}

/// @brief Parse a mechanism
/// @param file_path a location on the hard drive containing a mechanism
/// @return A pair containing the parsing status and a mechanism
Expand Down
31 changes: 31 additions & 0 deletions src/parse_status.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <open_atmos/mechanism_configuration/parse_status.hpp>

namespace open_atmos
{
namespace mechanism_configuration
{
std::string configParseStatusToString(const ConfigParseStatus& status)
{
switch (status)
{
case ConfigParseStatus::Success: return "Success";
case ConfigParseStatus::None: return "None";
case ConfigParseStatus::InvalidKey: return "InvalidKey";
case ConfigParseStatus::UnknownKey: return "UnknownKey";
case ConfigParseStatus::InvalidFilePath: return "InvalidFilePath";
case ConfigParseStatus::ObjectTypeNotFound: return "ObjectTypeNotFound";
case ConfigParseStatus::RequiredKeyNotFound: return "RequiredKeyNotFound";
case ConfigParseStatus::MutuallyExclusiveOption: return "MutuallyExclusiveOption";
case ConfigParseStatus::DuplicateSpeciesDetected: return "DuplicateSpeciesDetected";
case ConfigParseStatus::DuplicatePhasesDetected: return "DuplicatePhasesDetected";
case ConfigParseStatus::PhaseRequiresUnknownSpecies: return "PhaseRequiresUnknownSpecies";
case ConfigParseStatus::ReactionRequiresUnknownSpecies: return "ReactionRequiresUnknownSpecies";
case ConfigParseStatus::UnknownPhase: return "UnknownPhase";
case ConfigParseStatus::RequestedAerosolSpeciesNotIncludedInAerosolPhase: return "RequestedAerosolSpeciesNotIncludedInAerosolPhase";
case ConfigParseStatus::TooManyReactionComponents: return "TooManyReactionComponents";
case ConfigParseStatus::InvalidIonPair: return "InvalidIonPair";
default: return "Unknown";
}
}
}
}
Loading

0 comments on commit 2060be0

Please sign in to comment.