Application.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2008 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Base/Classes/Pulsar/Application.h
10 
11 #ifndef __Pulsar_Application_h
12 #define __Pulsar_Application_h
13 
14 #include "Pulsar/Processor.h"
15 #include "CommandLine.h"
16 #include "Functor.h"
17 
18 #include <algorithm>
19 
20 namespace Pulsar {
21 
22  class Archive;
23 
25  class Application : public Reference::Able
26  {
27  public:
28 
30  Application (const std::string& name,
31  const std::string& description);
32 
34  virtual int main (int argc, char** argv);
35 
37  class Options;
38 
40  void add (Options*);
41 
43  std::string get_name () const;
44 
46  std::string get_description () const;
47 
49  bool get_verbose () const;
50 
52  virtual bool must_save ();
53 
54  protected:
55 
57  std::vector< Reference::To<Options> > options;
58 
60  virtual void add_options (CommandLine::Menu&) = 0;
61 
63  virtual void parse (int argc, char** argv);
64 
66  virtual void set_quiet ();
67 
69  virtual void set_verbose ();
70 
72  virtual void set_very_verbose ();
73 
75  virtual void setup ();
76 
77  template<typename Compare>
78  void sort_archives (Compare c);
79 
81  virtual void run ();
82 
84  virtual Archive* load (const std::string& filename);
85 
87  virtual void process (Archive*) = 0;
88 
90  virtual bool do_finish () { return true; }
91 
93 
97  virtual Archive* result () { return 0; }
98 
100  virtual void finish (Archive*);
101 
103  virtual void finalize ();
104 
106  bool has_manual;
107 
109  bool update_history;
110 
112  bool stow_script;
113 
114  // name of the application
115  std::string name;
116 
117  // short description of the application
118  std::string description;
119 
120  // revision information
121  std::string version;
122 
123  // command line used to execute this program
124  std::string command;
125 
126  // filename of script
127  std::string script;
128 
129  // list of file names on which to operate
130  std::vector <std::string> filenames;
131 
132  // vector of loaded archives
133  std::vector < Reference::To<Archive> > archives;
134 
135  // name of file containing list of Archive filenames
136  std::string metafile;
137 
138  // verbosity flags
139  bool verbose;
140  bool very_verbose;
141 
142  // sort filenames returned by dirglob
143  bool sort_filenames;
144  };
145 
147  class Application::Options : public Processor
148  {
149  public:
150 
152  virtual void add_options (CommandLine::Menu&) = 0;
153 
155  virtual void setup ();
156 
158  virtual void process (Archive*);
159 
161  virtual void finish (Archive*);
162 
164  virtual void finalize();
165 
166  protected:
167 
168  friend class Application;
169 
172 
173  };
174 
175  template<typename Compare>
176  void Application::sort_archives (Compare compare)
177  {
178  archives.resize( filenames.size() );
179  for (unsigned ifile=0; ifile < filenames.size(); ifile++)
180  archives[ifile] = load (filenames[ifile]);
181 
182  std::sort (archives.begin(), archives.end(), compare);
183  }
184 
185 }
186 
187 #endif
Application with basic command line options.
Definition: Application.h:30
virtual void add_options(CommandLine::Menu &)=0
Add command line options.
virtual void setup()
Additional one-time setup tasks.
Definition: Application.C:264
std::string get_name() const
Get the application name.
Definition: Application.C:45
virtual void finish(Archive *)
Additional per-Archive finishing tasks (e.g., unload)
Definition: Application.C:274
virtual int main(int argc, char **argv)
Execute the main loop.
Definition: Application.C:223
virtual void set_help_footer(const std::string &s)
bool update_history
true if application should update the processing history
Definition: Application.h:114
virtual void parse(int argc, char **argv)
Parse the command line options.
Definition: Application.C:82
virtual void process(Archive *)
Additional per-Archive processing tasks.
Definition: Application.C:269
virtual void set_verbose()
Operate in verbose mode.
Definition: Application.C:67
The primary interface to pulsar observational data.
Definition: Archive.h:45
Application(const std::string &name, const std::string &description)
Construct with the application name and a short description.
Definition: Application.C:21
virtual void set_help_header(const std::string &s)
void add(Options *)
Add options to the application.
Definition: Application.C:38
virtual bool must_save()
Return true if the application needs to save data.
Definition: Application.C:253
Describes application command line options.
Definition: Application.h:152
Type * release()
std::vector< Reference::To< Options > > options
Available options.
Definition: Application.h:62
Type * get() const
virtual void run()
The main loop.
Definition: Application.C:168
virtual void set_quiet()
Operate in quiet mode.
Definition: Application.C:62
virtual void add_options(CommandLine::Menu &)=0
Additional getopt options.
std::string get_description() const
Get the application description.
Definition: Application.C:51
virtual void add(Item *)
virtual void set_version(const std::string &s)
virtual void set_very_verbose()
Operate in very verbose mode.
Definition: Application.C:74
Interface to any object that processes data in an Archive.
Definition: Processor.h:27
virtual void process(Archive *)=0
Data analysis tasks implemented by most derived classes.
virtual Archive * load(const std::string &filename)
Load file.
Definition: Application.C:151
virtual Archive * result()
Return pointer to new result constructed by process method.
Definition: Application.h:102
virtual void finalize()
Any final work after main loop finishes.
Definition: Application.C:259
virtual bool do_finish()
Return true if Options::finish tasks should be run after process.
Definition: Application.h:95
Reference::To< Application, false > application
The application to which these options belong.
Definition: Application.h:176
Defines the PSRCHIVE library.
Definition: CalSource.h:17
bool has_manual
true if application has an online manual
Definition: Application.h:111
virtual void finish(Archive *)
Finishing work performed on each output archive.
Definition: Application.C:205
virtual void finalize()
Additional one-time final tasks.
Definition: Application.C:279
bool get_verbose() const
Get the verbosity flag.
Definition: Application.C:57
virtual void parse(int argc, char *const *argv)
bool stow_script
true if application receives a script name as the first file
Definition: Application.h:117
virtual void setup()
Any extra setup before running main loop.
Definition: Application.C:248

Generated using doxygen 1.8.17