TextInterfaceInterpreter.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2013 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/Util/units/TextInterfaceInterpreter.h
10
11#ifndef __TextInterfaceInterpreter_h
12#define __TextInterfaceInterpreter_h
13
14#include "TextInterface.h"
15
16namespace TextInterface {
17
19
22 template<class I, class Get, class Set>
23 class Interpreter : public Value {
24
25 public:
26
28 Interpreter (const std::string& _name, I* ptr, Get _get, Set _set)
29 { name = _name, interpreter = ptr, get = _get; set = _set; }
30
32 std::string get_name () const
33 { return name; }
34
36 std::string get_value () const
37 { return (interpreter->*get)(); }
38
40 void set_value (const std::string& text)
41 { (interpreter->*set)(text); }
42
44 std::string get_description () const
45 { return description; }
46
48 void set_description (const std::string& text)
49 { description = text; }
50
52 std::string get_detailed_description () const
53 { return detailed_description; }
54
56 void set_detailed_description (const std::string& text)
57 { detailed_description = text; }
58
59 void set_modifiers (const std::string& modifiers) const
60 {
61 tostring_precision = fromstring<unsigned> (modifiers);
62 }
63
64 void reset_modifiers () const
65 {
66 tostring_precision = 0;
67 }
68
69 protected:
70
71 std::string name;
72 std::string description;
73 std::string detailed_description;
74 Reference::To<I> interpreter;
75 Get get;
76 Set set;
77
78 };
79
80 template<class I, class Get, class Set>
81 Interpreter<I,Get,Set>*
82 new_Interpreter (const std::string& n, I* i, Get g, Set s)
83 {
84 return new Interpreter<I,Get,Set> (n, i, g, s);
85 }
86
87 template<class I, class Get, class Set>
89 new_Interpreter (const std::string& n, const std::string& d,
90 I* i, Get g, Set s)
91 {
92 Interpreter<I,Get,Set>* result = new Interpreter<I,Get,Set> (n, i, g, s);
93 result->set_description (d);
94 return result;
95 }
96
97 template<class I, class Get, class Set>
99 new_Interpreter (const std::string& n, const std::string& d,
100 const std::string& dd,
101 I* i, Get g, Set s)
102 {
103 Interpreter<I,Get,Set>* result = new Interpreter<I,Get,Set> (n, i, g, s);
104 result->set_description (d);
105 result->set_detailed_description (dd);
106 return result;
107 }
108
109}
110
111#endif
Template class manages Reference::Able objects.
Definition ReferenceTo.h:25
Text interface to a text interpreter.
Definition TextInterfaceInterpreter.h:23
std::string get_name() const
Get the name of the value.
Definition TextInterfaceInterpreter.h:32
void set_description(const std::string &text)
Set the description of the value.
Definition TextInterfaceInterpreter.h:48
void set_detailed_description(const std::string &text)
Set the detailed description of the value.
Definition TextInterfaceInterpreter.h:56
void set_value(const std::string &text)
Set the value as text.
Definition TextInterfaceInterpreter.h:40
std::string get_detailed_description() const
Get the detailed description of the value.
Definition TextInterfaceInterpreter.h:52
std::string get_description() const
Get the description of the value.
Definition TextInterfaceInterpreter.h:44
void set_modifiers(const std::string &modifiers) const
Parse any modifiers that will alter the behaviour of the output stream.
Definition TextInterfaceInterpreter.h:59
Interpreter(const std::string &_name, I *ptr, Get _get, Set _set)
Set all attributes on construction.
Definition TextInterfaceInterpreter.h:28
std::string get_value() const
Get the value as text.
Definition TextInterfaceInterpreter.h:36
void reset_modifiers() const
Reset any output stream modifiers.
Definition TextInterfaceInterpreter.h:64
Value()
Explicit default constructor required to delay definition of Reference::To<Parser>
Definition TextInterfaceValue.C:13

Generated using doxygen 1.14.0