22
22
23
23
24
24
#include < string>
25
- #include < vector>
26
25
#include < algorithm>
27
26
28
27
#include " global.hpp"
28
+ #include " ordered_dict.h"
29
29
#include " data_point.hpp"
30
30
#include " data_line.hpp"
31
31
39
39
template <typename T_DATA_POINT, typename T_INDEX >
40
40
class Diagram {
41
41
public:
42
- using DataLine_t = DataLine<T_DATA_POINT, T_INDEX>;
43
- using DataPoint_t = DataPoint<T_DATA_POINT>;
42
+ using coordinate_t = T_DATA_POINT;
43
+ using index_t = T_INDEX;
44
+ using DataPoint_t = DataPoint<coordinate_t >;
45
+ using DataLine_t = DataLine<coordinate_t , index_t >;
46
+ using DataContainer_t = OrderedDict<DataLine_t>;
44
47
45
48
Diagram (const std::string& newDiagramTitle = " " , const std::string& newAxisXTitle = " " ) : DiagramTitle(newDiagramTitle), AxisXTitle(newAxisXTitle) {}
46
49
@@ -72,102 +75,75 @@ class Diagram {
72
75
AxisXTitle = newAxisXTitle;
73
76
}
74
77
75
- void AddNewDataLine (const std::string& newDataLineId = DataLine_t::invalid_id ,
78
+ bool AddNewDataLine (const std::string& newDataLineId,
76
79
const std::string& newDataLineTitle = " " )
77
80
{
78
- Data.push_back ( DataLine_t ( newDataLineId, newDataLineTitle));
81
+ return Data.emplace_back ( newDataLineId, DataLine_t ( newDataLineTitle));
79
82
}
80
83
81
- inline const T_INDEX GetTheNumberOfDataLines ( void ) const
84
+ inline bool HasDataLine ( const index_t & dataLineIndex ) const
82
85
{
83
- return Data.size ( );
86
+ return (! Data.empty () && (dataLineIndex <= GetTheNumberOfDataLines ()) );
84
87
}
85
88
86
- inline const std::string GetDataLineTitle ( const T_INDEX& dataLineIndex ) const
89
+ inline bool HasDataLine ( const std::string& dataLineId ) const
87
90
{
88
- CheckDataLineIndex (dataLineIndex);
89
-
90
- return Data[dataLineIndex].GetTitle ();
91
+ return Data.hasKey (dataLineId);
91
92
}
92
93
93
- inline void SetDataLineTitle ( const T_INDEX& dataLineIndex, const std::string& newDataLineTitle)
94
+ inline const index_t GetTheNumberOfDataLines ( void ) const
94
95
{
95
- CheckDataLineIndex (dataLineIndex);
96
-
97
- Data[dataLineIndex].SetTitle (newDataLineTitle);
96
+ return Data.size ();
98
97
}
99
98
100
- inline std::string GetDataLineId (const T_INDEX & dataLineIndex) const
99
+ inline const std::string GetDataLineTitle (const index_t & dataLineIndex) const
101
100
{
102
101
CheckDataLineIndex (dataLineIndex);
103
102
104
- return Data[dataLineIndex].GetId ();
103
+ return Data[dataLineIndex].GetTitle ();
105
104
}
106
105
107
- inline void SetDataLineId (const T_INDEX & dataLineIndex, const std::string& newDataLineId )
106
+ inline void SetDataLineTitle (const index_t & dataLineIndex, const std::string& newDataLineTitle )
108
107
{
109
108
CheckDataLineIndex (dataLineIndex);
110
109
111
- Data[dataLineIndex].SetId (newDataLineId);
112
- }
113
-
114
- inline bool GetDataLineIndex (const std::string& dataLineId, T_INDEX& dataLineIndex) const
115
- {
116
- bool result = false ;
117
- dataLineIndex = 0 ;
118
-
119
- for (auto const & dataLine : Data)
120
- {
121
- if (dataLine.GetId () == dataLineId)
122
- {
123
- result = true ;
124
- break ;
125
- }
126
- dataLineIndex++;
127
- }
128
-
129
- return result;
110
+ Data[dataLineIndex].SetTitle (newDataLineTitle);
130
111
}
131
112
132
- void AddNewDataPoint (T_INDEX dataLineIndex, const DataPoint_t& newDataPoint)
113
+ void AddNewDataPoint (const index_t & dataLineIndex, const DataPoint_t& newDataPoint)
133
114
{
134
115
CheckDataLineIndex (dataLineIndex);
135
116
136
117
Data[dataLineIndex].AddNewDataPoint (newDataPoint);
137
118
}
138
119
139
- void AddNewDataPoint (std::string dataLineId, const DataPoint_t& newDataPoint)
120
+ void AddNewDataPoint (const std::string& dataLineId, const DataPoint_t& newDataPoint)
140
121
{
141
- T_INDEX data_line_index = 0 ;
142
-
143
- if (GetDataLineIndex (dataLineId, data_line_index))
144
- {
145
- Data[data_line_index].AddNewDataPoint (newDataPoint);
146
- }
122
+ Data[dataLineId].AddNewDataPoint (newDataPoint);
147
123
}
148
124
149
- inline const T_INDEX GetTheNumberOfDataPoints (const T_INDEX & dataLineIndex) const
125
+ inline const index_t GetTheNumberOfDataPoints (const index_t & dataLineIndex) const
150
126
{
151
127
CheckDataLineIndex (dataLineIndex);
152
128
153
129
return Data[dataLineIndex].GetTheNumberOfDataPoints ();
154
130
}
155
131
156
- inline const DataPoint_t GetDataPoint (const T_INDEX & dataLineIndex, const T_INDEX & dataPointIndex) const
132
+ inline const DataPoint_t GetDataPoint (const index_t & dataLineIndex, const index_t & dataPointIndex) const
157
133
{
158
134
CheckDataLineIndex (dataLineIndex);
159
135
160
136
return Data[dataLineIndex].GetDataPoint (dataPointIndex);
161
137
}
162
138
163
- void SetDataPoint (const T_INDEX & dataLineIndex, const T_INDEX & dataPointIndex, const DataPoint_t& newDataPoint)
139
+ void SetDataPoint (const index_t & dataLineIndex, const index_t & dataPointIndex, const DataPoint_t& newDataPoint)
164
140
{
165
141
CheckDataLineIndex (dataLineIndex);
166
142
167
143
Data[dataLineIndex].SetDataPoint (dataPointIndex, newDataPoint);
168
144
}
169
145
170
- std::pair<DataPoint_t, DataPoint_t> GetExtremeValues (const T_INDEX & dataLineIndex) const
146
+ std::pair<DataPoint_t, DataPoint_t> GetExtremeValues (const index_t & dataLineIndex) const
171
147
{
172
148
CheckDataLineIndex (dataLineIndex);
173
149
@@ -192,10 +168,10 @@ class Diagram {
192
168
193
169
for (const auto & i : Data)
194
170
{
195
- data_points_with_min_x_values.AddNewDataPoint (i.GetDataPointWithMinValue (DataPoint_t::CompareXValues));
196
- data_points_with_max_x_values.AddNewDataPoint (i.GetDataPointWithMaxValue (DataPoint_t::CompareXValues));
197
- data_points_with_min_y_values.AddNewDataPoint (i.GetDataPointWithMinValue (DataPoint_t::CompareYValues));
198
- data_points_with_max_y_values.AddNewDataPoint (i.GetDataPointWithMaxValue (DataPoint_t::CompareYValues));
171
+ data_points_with_min_x_values.AddNewDataPoint (i.second . GetDataPointWithMinValue (DataPoint_t::CompareXValues));
172
+ data_points_with_max_x_values.AddNewDataPoint (i.second . GetDataPointWithMaxValue (DataPoint_t::CompareXValues));
173
+ data_points_with_min_y_values.AddNewDataPoint (i.second . GetDataPointWithMinValue (DataPoint_t::CompareYValues));
174
+ data_points_with_max_y_values.AddNewDataPoint (i.second . GetDataPointWithMaxValue (DataPoint_t::CompareYValues));
199
175
}
200
176
201
177
auto min_x_value = data_points_with_min_x_values.GetDataPointWithMinValue (DataPoint_t::CompareXValues).GetX ();
@@ -222,7 +198,7 @@ class Diagram {
222
198
}
223
199
224
200
private:
225
- void CheckDataLineIndex (const T_INDEX & dataLineIndex) const
201
+ void CheckDataLineIndex (const index_t & dataLineIndex) const
226
202
{
227
203
if (Data.size () <= dataLineIndex)
228
204
{
@@ -236,7 +212,7 @@ class Diagram {
236
212
237
213
std::string DiagramTitle;
238
214
std::string AxisXTitle;
239
- std::vector<DataLine_t> Data;
215
+ DataContainer_t Data;
240
216
};
241
217
242
218
0 commit comments