DbcMessage.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2015-2020, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #include "DbcMessage.hpp"
36 
37 #include <istream>
38 #include <limits>
39 #include <algorithm>
40 
41 std::istream& operator>>(std::istream& in, Message& msg) {
42  // Check if we are actually reading a Message otherwise fail the stream
43  std::string preamble;
44  in >> preamble;
45  if (preamble != "BO_") {
46  in.setstate(std::ios_base::failbit);
47  return in;
48  }
49 
50  // Parse the message ID
51  in >> msg.id;
52 
53  // Parse the name of the Message
54  std::string name;
55  in >> name;
56  msg.name = name.substr(0, name.length() - 1);
57 
58  // Parse the Messages length
59  in >> msg.dlc;
60 
61  // Parse the sender;
62  in >> msg.from;
63 
64  // As long as there is a Signal, parse the Signal
65  in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
66  while (in) {
67  Signal sig;
68  in >> sig;
69  if (in && !in.fail()) {
70  msg.signals.push_back(sig);
71  }
72  }
73 
74  in.clear();
75  return in;
76 }
77 
78 
79 std::set<std::string> Message::getTo() const {
80  std::set<std::string> collection;
81  for (size_t i = 0; i < signals.size(); i++) {
82  collection.insert(signals[i].getTo().begin(), signals[i].getTo().end());
83  }
84  return collection;
85 }
86 
std::set< std::string > getTo() const
Definition: DbcMessage.cpp:79
const_iterator begin() const
Definition: DbcMessage.hpp:81
const_iterator end() const
Definition: DbcMessage.hpp:82
std::istream & operator>>(std::istream &in, Message &msg)
Definition: DbcMessage.cpp:41
std::string name
Definition: DbcMessage.hpp:54
uint32_t id
Definition: DbcMessage.hpp:56
signals_t signals
Definition: DbcMessage.hpp:62
std::size_t dlc
Definition: DbcMessage.hpp:58
std::string from
Definition: DbcMessage.hpp:60


dataspeed_can_tools
Author(s): Micho Radovnikovich
autogenerated on Thu Jul 9 2020 03:41:59