MCPcopy Create free account
hub / github.com/NatLabRockies/SAM / Write_JSON_Constant

Method Write_JSON_Constant

src/variables.cpp:1609–1671  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1607}
1608
1609void VarValue::Write_JSON_Constant(rapidjson::Document& doc, const wxString& name, const wxArrayString& asCalculated, const wxArrayString& asIndicator, const double dConstant)
1610{
1611 wxString x;
1612 rapidjson::Value json_val, json_bin_array;
1613 rapidjson::Document json_table(&doc.GetAllocator()); // for table inside of json document.
1614 const char* p; // for VV_BINARY
1615
1616
1617 if (m_type == VV_NUMBER) {
1618 json_val = "ERROR: non-numeric value write"; // default if NaN, inf or invalid
1619 if (m_val.nrows() == 1 && m_val.ncols() == 1) {
1620 json_val = VarValueDoubleToJSONValue(dConstant);
1621 }
1622 doc.AddMember(rapidjson::Value(name.c_str(), name.size(), doc.GetAllocator()).Move(), json_val.Move(), doc.GetAllocator());
1623 }
1624 else if (m_type == VV_ARRAY) {
1625 json_val.SetArray();
1626 for (size_t j = 0; j < m_val.ncols(); j++) {
1627 json_val.PushBack(VarValueDoubleToJSONValue(dConstant), doc.GetAllocator());
1628 }
1629 doc.AddMember(rapidjson::Value(name.c_str(), name.size(), doc.GetAllocator()).Move(), json_val.Move(), doc.GetAllocator());
1630 }
1631 else if (m_type == VV_MATRIX) {
1632 json_val.SetArray();
1633 for (size_t i = 0; i < m_val.nrows(); i++) {
1634 json_val.PushBack(rapidjson::Value(rapidjson::kArrayType), doc.GetAllocator());
1635 for (size_t j = 0; j < m_val.ncols(); j++) {
1636 json_val[(rapidjson::SizeType)i].PushBack(VarValueDoubleToJSONValue(dConstant), doc.GetAllocator());
1637 }
1638 }
1639 doc.AddMember(rapidjson::Value(name.c_str(), name.size(), doc.GetAllocator()).Move(), json_val.Move(), doc.GetAllocator());
1640 }
1641 else if (m_type == VV_STRING) {
1642 x << dConstant;
1643 if (wxFileName::Exists(x)) { // write filename only
1644 wxString fn, ext;
1645 wxFileName::SplitPath(x, NULL, &fn, &ext);
1646 x = fn + "." + ext;
1647 }
1648 json_val.SetString(x.c_str(), doc.GetAllocator());
1649 doc.AddMember(rapidjson::Value(name.c_str(), name.size(), doc.GetAllocator()).Move(), json_val.Move(), doc.GetAllocator());
1650 }
1651 else if (m_type == VV_TABLE) {
1652 m_tab.Write_JSON(json_table, asCalculated, asIndicator);
1653 doc.AddMember(rapidjson::Value(name.c_str(), name.size(), doc.GetAllocator()).Move(), json_table.Move(), doc.GetAllocator());
1654 }
1655 else if (m_type == VV_DATMAT || m_type == VV_DATARR)
1656 throw(std::runtime_error("Function not implemented for VV_DATARR AND VV_DATMAT"));
1657 else if (m_type == VV_BINARY) {
1658 json_val.SetObject();
1659 json_val.AddMember("VV_TYPE", rapidjson::Value(VV_BINARY), doc.GetAllocator());
1660 p = (const char*)m_bin.GetData();
1661 json_bin_array.SetString(p, m_bin.GetDataLen());
1662 json_val.AddMember("DATA", json_bin_array.Move(), doc.GetAllocator());
1663 doc.AddMember(rapidjson::Value(name.c_str(), name.size(), doc.GetAllocator()).Move(), json_val.Move(), doc.GetAllocator());
1664 }
1665 else {
1666 // uncomment for production throw(std::runtime_error("Function not implemented for " + m_type));

Callers

nothing calls this directly

Calls 8

nrowsMethod · 0.80
ncolsMethod · 0.80
sizeMethod · 0.80
SetObjectMethod · 0.80
SetArrayMethod · 0.45
Write_JSONMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected