PlotFactory.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2006-2010 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/More/Plotting/Pulsar/PlotFactory.h
10
11#ifndef __Pulsar_PlotFactory_h
12#define __Pulsar_PlotFactory_h
13
14#include "Pulsar/Plot.h"
15
16#include <string>
17#include <vector>
18
19namespace Pulsar {
20
23
24 public:
25
27 PlotFactory ();
28
30 ~PlotFactory ();
31
33 Plot* construct (std::string name);
34
36 unsigned get_nplot () { return agents.size(); }
37
39 std::string get_name (unsigned i);
40
42 std::string get_description (unsigned i);
43
45 std::string help();
46
47 protected:
48
49 class Agent;
50
51 std::vector<Reference::To<Agent>> agents;
52
53 public:
54
55 template<class P> class Advocate;
56
58 void add (Agent* agent) { agents.push_back(agent); }
59
60 };
61
62 class PlotFactory::Agent : public Plot::Constructor
63 {
64 public:
65
66 Agent (char c, std::string n, std::string d)
67 : shortcut(c), name (n), description (d) {}
68
70 std::string get_name () { return name; }
71
73 char get_shortcut () { return shortcut; }
74
76 std::string get_description () { return description; }
77
78 protected:
79
80 char shortcut;
81 std::string name;
82 std::string description;
83
84 };
85
86 template<class P> class PlotFactory::Advocate : public Agent
87 {
88 public:
89
91 Advocate (std::string _name, std::string _description)
92 : Agent (' ', _name, _description) {}
93
95 Advocate (char shortcut, std::string _name, std::string _description)
96 : Agent (shortcut, _name, _description) {}
97
99 Plot* construct ()
100 {
101 P* plot = new P;
102 plot->set_constructor(this);
103 return plot;
104 }
105
106 };
107
108}
109
110#endif
PlotFactory()
Default constructor loads up all of the plot types.
Definition PlotFactory.C:51
Definition Plot.h:90
~PlotFactory()
Destructor.
Definition PlotFactory.C:168
unsigned get_nplot()
Return the number of plots.
Definition PlotFactory.h:36
void add(Agent *agent)
Add a plot.
Definition PlotFactory.h:58
PlotFactory()
Default constructor loads up all of the plot types.
Definition PlotFactory.C:51
Plot * construct(std::string name)
Return a new instance of the named plot.
Definition PlotFactory.C:175
std::string help()
Return a descriptive list of the available plots.
Definition PlotFactory.C:202
std::string get_name(unsigned i)
Return the name of the ith plot.
Definition PlotFactory.C:191
std::string get_description(unsigned i)
Return the name of the ith plot.
Definition PlotFactory.C:197
virtual Plot * construct()=0
Return a new default constructed instance of a derived type.
Base class of all plotters.
Definition Plot.h:23
Defines the PSRCHIVE library.
Definition CalSource.h:17

Generated using doxygen 1.14.0