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
20namespace Pulsar {
21
22 class Archive;
23
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&) { }
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
107
110
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 // set the commit hash compiled into application
146 void set_commit_hash (const std::string& hash) { commit_hash = hash; }
147
148 private:
149
150 // commit hash compiled into application
151 std::string commit_hash;
152
153 // verify that commit hash compiled into application equals that compiled into library
154 void verify_commit_hash ();
155 };
156
159 {
160 public:
161
163 virtual void add_options (CommandLine::Menu&) = 0;
164
166 virtual void setup ();
167
169 virtual void process (Archive*);
170
172 virtual void finish (Archive*);
173
175 virtual void finalize();
176
177 protected:
178
179 friend class Application;
180
183
184 };
185
186 template<typename Compare>
187 void Application::sort_archives (Compare compare)
188 {
189 archives.resize( filenames.size() );
190 for (unsigned ifile=0; ifile < filenames.size(); ifile++)
191 archives[ifile] = load (filenames[ifile]);
192
193 std::sort (archives.begin(), archives.end(), compare);
194 }
195
196}
197
198#endif
Describes application command line options.
Definition Application.h:159
virtual void finish(Archive *)
Additional per-Archive finishing tasks (e.g., unload)
Definition Application.C:322
virtual void process(Archive *)
Additional per-Archive processing tasks.
Definition Application.C:317
virtual void add_options(CommandLine::Menu &)=0
Additional getopt options.
Reference::To< Application, false > application
The application to which these options belong.
Definition Application.h:182
virtual void setup()
Additional one-time setup tasks.
Definition Application.C:312
virtual void finalize()
Additional one-time final tasks.
Definition Application.C:327
virtual void set_verbose()
Operate in verbose mode.
Definition Application.C:72
virtual void parse(int argc, char **argv)
Parse the command line options.
Definition Application.C:87
virtual void setup()
Any extra setup before running main loop.
Definition Application.C:296
virtual void finish(Archive *)
Finishing work performed on each output archive.
Definition Application.C:238
bool get_verbose() const
Get the verbosity flag.
Definition Application.C:62
virtual void add_options(CommandLine::Menu &)
Add command line options.
Definition Application.h:60
virtual void set_very_verbose()
Operate in very verbose mode.
Definition Application.C:79
virtual void set_quiet()
Operate in quiet mode.
Definition Application.C:67
Application(const std::string &name, const std::string &description)
Construct with the application name and a short description.
Definition Application.C:26
virtual void run()
The main loop.
Definition Application.C:201
virtual bool must_save()
Return true if the application needs to save data.
Definition Application.C:301
virtual int main(int argc, char **argv)
Execute the main loop.
Definition Application.C:269
virtual Archive * load(const std::string &filename)
Load file.
Definition Application.C:184
virtual Archive * result()
Return pointer to new result constructed by process method.
Definition Application.h:97
bool stow_script
true if application receives a script name as the first file
Definition Application.h:112
bool has_manual
true if application has an online manual
Definition Application.h:106
std::string get_name() const
Get the application name.
Definition Application.C:50
void add(Options *)
Add options to the application.
Definition Application.C:43
std::string get_description() const
Get the application description.
Definition Application.C:56
std::vector< Reference::To< Options > > options
Available options.
Definition Application.h:57
virtual bool do_finish()
Return true if Options::finish tasks should be run after process.
Definition Application.h:90
virtual void finalize()
Any final work after main loop finishes.
Definition Application.C:307
bool update_history
true if application should update the processing history
Definition Application.h:109
virtual void process(Archive *)=0
Data analysis tasks implemented by most derived classes.
The primary interface to pulsar observational data.
Definition Archive.h:46
Interface to any object that processes data in an Archive.
Definition Processor.h:23
Defines the PSRCHIVE library.
Definition CalSource.h:17

Generated using doxygen 1.14.0