@@ -40,8 +40,16 @@ class CANDatabase {
4040 static CANDatabase fromString (const std::string& src_string);
4141
4242public:
43- using container_type = std::map<unsigned long long , std::shared_ptr<CANFrame>>;
44- using str_container_type = std::map<std::string, std::shared_ptr<CANFrame>>;
43+ struct IDKey {
44+ std::string str_key;
45+ unsigned long long int_key;
46+ };
47+
48+ struct IntIDKeyCompare {
49+ bool operator ()(const IDKey& k1, const IDKey& k2) const ;
50+ };
51+
52+ using container_type = std::map<IDKey, CANFrame, IntIDKeyCompare>;
4553
4654 using iterator = container_type::iterator;
4755 using const_iterator = container_type::const_iterator;
@@ -64,46 +72,63 @@ class CANDatabase {
6472 * Creates a copy of the database: the individual frames are deep copied so there is no
6573 * shared memory betwwen the two databases.
6674 */
67- CANDatabase (const CANDatabase&);
75+ CANDatabase (const CANDatabase&) = default ;
6876
6977 /* *
7078 * @brief Makes a copy of the given database
71- * Note: the source database is passed-by-value for RVO
72- * (see https://stackoverflow.com/a/3279550/8147455 for more info)
7379 */
74- CANDatabase& operator =(const CANDatabase&);
80+ CANDatabase& operator =(const CANDatabase&) = default ;
7581
7682 /* *
7783 * @brief Moves a CANDatabase object. The CANFrame objects are NOT deep copied.
7884 */
79- CANDatabase (CANDatabase&&);
85+ CANDatabase (CANDatabase&&) = default ;
8086
8187 /* *
8288 * @see CANDatabase(const CANDatabase&&)
8389 */
84- CANDatabase& operator =(CANDatabase&&);
90+ CANDatabase& operator =(CANDatabase&&) = default ;
8591
8692public:
8793 /* *
8894 * @brief Get the frame with the given frame name
8995 */
90- std::shared_ptr<CANFrame> at (unsigned long long frame_name) const ;
96+ const CANFrame& at (unsigned long long frame_id) const ;
97+
98+ /* *
99+ * @brief Get the frame with the given frame name
100+ */
101+ CANFrame& at (unsigned long long frame_id);
102+
103+ /* *
104+ * @brief Get the frame with the given frame id
105+ */
106+ const CANFrame& at (const std::string& frame_name) const ;
91107
92108 /* *
93109 * @brief Get the frame with the given frame id
94110 */
95- std::shared_ptr< CANFrame> at (const std::string& frame_name) const ;
111+ CANFrame& at (const std::string& frame_name);
96112
97113 /* *
98114 * @brief Get the frame with the given frame id
99- * @see getFrame
100115 */
101- std::shared_ptr<CANFrame> operator [](unsigned long long frame_idx) const ;
116+ const CANFrame& operator [](unsigned long long frame_idx) const ;
117+
118+ /* *
119+ * @brief Get the frame with the given frame id
120+ */
121+ CANFrame& operator [](unsigned long long frame_idx);
102122
103123 /* *
104124 * @brief Get the frame with the given frame name
105125 */
106- std::shared_ptr<CANFrame> operator [](const std::string& frame_name) const ;
126+ const CANFrame& operator [](const std::string& frame_name) const ;
127+
128+ /* *
129+ * @brief Get the frame with the given frame name
130+ */
131+ CANFrame& operator [](const std::string& frame_name);
107132
108133 /* *
109134 * @return true if the CANDatabase contains a frame with the given frame id
@@ -152,14 +177,16 @@ class CANDatabase {
152177
153178 void clear ();
154179
155- void addFrame (std::shared_ptr< CANFrame> frame);
180+ void addFrame (const CANFrame& frame);
156181 void removeFrame (unsigned int idx);
157182 void removeFrame (const std::string& name);
158183
159184private:
160185 std::string filename_;
161- str_container_type strIndex_; // Index by frame name
162- container_type intIndex_; // Index by CAN ID
186+ container_type map_; // Index by CAN ID
187+
188+ std::map<unsigned long long , IDKey> intKeyIndex_;
189+ std::map<std::string, IDKey> strKeyIndex_;
163190};
164191
165192#endif
0 commit comments