MCPcopy Create free account
hub / github.com/Notgnoshi/generative / read_node

Method read_node

generative/io/tgf-graph-reader.cpp:64–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64void TGFGraphReader::read_node(const std::string& _line) noexcept
65{
66 const auto line = trim(_line);
67 std::istringstream input(line);
68
69 if (line == "#")
70 {
71 LOG4CPLUS_INFO(s_logger, "Finished reading " << m_nodes_list.size() << " nodes");
72 m_reading_nodes = false;
73 m_nodes_vec.reserve(m_nodes_list.size());
74 std::move(m_nodes_list.begin(), m_nodes_list.end(), std::back_inserter(m_nodes_vec));
75 return;
76 }
77
78 std::size_t index = 0;
79 std::string label;
80
81 input >> index;
82 std::getline(input, label);
83
84 if (input.fail())
85 {
86 LOG4CPLUS_WARN(s_logger, "Failed to read node from line '" << line << "'");
87 return;
88 }
89
90 //! @todo If we fail to parse node N, we will fail to parse node N+1, even if it is well-formed
91 //! until we parse node N. I think to fix this, we need to use a std::unordered_map<size_t,
92 //! Node>, and collapse it into a vector once both the nodes and the edges are known. This
93 //! removes the requirement of node labels 1...N without gaps. Doing so will also require
94 //! changing the index to be non-const in the Node definition.
95 if (index > m_nodes_list.size())
96 {
97 LOG4CPLUS_WARN(s_logger,
98 "Attempted to read node index " << index << " before expected index "
99 << m_nodes_list.size());
100 return;
101 }
102 if (index < m_nodes_list.size())
103 {
104 LOG4CPLUS_WARN(s_logger,
105 "Attempted to read duplicate index " << index << ". Expected index "
106 << m_nodes_list.size());
107 return;
108 }
109
110 std::unique_ptr<geos::geom::Geometry> geometry = nullptr;
111 try
112 {
113 geometry = m_reader.read(label);
114 } catch (const geos::io::ParseException& e)
115 {
116 LOG4CPLUS_WARN(s_logger, "Failed to parse node label '" << label << "' as WKT");
117 return;
118 }
119
120 if (geometry->getGeometryTypeId() != geos::geom::GeometryTypeId::GEOS_POINT)
121 {

Callers

nothing calls this directly

Calls 4

trimFunction · 0.85
readMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected