@@ -36,27 +36,15 @@ void CANFrame::setComment(const std::string& comment) {
3636}
3737
3838bool CANFrame::contains (const std::string& name) const {
39- return strKeyIdx_ .find (name) != strKeyIdx_ .end ();
39+ return map_ .find (name) != map_ .end ();
4040}
4141
4242const CANSignal& CANFrame::at (const std::string& name) const {
43- try {
44- const IDKey& map_key = strKeyIdx_.at (name);
45- return map_.at (map_key);
46- }
47- catch (const std::out_of_range& e) {
48- throw ;
49- }
43+ return map_.at (name);
5044}
5145
5246CANSignal& CANFrame::at (const std::string& name) {
53- try {
54- const IDKey& map_key = strKeyIdx_.at (name);
55- return map_.at (map_key);
56- }
57- catch (const std::out_of_range& e) {
58- throw ;
59- }
47+ return map_.at (name);
6048}
6149
6250const CANSignal& CANFrame::operator [](const std::string& name) const {
@@ -67,27 +55,20 @@ CANSignal& CANFrame::operator[](const std::string& name) {
6755 return at (name);
6856}
6957
70- void CANFrame::addSignal (const CANSignal& signal) {
71- IDKey map_key = { signal.name (), signal.start_bit () };
72-
73- map_.insert (std::make_pair (map_key, signal));
74- intKeyIdx_.insert (std::make_pair ( signal.start_bit (), map_key));
75- strKeyIdx_.insert (std::make_pair ( signal.name (), map_key));
58+ void CANFrame::addSignal (const CANSignal& signal) {
59+ map_.insert (std::make_pair (signal.name (), signal));
7660}
7761
7862void CANFrame::removeSignal (const std::string& name) {
79- try {
80- const IDKey& map_key = strKeyIdx_.at (name);
8163
82- intKeyIdx_.erase (intKeyIdx_.find (map_key.int_key ));
83- strKeyIdx_.erase (strKeyIdx_.find (map_key.str_key ));
84- map_.erase (map_.find (map_key));
85- }
86- catch (const std::out_of_range&) {
64+ auto ite = map_.find (name);
65+ if (ite == map_.end ()) {
8766 std::string excepText = " Cannot remove signal with name \" " + name +
8867 " \" from frame \" " + this ->name () + " \" " ;
8968 throw std::out_of_range (excepText);
9069 }
70+
71+ map_.erase (ite);
9172}
9273
9374CANFrame::iterator CANFrame::begin () {
@@ -155,23 +136,6 @@ std::size_t CANFrame::size() const
155136
156137void CANFrame::clear () {
157138 map_.clear ();
158- intKeyIdx_.clear ();
159- strKeyIdx_.clear ();
160- }
161-
162- void CANFrame::removeSignal (unsigned int start_bit) {
163- try {
164- const IDKey& map_key = intKeyIdx_.at (start_bit);
165-
166- intKeyIdx_.erase (intKeyIdx_.find (map_key.int_key ));
167- strKeyIdx_.erase (strKeyIdx_.find (map_key.str_key ));
168- map_.erase (map_.find (map_key));
169- }
170- catch (const std::out_of_range&) {
171- std::string excepText = " Cannot remove signal with start bit " + std::to_string (start_bit) +
172- " \" from frame \" " + this ->name () + " \" " ;
173- throw std::out_of_range (excepText);
174- }
175139}
176140
177141void swap (CANFrame & first, CANFrame & second) {
@@ -180,11 +144,5 @@ void swap(CANFrame & first, CANFrame & second) {
180144 std::swap (first.dlc_ , second.dlc_ );
181145 std::swap (first.period_ , second.period_ );
182146 std::swap (first.map_ , second.map_ );
183- std::swap (first.intKeyIdx_ , second.intKeyIdx_ );
184- std::swap (first.strKeyIdx_ , second.strKeyIdx_ );
185147 std::swap (first.comment_ , second.comment_ );
186- }
187-
188- bool CANFrame::IntIDKeyCompare::operator ()(const IDKey& k1, const IDKey& k2) const {
189- return k1.int_key < k2.int_key ;
190- }
148+ }
0 commit comments