File: plotmanager.h

package info (click to toggle)
aoflagger 3.4.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,960 kB
  • sloc: cpp: 83,076; python: 10,187; sh: 260; makefile: 178
file content (52 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef PLOTMANAGER_H
#define PLOTMANAGER_H

#include <functional>
#include <set>
#include <vector>

#include "xyplot.h"

class PlotManager {
 public:
  ~PlotManager() { clear(); }
  XYPlot& NewPlot2D(const std::string& plotTitle) {
    std::string title = plotTitle;
    if (_plotTitles.find(title) != _plotTitles.end()) {
      char addChar = 'B';
      std::string tryTitle;
      do {
        tryTitle = title + " (" + addChar + ')';
        ++addChar;
      } while (_plotTitles.find(tryTitle) != _plotTitles.end() &&
               addChar <= 'Z');
      if (addChar > 'Z') tryTitle = title + " (..)";
      title = tryTitle;
    }
    std::unique_ptr<XYPlot> plot(new XYPlot());
    plot->SetTitle(title);
    _plotTitles.insert(title);
    _items.push_back(std::move(plot));
    return *_items.back();
  }

  void Update() { _onUpdate(); }

  std::function<void()>& OnUpdate() { return _onUpdate; }

  const std::vector<std::unique_ptr<XYPlot>>& Items() const { return _items; }

  void Clear() {
    clear();
    Update();
  }

 private:
  void clear() { _items.clear(); }
  std::vector<std::unique_ptr<XYPlot>> _items;
  std::set<std::string> _plotTitles;

  std::function<void()> _onUpdate;
};

#endif