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 
19 namespace Pulsar {
20 
22  class PlotFactory {
23 
24  public:
25 
28 
30  Plot* construct (std::string name);
31 
33  unsigned get_nplot () { return agents.size(); }
34 
36  std::string get_name (unsigned i);
37 
39  std::string get_description (unsigned i);
40 
42  std::string help();
43 
44  protected:
45 
46  class Agent;
47 
48  std::vector<Agent*> agents;
49 
50  public:
51 
52  template<class P> class Advocate;
53 
55  void add (Agent* agent) { agents.push_back(agent); }
56 
57  };
58 
59  class PlotFactory::Agent : public Plot::Constructor
60  {
61  public:
62 
63  Agent (char c, std::string n, std::string d)
64  : shortcut(c), name (n), description (d) {}
65 
67  std::string get_name () { return name; }
68 
70  char get_shortcut () { return shortcut; }
71 
73  std::string get_description () { return description; }
74 
75  protected:
76 
77  char shortcut;
78  std::string name;
79  std::string description;
80 
81  };
82 
83  template<class P> class PlotFactory::Advocate : public Agent
84  {
85  public:
86 
88  Advocate (std::string _name, std::string _description)
89  : Agent (' ', _name, _description) {}
90 
92  Advocate (char shortcut, std::string _name, std::string _description)
93  : Agent (shortcut, _name, _description) {}
94 
96  Plot* construct ()
97  {
98  P* plot = new P;
99  plot->set_constructor(this);
100  return plot;
101  }
102 
103  };
104 
105 }
106 
107 #endif
PlotFactory()
Default constructor loads up all of the plot types.
Definition: PlotFactory.C:51
void add(Agent *agent)
Add a plot.
Definition: PlotFactory.h:65
std::string get_name(unsigned i)
Return the name of the ith plot.
Definition: PlotFactory.C:185
std::string get_description(unsigned i)
Return the name of the ith plot.
Definition: PlotFactory.C:191
Plot * construct(std::string name)
Return a new instance of the named plot.
Definition: PlotFactory.C:169
Defines the PSRCHIVE library.
Definition: CalSource.h:17
unsigned get_nplot()
Return the number of plots.
Definition: PlotFactory.h:43
Base class of all plotters.
Definition: Plot.h:28
std::string help()
Return a descriptive list of the available plots.
Definition: PlotFactory.C:196

Generated using doxygen 1.8.17