TextEditor.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2011 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/Util/units/TextEditor.h
10 
11 #ifndef __TextEditor_h
12 #define __TextEditor_h
13 
14 #include "TextInterface.h"
15 #include "strutil.h"
16 
18 template<class T>
20 {
21 
22  public:
23 
24  TextEditor ()
25  {
26  prefix_name = true;
27  output_identifier = true;
28  }
29 
31  void add_commands (const std::string& str)
32  { standard_separation (commands, str); }
33 
34  void add_script (const std::string& filename)
35  { loadlines (filename, commands); }
36 
38  void add_extensions (const std::string& str)
39  { standard_separation (extensions_to_add, str); }
40 
42  void remove_extensions (const std::string& str)
43  { standard_separation (extensions_to_remove, str); }
44 
46  bool will_modify () const;
47 
49  std::string process (T*);
50 
52  virtual void add_extension (T*, const std::string& name) { }
53 
55  virtual void remove_extension (T*, const std::string& name) { }
56 
58  virtual std::string get_identifier (const T*) { return std::string(); }
59 
61  bool prefix_name;
62 
64  bool output_identifier;
65 
67  std::string delimiter;
68 
69  protected:
70 
72  std::vector<std::string> commands;
73 
75  std::vector<std::string> extensions_to_add;
76 
78  std::vector<std::string> extensions_to_remove;
79 
80 };
81 
82 template <typename T>
84 {
85  if (extensions_to_add.size() > 0 &&
86  extensions_to_add[0] != "help")
87  return true;
88 
89  if (extensions_to_remove.size() > 0)
90  return true;
91 
92  for (unsigned j = 0; j < commands.size(); j++)
93  if (commands[j].find('=') != std::string::npos &&
94  commands[j].find("help") == std::string::npos)
95  return true;
96 
97  return false;
98 }
99 
100 template <typename T>
101 std::string TextEditor<T>::process (T* instance)
102 {
103  for (unsigned i = 0; i < extensions_to_add.size(); i++)
104  add_extension (instance, extensions_to_add[i]);
105 
106  for (unsigned i = 0; i < extensions_to_remove.size(); i++)
107  remove_extension (instance, extensions_to_remove[i]);
108 
109  std::string result;
110 
111  if (will_modify() && commands.size() == 0)
112  return result;
113 
114  Reference::To<TextInterface::Parser> interface = instance->get_interface();
115 
116  if (commands.size() == 0)
117  return interface->help (true);
118 
119  // so that a space precedes each parameter processed
120  interface->set_indentation (" ");
121  interface->set_prefix_name (prefix_name);
122 
123  if (delimiter.length())
124  interface->set_delimiter (delimiter);
125 
126  if (output_identifier)
127  result = get_identifier (instance);
128 
129  for (unsigned j = 0; j < commands.size(); j++)
130  result += interface->process (commands[j]);
131 
132  return result;
133 }
134 
135 #endif
@ Pulsar
A pulsar.
Definition: Types.h:63
A list of strings indexed by another string.
Definition: LogFile.h:18
Enter a Child with default constructor into Registry::List<Parent>
Definition: Registry.h:81
void add_data(double x, Estimate< double > y)
Add a data point.
Definition: SplineFit.C:68
Modifies a value on construction and restores it on destruction.
Definition: ModifyRestore.h:16
bool prefix_name
Prefix parameter value queries with parameter name=.
Definition: TextEditor.h:66
bool will_modify() const
Return true if the process method will modify the archive.
Definition: TextEditor.h:83
std::string get_name() const
Get the observatory name.
Definition: Observatory.C:48
virtual void set_time_span(const MJD &start, const MJD &finish)=0
Set the range of epochs over which to generate.
void add(const std::string &index, const std::string &message)
add a log message
Definition: LogFile.C:39
void frc1d(size_t nfft, float *into, const float *from)
Forward real-to-complex FFT.
Definition: FTransform.C:39
void set_value(const std::string &value)
Set the value of the attribute.
Definition: TextInterfaceAttribute.h:46
Estimate< T, U > get_intercept() const
Return the intercept, a.
Definition: StraightLine.h:46
Pulsar::Predictor * generate() const
Return a new Predictor instance.
Definition: T2Generator.C:168
void clean_plans()
Clears out the memory associated with the plans.
Definition: FTransform.C:130
std::string get_name(unsigned) const
Get the name of the value.
Definition: TextInterfaceParser.C:268
void add_coordinate(double x, const Estimate< T, U > &d)
Addition operator.
Definition: StraightLine.h:34
static bool verbose
During constructor, print messages.
Definition: Error.h:62
void bcr1d(size_t nfft, float *into, const float *from)
Backward complex-to-real FFT.
Definition: FTransform.C:45
std::string get_message(const std::string &index)
get a log message
Definition: LogFile.C:50
A convenient exception handling class.
Definition: Error.h:54
std::string get_value(const std::string &name) const
Get the named value.
Definition: TextInterfaceParser.C:223
void set_value(const std::string &name, const std::string &value)
Set the named value.
Definition: TextInterfaceParser.C:256
Estimate< T, U > get_slope() const
Return the slope, b.
Definition: StraightLine.h:55
void set_time_span(const MJD &start, const MJD &finish)
Set the range of epochs over which to generate.
Definition: T2Generator.C:127
std::vector< std::string > extensions_to_remove
extensions to be removed
Definition: TextEditor.h:83
static Generator * factory(const Parameters *)
Return a pointer to a new Generator that can best handle the parameters.
Definition: Generator_factory.C:63
Quaternion.
Definition: Quaternion.h:29
virtual void set_instance(C *c)
Set the instance.
Definition: TextInterfaceTo.h:44
T val
The value, .
Definition: Estimate.h:42
Manages a unique std::ostream for each thread.
Definition: ThreadStream.h:25
A range of values with a Phase::Unit.
Definition: PhaseRange.h:83
For use in the efficient computation of a running median.
Definition: RunningMedian.h:39
double evaluate(double x)
Evaluate the fit solution at the given x.
Definition: SplineFit.C:89
void compute()
Compute the fit using current data.
Definition: SplineFit.C:198
U get_error() const
const Observatory * observatory(const std::string &telescope_name)
Return the Observatory data given the telescope name.
Definition: Observatory.C:130
void add(const std::string &alias, const std::string &name)
Add an alias.
Definition: Alias.C:11
Type * release()
Return the pointer and unhook without deleting the object.
Definition: ReferenceTo.h:218
virtual void remove_extension(T *, const std::string &name)
Remove the named extension from the instance.
Definition: TextEditor.h:60
Parent * create(unsigned i) const
Return pointer to a null-constructed instance of Parent class.
Definition: Registry.h:96
Type * get() const
Return the pointer.
Definition: ReferenceTo.h:206
virtual void get_sph(double &lat, double &lon, double &rad) const =0
Get the latitude and longitude in radians, and radius in metres.
virtual void unload(FILE *) const =0
Unload to an open stream.
U var
The variance of the value, .
Definition: Estimate.h:44
Matrix is a column vector of row vectors.
Definition: Matrix.h:20
void import(const To< P > *parent)
Import the attribute interfaces from a parent text interface.
Definition: TextInterfaceTo.h:79
AnglePair class : useful for sky positions.
Definition: Angle.h:165
void remove_extensions(const std::string &str)
Add a semi-colon or comma-separated list of extensions to remove.
Definition: TextEditor.h:47
Template class manages Reference::Able objects.
Definition: Reference.h:74
virtual void set_site(const std::string &)=0
Set the site at which the signal is observed.
virtual void set_value(const std::string &value)=0
Set the value as text.
Virtual memory manager.
Definition: VirtualMemory.h:21
Linear least squares fit to a straight line.
Definition: StraightLine.h:21
An N-dimensional array of elements of type T, defined recursively.
Definition: ndArray.h:21
void unload(FILE *) const
Unload to an open stream.
Definition: T2Predictor.C:351
A set of ranges of values with a common Phase::Unit.
Definition: PhaseRange.h:103
Text interface to a value of undefined type.
Definition: TextInterfaceValue.h:35
static bool verbose
Verbosity flag.
Definition: Parameters.h:38
Observatory data available from TEMPO.
Definition: Observatory.h:25
static List & get_registry()
provide access to the single registry instance
Definition: Registry.h:102
Edit the metadata in a pulsar archive.
Definition: TextEditor.h:19
Stores pulsar parameters as uninterpreted text.
Definition: TextParameters.h:24
unsigned size() const
Return the size of the list.
Definition: Registry.h:87
Generator of functions that predict pulse phase.
Definition: Generator.h:31
void load(FILE *)
Load from an open stream.
Definition: polyco.C:728
Manages Reference::To references to the instance.
Definition: ReferenceAble.h:40
std::string get_value() const
Get the value of the attribute.
Definition: TextInterfaceAttribute.h:42
void add_commands(const std::string &str)
Add a semi-colon or comma-separated list of commands to execute.
Definition: TextEditor.h:36
std::string get_itoa_code() const
Get the two-letter ITOA code.
Definition: Observatory.C:34
A value with a Phase::Unit.
Definition: PhaseRange.h:60
Opens a temporary file with a unique name and deletes it when finished.
Definition: TemporaryFile.h:20
Stores keyword-value pairs.
Definition: Alias.h:21
double density(double x)
Get the value of the probability density at x.
Definition: NormalDistribution.C:14
Functions that predict pulse phase.
Definition: T2Predictor.h:31
unsigned get_nvalue() const
Get the number of values.
Definition: TextInterfaceParser.C:262
T get_value() const
std::vector< std::string > extensions_to_add
extensions to be added
Definition: TextEditor.h:80
virtual std::string get_identifier(const T *)
Get the identifier for this instance.
Definition: TextEditor.h:63
void set_parameters(const Pulsar::Parameters *)
Set the parameters used to generate the predictor.
Definition: T2Generator.C:92
virtual double moment2(double x1, double x2)
Get the second moment of the distribution averaged from x1 to x2.
Definition: Probability.C:20
void set_period(double P_ms)
Set the period in milliseconds.
Definition: PhaseRange.h:56
virtual void set_parameters(const Parameters *)=0
Set the parameters used to generate the predictor.
Handles warning messages in a standardized fashion.
Definition: Warning.h:34
void add_extensions(const std::string &str)
Add a semi-colon or comma-separated list of extensions to install.
Definition: TextEditor.h:43
void set_frequency_span(long double low, long double high)
Set the range of frequencies over which to generate.
Definition: T2Generator.C:134
Implements an adaptable function object in compliance with the STL.
Definition: Functor.h:39
static bool abort
Abort after processing any signals.
Definition: TemporaryFile.h:31
Base class of probability density functions.
Definition: NormalDistribution.h:17
double get_scale(size_t nfft, type t)
Returns the scale factor associated with the FFT operation.
Definition: FTransform.C:109
const Type * ptr() const
Return pointer without testing for validity.
Definition: ReferenceTo.h:234
Functions that predict pulse phase.
Definition: Predictor.h:33
static bool verbose
Verbosity flag.
Definition: Predictor.h:52
AttributeGet and AttributeGetSet factory.
Definition: TextInterfaceAttribute.h:285
virtual void set_frequency_span(long double low, long double high)=0
Set the range of frequencies over which to generate.
Returns a random variable from a normal distribution.
Definition: BoxMuller.h:15
std::vector< std::string > commands
commands to be executed
Definition: TextEditor.h:77
bool output_identifier
Print the name of each file processed.
Definition: TextEditor.h:69
void bcc1d(size_t nfft, float *into, const float *from)
Backward complex-to-complex FFT.
Definition: FTransform.C:57
const std::string get_message() const
Get the error message.
Definition: Error.C:133
Interface to regex.
Definition: RegularExpression.h:17
Class for sky coordinates.
Definition: sky_coord.h:19
virtual std::string help(bool show_default_values=false, bool show_header=false, const char *indent=0)
Return the list of available values.
Definition: TextInterfaceParser.C:99
Spline fitting for smoothing and/or interpolation, using GSL's bspline routines.
Definition: SplineFit.h:20
Generates a Tempo2::Predictor.
Definition: T2Generator.h:26
virtual Predictor * generate() const =0
Return a new Predictor instance.
char get_code() const
Get the one-letter tempo code.
Definition: Observatory.C:24
void set_uniform_breaks(int nint)
Set uniform breakpoints to span the data.
Definition: SplineFit.C:75
Class for representing modified Julian dates with high precision.
Definition: MJD.h:27
Text interface to a class attribute.
Definition: TextInterfaceAttribute.h:27
Implements Predictor class for Tempo.
Definition: polyco.h:202
direction
The FFT direction.
Definition: FTransform.h:73
Parses and manages a named set of indeces.
Definition: TextIndex.h:17
Storage of pulsar parameters used to create a Predictor.
Definition: Parameters.h:28
std::string process(T *)
Edit the Archive according to the current state.
Definition: TextEditor.h:101
Class text interface: an instance of C and a vector of Attribute<C>
Definition: TextInterfaceTo.h:30
void fcc1d(size_t nfft, float *into, const float *from)
Forward complex-to-complex FFT.
Definition: FTransform.C:51
virtual Phase phase(const MJD &t) const =0
Return the phase, given the epoch.
virtual void add_extension(T *, const std::string &name)
Add the named extension to the instance.
Definition: TextEditor.h:57
Pulsar::Phase phase(const MJD &t) const
Return the phase, given the epoch.
Definition: polyco.h:248
normalization get_norm()
Returns the normalization convention of the currently selected library.
Definition: FTransform.C:102
double cumulative_distribution(double x)
Get the value of the distribution function at x.
Definition: NormalDistribution.C:20
std::string delimiter
Optionally set the delimiter used to separate elements of a container.
Definition: TextEditor.h:72
void set(std::ostream *)
Set the ostream for the current thread.
Definition: ThreadStream.C:54
void load(FILE *)
Load from an open stream.
Definition: T2Predictor.C:335
Defines a single interface to a variety of Fourier transform libraries.
Definition: FFTW3_Transform.h:14

Generated using doxygen 1.8.17