stringseries.h
Go to the documentation of this file.
1 /*
2  * This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
5  */
6 
7 #ifndef PJ_STRINGSERIES_H
8 #define PJ_STRINGSERIES_H
9 
10 #include "PlotJuggler/timeseries.h"
12 #include <algorithm>
13 #include <unordered_set>
14 
15 namespace PJ
16 {
17 class StringSeries : public TimeseriesBase<StringRef>
18 {
19 public:
21 
22  StringSeries(const std::string& name, PlotGroup::Ptr group)
24  {
25  }
26 
27  StringSeries(const StringSeries& other) = delete;
28  StringSeries(StringSeries&& other) = default;
29 
30  StringSeries& operator=(const StringSeries& other) = delete;
31  StringSeries& operator=(StringSeries&& other) = default;
32 
33  virtual void clear() override
34  {
35  _storage.clear();
37  }
38 
39  void pushBack(const Point& p) override
40  {
41  auto temp = p;
42  pushBack(std::move(temp));
43  }
44 
45  virtual void pushBack(Point&& p) override
46  {
47  const auto& str = p.y;
48  // do not add empty strings
49  if (str.data() == nullptr || str.size() == 0)
50  {
51  return;
52  }
53  if (str.isSSO())
54  {
55  // the object stroed the string already, just push it
57  }
58  else
59  {
60  // save a copy of the string in the flywheel structure _storage
61  // create a reference to that cached value.
62  _tmp_str.assign(str.data(), str.size());
63 
64  auto it = _storage.find(_tmp_str);
65  if (it == _storage.end())
66  {
67  it = _storage.insert(_tmp_str).first;
68  }
70  }
71  }
72 
73 private:
74  std::string _tmp_str;
75  std::unordered_set<std::string> _storage;
76 };
77 
78 } // namespace PJ
79 
80 #endif
PJ::TimeseriesBase
Definition: timeseries.h:16
PJ::StringSeries::pushBack
void pushBack(const Point &p) override
Definition: stringseries.h:39
PJ::StringSeries::_storage
std::unordered_set< std::string > _storage
Definition: stringseries.h:75
PJ::TimeseriesBase::pushBack
void pushBack(const Point &p) override
Definition: timeseries.h:61
timeseries.h
PJ::StringSeries::pushBack
virtual void pushBack(Point &&p) override
Definition: stringseries.h:45
PJ::StringRef
Super simple, unmutable, string_view with small string optimization. If the string is 15 bytes or les...
Definition: string_ref_sso.h:21
PJ::PlotDataBase< double, StringRef >::group
const PlotGroup::Ptr & group() const
Definition: plotdatabase.h:173
PJ::PlotDataBase< double, Value >::clear
virtual void clear()
Definition: plotdatabase.h:213
PJ::PlotGroup::Ptr
std::shared_ptr< PlotGroup > Ptr
Definition: plotdatabase.h:83
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:394
PJ::TimeseriesBase< StringRef >::Point
typename PlotDataBase< double, StringRef >::Point Point
Definition: timeseries.h:23
PJ::StringSeries::StringSeries
StringSeries(const std::string &name, PlotGroup::Ptr group)
Definition: stringseries.h:22
PJ::StringSeries::clear
virtual void clear() override
Definition: stringseries.h:33
PJ
Definition: dataloader_base.h:16
PJ::StringSeries::_tmp_str
std::string _tmp_str
Definition: stringseries.h:74
string_ref_sso.h
PJ::StringSeries::operator=
StringSeries & operator=(const StringSeries &other)=delete
PJ::StringSeries
Definition: stringseries.h:17


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:47