Skip to content

Commit 01aba4c

Browse files
author
Joshua Whitley
committed
More const stuff.
1 parent 695a28c commit 01aba4c

File tree

10 files changed

+54
-24
lines changed

10 files changed

+54
-24
lines changed

examples/parse_types.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int main(int argc, char ** argv)
6161
std::cout << "Signal receiving bus nodes: ";
6262

6363
for (auto & node : sig.getReceivingNodes()) {
64-
std::cout << node.getName() << " ";
64+
std::cout << node->getName() << " ";
6565
}
6666

6767
std::cout << std::endl;

examples/read_dbc.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ int main(int argc, char ** argv)
5151
auto attr_defs = dbc.getAttributeDefinitions();
5252

5353
for (auto & bus_node : bus_nodes) {
54-
if (bus_node.getComment() != nullptr) {
54+
if (bus_node->getComment() != nullptr) {
5555
bus_node_comment_counter++;
5656
}
5757
}
5858

5959
for (auto & msg : messages) {
60-
auto signals = msg.second.getSignals();
60+
auto signals = msg.second->getSignals();
6161

62-
if (msg.second.getComment() != nullptr) {
62+
if (msg.second->getComment() != nullptr) {
6363
message_comment_counter++;
6464
}
6565

6666
signal_counter += signals.size();
6767

6868
for (auto & sig : signals) {
69-
if (sig.second.getComment() != nullptr) {
69+
if (sig.second->getComment() != nullptr) {
7070
signal_comment_counter++;
7171
}
7272
}

include/bus_node.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace DbcLoader
3535
{
3636

3737
class BusNode
38-
: public AttributeObject
38+
: public AttrObj
3939
{
4040
public:
4141
BusNode(std::string && node_name);

include/common_defs.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class DbcObj
152152
virtual void parse() = 0;
153153
};
154154

155-
class AttributeObject
155+
class AttrObj
156156
{
157157
public:
158158
const std::unordered_map<std::string, std::string> getAttributeValues()

include/database.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ class Database
5656

5757
std::string getVersion() const;
5858
std::string getBusConfig() const;
59-
std::vector<BusNode> getBusNodes() const;
60-
std::unordered_map<unsigned int, Message> getMessages() const;
59+
std::vector<const BusNode *> getBusNodes() const;
60+
std::unordered_map<unsigned int, const Message *> getMessages() const;
6161
std::vector<const Attribute *> getAttributeDefinitions() const;
6262
void writeDbcToFile(const std::string & dbc_path) const;
6363
void writeDbcToStream(std::ostream & mem_stream) const;

include/message.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace DbcLoader
3939
{
4040

4141
class Message
42-
: public DbcObj, public AttributeObject
42+
: public DbcObj, public AttrObj
4343
{
4444
public:
4545
Message(std::string && dbc_text);
@@ -60,7 +60,7 @@ class Message
6060
unsigned char getDlc() const;
6161
unsigned char getLength() const;
6262
BusNode getTransmittingNode() const;
63-
std::unordered_map<std::string, Signal> getSignals() const;
63+
std::unordered_map<std::string, const Signal *> getSignals() const;
6464
const std::string * getComment() const;
6565

6666
unsigned char dlcToLength(const unsigned char & dlc) const;

include/signal.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace DbcLoader
3838
{
3939

4040
class Signal
41-
: public DbcObj, public AttributeObject
41+
: public DbcObj, public AttrObj
4242
{
4343
public:
4444
Signal(std::string && dbc_text);
@@ -76,8 +76,8 @@ class Signal
7676
float getMinVal() const;
7777
float getMaxVal() const;
7878
std::string getUnit() const;
79-
std::vector<BusNode> getReceivingNodes() const;
80-
std::map<unsigned int, std::string> getValueDescriptions() const;
79+
std::vector<const BusNode *> getReceivingNodes() const;
80+
std::map<unsigned int, const std::string *> getValueDescriptions() const;
8181
const std::string * getComment() const;
8282

8383
friend class Message;

src/database.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,26 @@ std::string Database::getBusConfig() const
9494
return bus_config_;
9595
}
9696

97-
std::vector<BusNode> Database::getBusNodes() const
97+
std::vector<const BusNode *> Database::getBusNodes() const
9898
{
99-
return std::vector<BusNode>(bus_nodes_);
99+
std::vector<const BusNode *> nodes;
100+
101+
for (auto & node : bus_nodes_) {
102+
nodes.emplace_back(&node);
103+
}
104+
105+
return nodes;
100106
}
101107

102-
std::unordered_map<unsigned int, Message> Database::getMessages() const
108+
std::unordered_map<unsigned int, const Message *> Database::getMessages() const
103109
{
104-
return std::unordered_map<unsigned int, Message>(messages_);
110+
std::unordered_map<unsigned int, const Message *> msgs;
111+
112+
for (auto & msg : messages_) {
113+
msgs[msg.first] = &(msg.second);
114+
}
115+
116+
return msgs;
105117
}
106118

107119
std::vector<const Attribute *> Database::getAttributeDefinitions() const

src/message.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,15 @@ BusNode Message::getTransmittingNode() const
103103
return BusNode(transmitting_node_);
104104
}
105105

106-
std::unordered_map<std::string, Signal> Message::getSignals() const
106+
std::unordered_map<std::string, const Signal *> Message::getSignals() const
107107
{
108-
return signals_;
108+
std::unordered_map<std::string, const Signal *> sigs;
109+
110+
for (auto & sig : signals_) {
111+
sigs[sig.first] = &(sig.second);
112+
}
113+
114+
return sigs;
109115
}
110116

111117
const std::string * Message::getComment() const

src/signal.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,26 @@ std::string Signal::getUnit() const
166166
return unit_;
167167
}
168168

169-
std::vector<BusNode> Signal::getReceivingNodes() const
169+
std::vector<const BusNode *> Signal::getReceivingNodes() const
170170
{
171-
return receiving_nodes_;
171+
std::vector<const BusNode *> nodes;
172+
173+
for (auto & node : receiving_nodes_) {
174+
nodes.push_back(&node);
175+
}
176+
177+
return nodes;
172178
}
173179

174-
std::map<unsigned int, std::string> Signal::getValueDescriptions() const
180+
std::map<unsigned int, const std::string *> Signal::getValueDescriptions() const
175181
{
176-
return value_descs_;
182+
std::map<unsigned int, const std::string *> descs;
183+
184+
for (auto & desc : value_descs_) {
185+
descs[desc.first] = &(desc.second);
186+
}
187+
188+
return descs;
177189
}
178190

179191
const std::string * Signal::getComment() const

0 commit comments

Comments
 (0)