TextInterfaceParser.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2003-2013 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/psrchive/Util/units/TextInterfaceParser.h
10
11#ifndef __TextInterfaceParser_h
12#define __TextInterfaceParser_h
13
14#include "TextInterfaceValue.h"
15
16#include "Alias.h"
17#include "Error.h"
18#include "tostring.h"
19
20// #define _DEBUG 1
21
22#ifdef _DEBUG
23#include <iostream>
24#endif
25
26namespace TextInterface
27{
28
30 class Parser : public Reference::Able
31 {
32
33 public:
34
36 Parser ();
37
39 ~Parser ();
40
42 std::string get_value (const std::string& name) const;
43
45 std::string get_name_value (std::string& name) const;
46
48 void set_value (const std::string& name, const std::string& value);
49
51 Value* find (const std::string& name, bool throw_exception = true) const;
52
54 bool found (const std::string& name) const;
55
57 bool found (const std::string& prefix, const std::string& name) const;
58
60 virtual void setup (const Value*) { }
61
63 unsigned get_nvalue () const;
64
66 std::string get_name (unsigned) const;
67
69 std::string get_value (unsigned) const;
70
72 std::string get_description (unsigned) const;
73
75 virtual std::string process (const std::string& command);
76
78 virtual std::string process (const std::vector<std::string>& commands);
79
81 virtual std::string help (bool show_default_values = false,
82 bool show_header = false,
83 const char* indent = 0);
84
86 virtual std::string get_interface_name () const { return ""; }
87
89 virtual std::string get_interface_description () const { return ""; }
90
92 void set_indentation (const std::string& indent) { indentation = indent; }
93 std::string get_indentation () const { return indentation; }
94
96 void set_delimiter (const std::string&);
97 std::string get_delimiter () const { return delimiter; }
98
100 void set_prefix_name (bool flag) { prefix_name = flag; }
101
103 void set_aliases (const Alias* alias) { aliases = alias; }
104
106
107 void insert (Parser*);
108
110
111 void insert (const std::string& prefix, Parser*);
112
114 void clean ();
115
116 protected:
117
119 std::string indentation;
120
122 std::string delimiter;
123
126
129
132
135
137 void add_value (Value* value);
138
140 void remove (const std::string& name);
141
143 void clean_invalid ();
144
146 std::vector< Reference::To<Value> > values;
147
149 std::vector< Reference::To<Parser> > inserted;
150 };
151
153 bool matches (const std::string& name,
154 const std::string& prefix, const Value* value);
155
156}
157
158#endif
Stores keyword-value pairs.
Definition Alias.h:22
Manages Reference::To references to the instance.
Definition ReferenceAble.h:35
Template class manages Reference::Able objects.
Definition ReferenceTo.h:25
An array of Value interfaces.
Definition TextInterfaceParser.h:31
virtual void setup(const Value *)
Allow derived types to setup a Value instance before use.
Definition TextInterfaceParser.h:60
Value * find(const std::string &name, bool throw_exception=true) const
Find the named value.
Definition TextInterfaceParser.C:307
void clean()
Clear all nested interfaces.
Definition TextInterfaceParser.C:372
~Parser()
Destructor.
Definition TextInterfaceParser.C:215
bool prefix_name
Prefix "name=" when retrieving a value.
Definition TextInterfaceParser.h:131
std::string get_name(unsigned) const
Get the name of the value.
Definition TextInterfaceParser.C:271
std::string get_name_value(std::string &name) const
Get the named value and update name for display purposes.
Definition TextInterfaceParser.C:229
Reference::To< const Alias > aliases
The aliases for the value names.
Definition TextInterfaceParser.h:134
void insert(Parser *)
Insert Parser into self.
Definition TextInterfaceParser.C:334
virtual std::string get_interface_description() const
Get a short description of this interface.
Definition TextInterfaceParser.h:89
std::vector< Reference::To< Value > > values
The vector of values.
Definition TextInterfaceParser.h:146
bool alphabetical
Maintain alphabetical order of parameter names.
Definition TextInterfaceParser.h:125
bool import_filter
Filter duplicate value names during import.
Definition TextInterfaceParser.h:128
unsigned get_nvalue() const
Get the number of values.
Definition TextInterfaceParser.C:265
virtual std::string get_interface_name() const
Get the name of this interface.
Definition TextInterfaceParser.h:86
void set_aliases(const Alias *alias)
Set aliases for value names.
Definition TextInterfaceParser.h:103
void set_prefix_name(bool flag)
Prefix output with "name=".
Definition TextInterfaceParser.h:100
void set_value(const std::string &name, const std::string &value)
Set the named value.
Definition TextInterfaceParser.C:259
std::string indentation
The indentation that precedes the output of a call to process.
Definition TextInterfaceParser.h:119
std::string get_description(unsigned) const
Get the description of the value.
Definition TextInterfaceParser.C:284
void add_value(Value *value)
Add a new value interface.
Definition TextInterfaceParser.C:172
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:106
std::vector< Reference::To< Parser > > inserted
Any inserted Parser is owned by this.
Definition TextInterfaceParser.h:149
std::string get_value(const std::string &name) const
Get the named value.
Definition TextInterfaceParser.C:222
void set_indentation(const std::string &indent)
Set the indentation that precedes the output of a call to process.
Definition TextInterfaceParser.h:92
virtual std::string process(const std::string &command)
Process a command.
Definition TextInterfaceParser.C:41
void clean_invalid()
Clean up invalid references in values vector.
Definition TextInterfaceParser.C:193
std::string delimiter
The delimiter used to separate the elements of a container.
Definition TextInterfaceParser.h:122
Parser()
Default constructor.
Definition TextInterfaceParser.C:205
void set_delimiter(const std::string &)
Set the delimiter used to separate the elements of a container.
Definition TextInterfaceParser.C:24
void remove(const std::string &name)
Remove the named value interface.
Definition TextInterfaceParser.C:185
bool found(const std::string &name) const
Return true if the named value is found.
Definition TextInterfaceParser.C:290
Text interface to a value of undefined type.
Definition TextInterfaceValue.h:31

Generated using doxygen 1.14.0