| 241 | } |
| 242 | |
| 243 | void PcdWriter::write(const PointViewPtr view) |
| 244 | { |
| 245 | std::unique_ptr<std::ostream> out(Utils::createFile(filename(), false)); |
| 246 | if (!out) |
| 247 | throwError("Couldn't open '" + filename() + "' for output."); |
| 248 | |
| 249 | PcdHeader header; |
| 250 | |
| 251 | header.m_version = PcdVersion::PCD_V7; |
| 252 | header.m_height = 1; |
| 253 | if (m_compression_string == "ascii") |
| 254 | header.m_dataStorage = PcdDataStorage::ASCII; |
| 255 | else if (m_compression_string == "binary") |
| 256 | header.m_dataStorage = PcdDataStorage::BINARY; |
| 257 | else |
| 258 | throwError("Unrecognized compression string '" + m_compression_string + "'. " |
| 259 | "Expected 'ASCII' or 'BINARY'."); |
| 260 | |
| 261 | for (auto di = m_dims.begin(); di != m_dims.end(); ++di) |
| 262 | header.m_fields.push_back(di->m_field); |
| 263 | |
| 264 | header.m_width = view->size(); |
| 265 | header.m_pointCount = view->size(); |
| 266 | |
| 267 | *out << header; |
| 268 | |
| 269 | if (m_compression_string == "ascii") |
| 270 | writeAscii(view, *out); |
| 271 | else |
| 272 | { |
| 273 | // Reopen as for binary output, seeking to the end of the header before writing data. |
| 274 | out.reset(FileUtils::openExisting(filename(), true)); |
| 275 | out->seekp(0, std::ios::end); |
| 276 | writeBinary(view, *out); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | void PcdWriter::writeAscii(const PointViewPtr view, std::ostream& out) |
| 281 | { |
nothing calls this directly
no test coverage detected