feat(json): added nlohmann JSON

Added header only json library for better logging
This commit is contained in:
2025-11-24 09:06:34 -05:00
parent 9f56ba0083
commit 15ed7f70b1
9 changed files with 25555 additions and 123 deletions

View File

@@ -1,3 +0,0 @@
#pragma once
#include "gridfire/expectations/expected_engine.h"

View File

@@ -1,60 +0,0 @@
#pragma once
#include <string>
#include <iostream>
#include <utility>
namespace gridfire::expectations {
enum class EngineErrorTypes {
FAILURE,
INDEX,
STALE
};
enum class StaleEngineErrorTypes {
SYSTEM_RESIZED
};
// TODO: rename this to EngineExpectation or something similar
struct EngineError {
std::string m_message;
const EngineErrorTypes type = EngineErrorTypes::FAILURE;
explicit EngineError(std::string message, const EngineErrorTypes type)
: m_message(std::move(message)), type(type) {}
virtual ~EngineError() = default;
friend std::ostream& operator<<(std::ostream& os, const EngineError& e) {
os << "EngineError: " << e.m_message;
return os;
}
};
struct EngineIndexError : EngineError {
int m_index;
explicit EngineIndexError(const int index)
: EngineError("Index error occurred", EngineErrorTypes::INDEX), m_index(index) {}
friend std::ostream& operator<<(std::ostream& os, const EngineIndexError& e) {
os << "EngineIndexError: " << e.m_message << " at index " << e.m_index;
return os;
}
};
struct StaleEngineError final : EngineError {
StaleEngineErrorTypes staleType;
explicit StaleEngineError(const StaleEngineErrorTypes sType)
: EngineError("Stale engine error occurred", EngineErrorTypes::STALE), staleType(sType) {}
explicit operator std::string() const {
switch (staleType) {
case (StaleEngineErrorTypes::SYSTEM_RESIZED):
return "StaleEngineError: System resized, please update the engine.";
default:
return "StaleEngineError: Unknown stale error type.";
}
}
};
}

View File

@@ -2,13 +2,13 @@
//
// Copyright (C) 2025 -- The 4D-STAR Collaboration
// File Authors: Emily Boudreaux, Aaron Dotter
// Last Modified: March 21, 2025
// Last Modified: Nov 24, 2025
//
// 4DSSE is free software; you can use it and/or modify
// GridFire is free software; you can use it and/or modify
// it under the terms and restrictions the GNU General Library Public
// License version 3 (GPLv3) as published by the Free Software Foundation.
//
// 4DSSE is distributed in the hope that it will be useful,
// GridFire is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Library General Public License for more details.
@@ -28,20 +28,6 @@
namespace gridfire {
enum NetworkFormat {
APPROX8, ///< Approx8 nuclear reaction network format.
REACLIB, ///< General REACLIB nuclear reaction network format.
UNKNOWN,
};
static inline std::unordered_map<NetworkFormat, std::string> FormatStringLookup = {
{APPROX8, "Approx8"},
{REACLIB, "REACLIB"},
{UNKNOWN, "Unknown"}
};
struct NetIn {
fourdst::composition::Composition composition; ///< Composition of the network
double tMax; ///< Maximum time

View File

@@ -1,43 +0,0 @@
/* ***********************************************************************
//
// Copyright (C) 2025 -- The 4D-STAR Collaboration
// File Authors: Aaron Dotter, Emily Boudreaux
// Last Modified: March 21, 2025
//
// 4DSSE is free software; you can use it and/or modify
// it under the terms and restrictions the GNU General Library Public
// License version 3 (GPLv3) as published by the Free Software Foundation.
//
// 4DSSE is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this software; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// *********************************************************************** */
#include "gridfire/network.h"
#include "gridfire/reaction/reaction.h"
#include <ranges>
namespace gridfire {
// Trim whitespace from both ends of a string
std::string trim_whitespace(const std::string& str) {
auto startIt = str.begin();
const auto endIt = str.end();
while (startIt != endIt && std::isspace(static_cast<unsigned char>(*startIt))) {
++startIt;
}
if (startIt == endIt) {
return "";
}
const auto ritr = std::find_if(str.rbegin(), std::string::const_reverse_iterator(startIt),
[](const unsigned char ch){ return !std::isspace(ch); });
return {startIt, ritr.base()};
}
}