Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/ConvertInputFormat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#include <thread>
#include <vector>

using json = nlohmann::json;
using json = nlohmann::ordered_json;

enum class OutputTypes
{
Expand Down Expand Up @@ -294,7 +294,8 @@ bool processInput(fs::path const &inputFilePath,
OutputTypes outputType,
fs::path outputDirPath,
std::string &outputTypeStr,
bool convertHVACTemplate)
bool convertHVACTemplate,
bool orderJSON)
{
auto validation(std::make_unique<Validation>(&schema));
auto idf_parser(std::make_unique<IdfParser>());
Expand Down Expand Up @@ -502,6 +503,9 @@ Select one (case insensitive):
bool noConvertHVACTemplate = false;
app.add_flag("-n,--noHVACTemplate", noConvertHVACTemplate, "Do not convert HVACTemplate objects");

bool orderJSON = false;
app.add_flag("-k,--orderJSON", orderJSON, "Order epJSON objects");

std::vector<fs::path> files;
app.add_option("input_file", files, "Multiple input files to be translated")->required(false)->check(CLI::ExistingFile);

Expand Down Expand Up @@ -554,7 +558,7 @@ Select one (case insensitive):
{
# pragma omp for
for (int i = 0; i < number_files; ++i) {
const bool successful = processInput(files[i], schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate);
const bool successful = processInput(files[i], schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate, orderJSON);
# pragma omp atomic
++fileCount;
if (successful) {
Expand All @@ -573,7 +577,7 @@ Select one (case insensitive):
}

for (auto const &file : files) {
bool successful = processInput(file, schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate);
bool successful = processInput(file, schema, outputType, outputDirectoryPath, outputTypeStr, convertHVACTemplate, orderJSON);
++fileCount;
if (successful) {
displayMessage("Input file converted to {} successfully | {}/{} | {}", outputTypeStr, fileCount, number_files, file.generic_string());
Expand Down
12 changes: 6 additions & 6 deletions src/EnergyPlus/FileSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ namespace FileSystem {
return result;
}

nlohmann::json readJSON(fs::path const &filePath, std::ios_base::openmode mode)
nlohmann::ordered_json readJSON(fs::path const &filePath, std::ios_base::openmode mode)
{

// Shenanigans would not be needed with fmt 10+ (maybe earlier), because fmt has native fs::path support
Expand All @@ -389,15 +389,15 @@ namespace FileSystem {
case FileTypes::EpJSON:
case FileTypes::JSON:
case FileTypes::GLHE:
return nlohmann::json::parse(file, nullptr, true, true);
return nlohmann::ordered_json::parse(file, nullptr, true, true);
case FileTypes::CBOR:
return nlohmann::json::from_cbor(file);
return nlohmann::ordered_json::from_cbor(file);
case FileTypes::MsgPack:
return nlohmann::json::from_msgpack(file);
return nlohmann::ordered_json::from_msgpack(file);
case FileTypes::UBJSON:
return nlohmann::json::from_ubjson(file);
return nlohmann::ordered_json::from_ubjson(file);
case FileTypes::BSON:
return nlohmann::json::from_bson(file);
return nlohmann::ordered_json::from_bson(file);
default:
throw FatalError("Invalid file extension. Must be epJSON, JSON, or other experimental extensions");
}
Expand Down
16 changes: 8 additions & 8 deletions src/EnergyPlus/FileSystem.hh
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,22 @@ namespace FileSystem {
std::string readFile(fs::path const &filePath, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary);

// Reads the full json file if it exists
nlohmann::json readJSON(fs::path const &filePath, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary);
nlohmann::ordered_json readJSON(fs::path const &filePath, std::ios_base::openmode mode = std::ios_base::in | std::ios_base::binary);

template <FileTypes fileType> std::string getJSON(const nlohmann::json &data, int const indent = 4)
template <FileTypes fileType> std::string getJSON(const nlohmann::ordered_json &data, int const indent = 4)
{
if constexpr (is_json_type(fileType)) {
return data.dump(indent, ' ', false, nlohmann::json::error_handler_t::replace);
return data.dump(indent, ' ', false, nlohmann::ordered_json::error_handler_t::replace);
} else if constexpr (is_binary_json_type(fileType)) {
std::string binary_data;
if constexpr (fileType == FileTypes::CBOR) {
nlohmann::json::to_cbor(data, binary_data);
nlohmann::ordered_json::to_cbor(data, binary_data);
} else if constexpr (fileType == FileTypes::MsgPack) {
nlohmann::json::to_msgpack(data, binary_data);
nlohmann::ordered_json::to_msgpack(data, binary_data);
} else if constexpr (fileType == FileTypes::BSON) {
nlohmann::json::to_bson(data, binary_data);
nlohmann::ordered_json::to_bson(data, binary_data);
} else if constexpr (fileType == FileTypes::UBJSON) {
nlohmann::json::to_ubjson(data, binary_data);
nlohmann::ordered_json::to_ubjson(data, binary_data);
}
return binary_data;
} else {
Expand All @@ -225,7 +225,7 @@ namespace FileSystem {

template <class T, FileTypes fileType>
inline constexpr bool enable_json_v =
is_all_json_type(fileType) && is_any<T, nlohmann::json>::value && !is_any<T, std::string_view, std::string, char *>::value;
is_all_json_type(fileType) && is_any<T, nlohmann::ordered_json>::value && !is_any<T, std::string_view, std::string, char *>::value;

template <FileTypes fileType> void writeFile(fs::path const &filePath, const std::string_view data)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/InputProcessing/IdfParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <milo/dtoa.h>
#include <milo/itoa.h>

using json = nlohmann::json;
using json = nlohmann::ordered_json;

auto const icompare = [](std::string_view a, std::string_view b) { // (AUTO_OK)
return (a.length() == b.length()
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/InputProcessing/IdfParser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class IdfParser
{
public:
friend class EnergyPlus::InputProcessorFixture;
using json = nlohmann::json;
using json = nlohmann::ordered_json;

IdfParser() = default;

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/InputProcessing/InputProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace EnergyPlus {

static std::string const BlankString;

using json = nlohmann::json;
using json = nlohmann::ordered_json;

const json &InputProcessor::schema()
{
Expand Down
4 changes: 2 additions & 2 deletions src/EnergyPlus/InputProcessing/InputProcessor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ struct EnergyPlusData;

namespace EnergyPlus {

void cleanEPJSON(nlohmann::json &epjson);
void cleanEPJSON(nlohmann::ordered_json &epjson);

class InputProcessor
{
public:
using json = nlohmann::json;
using json = nlohmann::ordered_json;

json::parser_callback_t callback;

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/InputProcessing/InputValidation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#include <valijson/utils/nlohmann_json_utils.hpp>
#include <valijson/validator.hpp>

using json = nlohmann::json;
using json = nlohmann::ordered_json;

Validation::Validation(json const *parsed_schema)
{
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/InputProcessing/InputValidation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
class Validation
{
public:
using json = nlohmann::json;
using json = nlohmann::ordered_json;

explicit Validation(json const *parsed_schema);

Expand Down
2 changes: 1 addition & 1 deletion src/EnergyPlus/ResultsFramework.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ struct JsonOutputFilePaths;

namespace ResultsFramework {

using json = nlohmann::json;
using json = nlohmann::ordered_json;

using OutputProcessor::ReportFreq;
using OutputProcessor::TimeStepType;
Expand Down
2 changes: 1 addition & 1 deletion tst/EnergyPlus/unit/Fixtures/EnergyPlusFixture.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
#include <nlohmann/json.hpp>
#include <regex>

using json = nlohmann::json;
using json = nlohmann::ordered_json;

namespace EnergyPlus {

Expand Down
2 changes: 1 addition & 1 deletion tst/EnergyPlus/unit/Fixtures/InputProcessorFixture.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace EnergyPlus {
class InputProcessorFixture : public EnergyPlusFixture
{
protected:
using json = nlohmann::json;
using json = nlohmann::ordered_json;

// static void SetUpTestCase()
// {
Expand Down
2 changes: 1 addition & 1 deletion tst/EnergyPlus/unit/Fixtures/ResultsFrameworkFixture.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace EnergyPlus {
class ResultsFrameworkFixture : public EnergyPlusFixture
{
protected:
using json = nlohmann::json;
using json = nlohmann::ordered_json;

// static void SetUpTestCase()
// {
Expand Down
Loading