BinHandler.cpp
Go to the documentation of this file.
2 
3 #include <boost/archive/binary_iarchive.hpp>
4 #include <boost/archive/binary_oarchive.hpp>
5 #include <fstream>
6 
10 
11 namespace lanelet {
12 namespace io_handlers {
13 
14 namespace {
15 // register with factories
16 RegisterParser<BinParser> regParser;
17 RegisterWriter<BinWriter> regWriter;
18 
19 } // namespace
20 
21 void BinWriter::write(const std::string& filename, const LaneletMap& laneletMap, ErrorMessages& /*errors*/, const io::Configuration& /*params*/) const {
22  std::ofstream fs(filename, std::ofstream::binary);
23  if (!fs.good()) {
24  throw ParseError("Failed open archive " + filename);
25  }
26  boost::archive::binary_oarchive oa(fs);
27  oa << laneletMap;
28  auto idCounter = utils::getId();
29  oa << idCounter;
30 }
31 
32 std::unique_ptr<LaneletMap> BinParser::parse(const std::string& filename, ErrorMessages& /*errors*/) const {
33  std::ifstream fs(filename, std::ifstream::binary);
34  if (!fs.good()) {
35  throw ParseError("Failed open archive " + filename);
36  }
37  std::unique_ptr<LaneletMap> laneletMap = std::make_unique<LaneletMap>();
38  boost::archive::binary_iarchive ia(fs);
39  ia >> *laneletMap;
40  Id idCounter = 0;
41  ia >> idCounter;
42  utils::registerId(idCounter);
43  return laneletMap;
44 }
45 } // namespace io_handlers
46 } // namespace lanelet
lanelet::ErrorMessages
std::vector< std::string > ErrorMessages
Definition: Io.h:11
lanelet::utils::registerId
void registerId(Id id)
lanelet
lanelet::io::Configuration
std::map< std::string, Attribute > Configuration
Definition: Configuration.h:8
lanelet::utils::getId
Id getId()
lanelet::Id
int64_t Id
lanelet::io_handlers::BinParser::parse
std::unique_ptr< LaneletMap > parse(const std::string &filename, ErrorMessages &) const override
Definition: BinHandler.cpp:32
BinHandler.h
Serialize.h
lanelet::LaneletMap
lanelet::ParseError
Error thrown if some error occured during the parsing of the file.
Definition: Exceptions.h:42
lanelet::io_handlers::BinWriter::write
void write(const std::string &filename, const LaneletMap &laneletMap, ErrorMessages &, const io::Configuration &) const override
Definition: BinHandler.cpp:21
Factory.h
Exceptions.h


lanelet2_io
Author(s): Fabian Poggenhans
autogenerated on Thu Mar 6 2025 03:26:03