utils.cpp
Go to the documentation of this file.
1 #include "utils.h"
2 
3 /*
4 std::vector<double> BuiltTimepointsList(PlotDataMapRef &data)
5 {
6  {
7  std::vector<size_t> index_num( data.numeric.size(), 0);
8 
9  std::vector<double> out;
10 
11  bool loop = true;
12 
13  const double MAX = std::numeric_limits<double>::max();
14 
15  while(loop)
16  {
17  double min_time = MAX;
18  double prev_time = out.empty() ? -MAX : out.back();
19  loop = false;
20  size_t count = 0;
21  for(const auto& it: data.numeric)
22  {
23  const auto& plot = it.second;
24  out.reserve(plot.size());
25 
26  size_t index = index_num[count];
27 
28  while ( index < plot.size() && plot.at(index).x <= prev_time )
29  {
30  index++;
31  }
32  if( index >= plot.size() )
33  {
34  count++;
35  continue;
36  }
37  else{
38  loop = true;
39  }
40  index_num[count] = index;
41  double time_val = plot.at(index).x;
42  min_time = std::min( min_time, time_val);
43  count++;
44  }
45  if( min_time < MAX)
46  {
47  out.push_back( min_time );
48  }
49  }
50  return out;
51  }
52 }
53 */
54 
55 std::pair<std::vector<QString>, bool> MoveData(PlotDataMapRef &source, PlotDataMapRef &destination)
56 {
57  bool destination_updated = false;
58 
59  std::vector<QString> added_curves;
60  for (auto& it : source.numeric)
61  {
62  const std::string& name = it.first;
63  if (it.second.size() > 0 && destination.numeric.count(name) == 0)
64  {
65  added_curves.push_back(QString::fromStdString(name));
66  }
67  }
68 
69  for (auto& it : source.numeric)
70  {
71  const std::string& name = it.first;
72  auto& source_plot = it.second;
73  auto plot_with_same_name = destination.numeric.find(name);
74 
75  // this is a new plot
76  if (plot_with_same_name == destination.numeric.end())
77  {
78  plot_with_same_name =
79  destination.numeric
80  .emplace(std::piecewise_construct, std::forward_as_tuple(name), std::forward_as_tuple(name))
81  .first;
82  }
83  auto& destination_plot = plot_with_same_name->second;
84  for (size_t i = 0; i < source_plot.size(); i++)
85  {
86  destination_plot.pushBack(source_plot.at(i));
87  destination_updated = true;
88  }
89  source_plot.clear();
90  }
91 
92  for (auto& it : source.user_defined)
93  {
94  const std::string& name = it.first;
95  auto& source_plot = it.second;
96  auto plot_with_same_name = destination.user_defined.find(name);
97 
98  // this is a new plot
99  if (plot_with_same_name == destination.user_defined.end())
100  {
101  plot_with_same_name =
102  destination.user_defined
103  .emplace(std::piecewise_construct, std::forward_as_tuple(name), std::forward_as_tuple(name))
104  .first;
105  }
106  auto& destination_plot = plot_with_same_name->second;
107  for (size_t i = 0; i < source_plot.size(); i++)
108  {
109  destination_plot.pushBack( std::move(source_plot.at(i)) );
110  destination_updated = true;
111  }
112  source_plot.clear();
113  }
114  return { added_curves, destination_updated };
115 }
std::unordered_map< std::string, PlotData > numeric
Definition: plotdata.h:495
const char * name
const T & move(const T &v)
Definition: backward.hpp:394
std::pair< std::vector< QString >, bool > MoveData(PlotDataMapRef &source, PlotDataMapRef &destination)
Definition: utils.cpp:55
std::unordered_map< std::string, PlotDataAny > user_defined
Definition: plotdata.h:496


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 04:02:48