#include "dbcc/message.h" #include #include #include namespace ad { namespace dbcc { std::istream& operator>>(std::istream& in, Message& msg) { // Parse the message ID. in >> msg.id_; // Parse the name of the message std::string name; in >> name; msg.name_ = name.substr(0, name.length() - 1); // Parse the message length in >> msg.dlc_; // Parse the sender in >> msg.from_; in.ignore(std::numeric_limits::max(), '\n'); // As long as there is a signal, parse the signal while (true) { std::string preamble; auto pos = in.tellg(); in >> preamble; // Check if we are actually reading a signal if (preamble != "SG_") { if (in.eof()) { return in; } // Revert the stream to the preamble position in.seekg(pos, std::ios_base::beg); break; } Signal sig; in >> sig; if (in) { msg.AppendSignal(sig); } } in.clear(); return in; } std::set Message::To() const { std::set collection; for (auto sig : signals_) { auto to_list = sig.To(); collection.insert(to_list.begin(), to_list.end()); } return collection; } std::ostream& operator<<(std::ostream& out, const Message& msg) { out << "BU_ " << msg.Id() << " " << msg.Name() << ": " << msg.Dlc() << " "; if (!msg.From().empty()) { out << msg.From(); } out << "\n"; for (auto& sig : msg.signals_) { out << " " << sig.ToDbcString() << "\n"; } return out; } } // namespace dbcc } // namespace ad