Files
OrcaSlicer/src/slic3r/GUI/DeviceCore/DevHMS.cpp
T
HanifKoh 73d32d4791 Stop Leaking json Through Headers and Drop Includes Kept Only for the Name (#16221)
* Stop Leaking json Through Headers and Drop Includes Kept Only for the Name

AppConfig.hpp, DeviceManager.hpp and UserManager.hpp carried a global
"using namespace nlohmann;", json_diff.hpp a global "using json =
nlohmann::json;" and PrinterFileSystem.h a global "using nlohmann::json;".
Every file that included one of them, directly or not, could write a
bare json, and 63 did without declaring it.

The last two also made the include checker treat json_diff.hpp and
PrinterFileSystem.h as the headers that provide json, so they were
included from files that use nothing else from them: 57 of the 59
includers of json_diff.hpp never name json_diff.

The five statements are removed. Headers that use the type now spell
nlohmann::json, source files declare their own "using json =
nlohmann::json;", and the includes that only supplied the name are
dropped or replaced by <nlohmann/json.hpp>.

Eight files reached json_diff.hpp only through an include that is now
gone and with it lost that header's "using namespace std;". The std
names they used unqualified are qualified.

* Declare json in OrcaSlicer.cpp on Every Platform

OrcaSlicer.cpp had its "using namespace nlohmann;" and the json include
inside the Linux-only include block, so on Windows and macOS it took
json from AppConfig.hpp's global directive, which is gone. The include
and a "using json = nlohmann::json;" now sit outside the block.
2026-10-07 14:22:16 +08:00

75 lines
2.0 KiB
C++

//#include "D:/dev/bamboo_slicer/build_release/src/slic3r/CMakeFiles/libslic3r_gui.dir/Release/cmake_pch.hxx"
#include "DevHMS.h"
#include <string>
#include <cstdio>
#include <nlohmann/json.hpp>
#include <exception>
#include <cassert>
using json = nlohmann::json;
namespace Slic3r
{
bool DevHMSItem::parse_hms_info(unsigned attr, unsigned code)
{
bool result = true;
unsigned int model_id_int = (attr >> 24) & 0xFF;
this->m_module_id = (ModuleID)model_id_int;
this->m_module_num = (attr >> 16) & 0xFF;
this->m_part_id = (attr >> 8) & 0xFF;
this->m_reserved = (attr >> 0) & 0xFF;
unsigned msg_level_int = code >> 16;
if (msg_level_int < (unsigned)HMS_MSG_LEVEL_MAX)
{
this->m_msg_level = (HMSMessageLevel)msg_level_int;
}
else
{
this->m_msg_level = HMS_UNKNOWN;
}
this->m_msg_code = code & 0xFFFF;
return result;
}
std::string DevHMSItem::get_long_error_code() const
{
char buf[64];
// Orca: HMS long-error-code format excludes the reserved byte and keys the Orca HMS wiki lookups
::sprintf(buf, "%02X%02X%02X00000%1X%04X",
this->m_module_id,
this->m_module_num,
this->m_part_id,
(int)this->m_msg_level,
this->m_msg_code);
return std::string(buf);
}
void DevHMS::ParseHMSItems(const json& hms_json)
{
m_hms_list.clear();
try
{
if (hms_json.is_array())
{
for (auto it = hms_json.begin(); it != hms_json.end(); it++)
{
DevHMSItem item;
if ((*it).contains("attr") && (*it).contains("code"))
{
unsigned attr = (*it)["attr"].get<unsigned>();
unsigned code = (*it)["code"].get<unsigned>();
item.parse_hms_info(attr, code);
}
m_hms_list.push_back(item);
}
}
}
catch (const std::exception&)
{
assert(false && "Parse HMS items failed");
}
}
}