Home
Install
Use
Develop
Support
News
Credits
hosted by
|
12#ifndef __TextInterfaceEmbed_h
13#define __TextInterfaceEmbed_h
15#include "TextInterfaceAttribute.h"
18namespace TextInterface
25 template< class C, class Type, class Get, class Set>
36 std::cerr << "OptionalInterface name=" << t << std::endl;
45 std::string get_value ( const C* ptr) const;
51 bool matches ( const std::string& name) const;
58 virtual Parser* get_parser ( const C* ptr) const = 0;
62 mutable bool help = false;
68 template< class C, class Get>
72 Parser* operator () ( const C* ptr, Get func) const
74 return func ( const_cast<C* >(ptr));
78 template< class C, class P>
82 Parser* operator () ( const C* ptr, Parser* (P::*get)()) const
84 return ( const_cast<C* >(ptr)->*get)();
92 Parser* operator () ( const C* ptr, Parser* (*func)(C*)) const
94 return func ( const_cast<C* >(ptr));
98 template< class C, class Type, class Get, class Set, class GetParser>
102 GetParserPolicy<C,GetParser> get_parser_policy;
107 DirectInterface ( const std::string& t, Get g, Set s, GetParser p)
112 { return new DirectInterface(* this); }
117 GetParser get_parser_method;
119 Parser* get_parser ( const C* ptr) const try
121 return get_parser_policy (ptr, get_parser_method);
125 throw error += "DirectInterface::get_parser";
129 template< class C, class Type, class Get, class Set, class GetParser>
136 IndirectInterface ( const std::string& t, Get g, Set s, GetParser p)
141 { return new IndirectInterface(* this); }
146 GetParser get_parser_method;
148 Parser* get_parser ( const C* ptr) const try
150 Type tptr = ( const_cast<C* >(ptr)->*(this-> get))();
151 return (tptr->*get_parser_method)();
155 throw error += "IndirectInterface::get_parser";
159 template< class C, class Type>
164 template< class Get, class Set, class GetParser>
165 OptionalInterface<C,Type,Get,Set>*
166 direct ( const std::string& n, Get g, Set s, GetParser p)
168 return new DirectInterface<C,Type,Get,Set,GetParser> (n,g,s,p);
172 template< class Get, class Set, class GetParser>
173 OptionalInterface<C,Type,Get,Set>*
174 indirect ( const std::string& n, Get g, Set s, GetParser p)
176 return new IndirectInterface<C,Type,Get,Set,GetParser> (n,g,s,p);
184 template< class V, class Get, class Size>
204 { return prefix + "*:@"; }
208 { return prefix + ":help for attribute list"; }
211 std::string get_value ( const V* ptr) const;
214 void set_value (V* ptr, const std::string& value);
223 bool matches ( const std::string& name) const;
259 template < class G, class S>
269 template< class M, class K, class Get>
291 { return prefix + "?:@"; }
295 { return prefix + ":help for attribute list"; }
298 std::string get_value ( const M* ptr) const;
301 void set_value (M* ptr, const std::string& value);
310 bool matches ( const std::string& name) const;
328 const std::string& param) const;
334template< class C, class T, class G, class S>
342 return "\n" + parser->help();
344 return "no text parser available";
348 return value->get_value();
357template< class C, class T, class G, class S>
359 const std::string& val) try
362 value->set_value (val);
368 throw error += "TextInterface::OptionalInterface::set_value";
371template< class C, class T, class G, class S>
373 ( const std::string& text) const try
376 std::cerr << "TextInterface::OptionalInterface::matches"
377 " text='" << text << "'" << std::endl;
383 if (text == this-> name)
386 if (text == this-> name + "[:@]")
390 std::string remainder;
391 if (!match (this-> name, text, &range, &remainder))
395 std::cerr << "TextInterface::OptionalInterface::matches"
396 " remainder='" << remainder << "'" << std::endl;
399 if (remainder == "help")
408 std::cerr << "TextInterface::OptionalInterface::matches"
409 " no instance" << std::endl;
415 std::cerr << "TextInterface::OptionalInterface::matches"
416 " getting Parser" << std::endl;
423 parser = get_parser(this-> instance);
434 std::cerr << "TextInterface::OptionalInterface::matches"
435 " got Parser" << std::endl;
438 bool throw_exception = false;
439 value = parser->find (remainder, throw_exception);
444 std::cerr << "TextInterface::OptionalInterface::matches"
445 " Parser::find(" << remainder << ") returns false" << std::endl;
451 std::cerr << "TextInterface::OptionalInterface::matches"
452 " Parser::find(" << remainder << ") returns true" << std::endl;
459 throw error += "TextInterface::OptionalInterface::matches";
462template< class C, class T, class G, class S>
468 std::cerr << "TextInterface::OptionalInterface"
469 " calling Value::set_modifiers (" << modifiers << ")" << std::endl;
471 value->set_modifiers (modifiers);
476 std::cerr << "TextInterface::OptionalInterface"
477 " calling AttributeGetSet<>::set_modifiers" << std::endl;
484 throw error += "TextInterface::OptionalInterface::set_modifiers";
487template< class C, class T, class G, class S>
491 value->reset_modifiers ();
497 throw error += "TextInterface::OptionalInterface::reset_modifiers";
507template< class V, class G, class S>
511 std::vector<unsigned> ind;
512 parse_indeces (ind, this-> range, (ptr->*(this->size))());
516 throw Error (InvalidState, "VectorOfInterfaces["+ prefix+ "]", "no parent");
518 for ( unsigned i=0; i<ind.size(); i++)
522 result += this-> parent->get_delimiter();
525 if (label_elements && ind.size() > 1)
526 result += tostring(ind[i]) + ")";
529 parser = ( const_cast<V* >(ptr)->* get)(ind[i])->get_interface();
531 parser->set_delimiter( this-> parent->get_delimiter() );
534 result += "\n" + parser->help();
540 result += parser->get_value (pass_to_parser);
548 throw error += "TextInterface::VectorOfInterfaces::get_value";
551template< class V, class G, class S>
553 const std::string& val) try
555 std::vector<unsigned> ind;
556 parse_indeces (ind, range, (ptr->* size)());
558 for ( unsigned i=0; i<ind.size(); i++)
566 throw error += "TextInterface::VectorOfInterfaces::set_value";
569template< class C, class Get, class Size>
571 ( const std::string& name) const try
574 std::cerr << "TextInterface::VectorOfInterfaces::matches" << std::endl;
589 std::vector<unsigned> ind;
592 for ( unsigned i=0; i<ind.size(); i++)
603 throw error += "TextInterface::VectorOfInterfaces::matches";
606template< class M, class K, class G>
615 throw Error (InvalidState, "MapOfInterfaces["+ prefix+ "]", "no parent");
617 for ( unsigned i=0; i<ind.size(); i++)
621 result += this-> parent->get_delimiter();
624 if (label_elements && ind.size() > 1)
625 result += tostring(ind[i]) + ")";
628 parser->set_delimiter( this-> parent->get_delimiter() );
636 throw error += "TextInterface::MapOfInterfaces::get_value";
639template< class M, class K, class G>
641 const std::string& val) try
646 for ( unsigned i=0; i<ind.size(); i++)
654 throw error += "TextInterface::MapOfInterfaces::set_value";
657template< class M, class K, class G>
660 const std::string& par) const try
663 std::cerr << "MapOfInterfaces::get_indeces " << par << std::endl;
666 std::string::size_type length = par.length();
668 std::string range = par;
671 if (par[0] != '[' || par[length-1] != ']')
673 range = par.substr (1, length-2);
678 std::vector<std::string> key_str;
679 separate ( range, key_str, ", ");
681 indeces.resize (key_str.size());
682 for ( unsigned i=0; i<key_str.size(); i++)
683 indeces[i] = fromstring<K>(key_str[i]);
687 throw error += "TextInterface::MapOfInterfaces::get_indeces";
690template< class M, class K, class G>
692 ( const std::string& name) const try
695 std::cerr << "TextInterface::MapOfInterfaces::matches" << std::endl;
710 for ( unsigned i=0; i<ind.size(); i++)
720 throw error += "TextInterface::MapOfInterfaces::matches";
A convenient exception handling class. Definition Error.h:54
Template class manages Reference::Able objects. Definition ReferenceTo.h:25
Attribute< C > * clone() const Return a clone. Definition TextInterfaceAttribute.h:260
AttributeGetSet(const std::string &_name, Get _get, Set _set) Constructor. Definition TextInterfaceAttribute.h:256
void set_value(C *ptr, const std::string &value) Set the value of the attribute. Definition TextInterfaceAttribute.h:263
Get get The get method. Definition TextInterfaceAttribute.h:243
void reset_modifiers() const Reset any output stream modifiers. Definition TextInterfaceAttribute.h:228
std::string get_name() const Get the name of the attribute. Definition TextInterfaceAttribute.h:200
void set_modifiers(const std::string &modifiers) const Parse any modifiers that will alter the behaviour of the output stream. Definition TextInterfaceAttribute.h:225
std::string name The name of the attribute. Definition TextInterfaceAttribute.h:234
std::string get_value() const Get the value of the attribute. Definition TextInterfaceAttribute.h:31
Reference::To< C, false > instance Pointer to the instance from which attribute value will be obtained. Definition TextInterfaceAttribute.h:54
Attribute() Default constructor. Definition TextInterfaceAttribute.h:28
Embedded interface factory for TextInterface::To<C> Definition TextInterfaceEmbed.h:257
Policy for getting a Parser. Definition TextInterfaceEmbed.h:70
MapOfInterfaces(const MapOfInterfaces ©) Copy constructor. Definition TextInterfaceEmbed.h:280
std::string remainder Remainder parsed from name during matches. Definition TextInterfaceEmbed.h:324
std::string get_name() const Get the name of the attribute. Definition TextInterfaceEmbed.h:290
void set_detailed_description(const std::string &) Set the detailed description of the attribute. Definition TextInterfaceEmbed.h:307
bool matches(const std::string &name) const Return true if the name argument matches. Definition TextInterfaceEmbed.h:692
MapOfInterfaces(const std::string &pre, Get g) Construct from a pointer to parent class attribute interface. Definition TextInterfaceEmbed.h:276
void set_value(M *ptr, const std::string &value) Set the value of the attribute. Definition TextInterfaceEmbed.h:640
Attribute< M > * clone() const Set the prefix to be added before attribute name. Definition TextInterfaceEmbed.h:286
std::string range Range parsed from name during matches. Definition TextInterfaceEmbed.h:321
Get get Method of M that returns element, given K. Definition TextInterfaceEmbed.h:315
void get_indeces(std::vector< K > &keys, const std::string ¶m) const Worker function parses keys for get_value and set_value. Definition TextInterfaceEmbed.h:659
void set_description(const std::string &) Set the description of the attribute. Definition TextInterfaceEmbed.h:304
std::string get_description() const Get the description of the attribute. Definition TextInterfaceEmbed.h:294
std::string prefix The name of the map instance. Definition TextInterfaceEmbed.h:318
Dynamically embeds the interface of something that can be got and set. Definition TextInterfaceEmbed.h:27
bool matches(const std::string &name) const Return true if the name argument matches. Definition TextInterfaceEmbed.h:373
void set_modifiers(const std::string &) const Parse any modifiers that will alter the behaviour of the output stream. Definition TextInterfaceEmbed.h:463
Reference::To< Value > value Value found during match. Definition TextInterfaceEmbed.h:61
void set_value(C *ptr, const std::string &value) Set the value of the attribute. Definition TextInterfaceEmbed.h:358
OptionalInterface(const std::string &t, Get g, Set s) Construct from a pointer to element attribute interface. Definition TextInterfaceEmbed.h:32
std::string get_name() const Get the name of the attribute. Definition TextInterfaceEmbed.h:41
void reset_modifiers() const Reset any output stream modifiers. Definition TextInterfaceEmbed.h:488
An array of Value interfaces. Definition TextInterfaceParser.h:31
virtual std::string get_value() const =0 Get the value as text.
Reference::To< Parser, false > parent The Parser composite in which this Value component is integrated. Definition TextInterfaceValue.h:75
Dynamically embeds the interfaces of elements in a vector. Definition TextInterfaceEmbed.h:186
VectorOfInterfaces(const VectorOfInterfaces ©) Copy constructor. Definition TextInterfaceEmbed.h:195
std::string remainder Remainder parsed from name during matches. Definition TextInterfaceEmbed.h:248
Get get Method of V that returns E*. Definition TextInterfaceEmbed.h:236
std::string modifiers Any modifiers set by caller. Definition TextInterfaceEmbed.h:251
VectorOfInterfaces(const std::string &p, Get g, Size s) Construct from a pointer to element attribute interface. Definition TextInterfaceEmbed.h:191
void reset_modifiers() const Reset any output stream modifiers. Definition TextInterfaceEmbed.h:230
bool matches(const std::string &name) const Return true if the name argument matches. Definition TextInterfaceEmbed.h:571
Attribute< V > * clone() const Retun a newly constructed copy. Definition TextInterfaceEmbed.h:199
std::string prefix The name of the vector instance. Definition TextInterfaceEmbed.h:242
void set_detailed_description(const std::string &) Set the detailed description of the attribute. Definition TextInterfaceEmbed.h:220
void set_value(V *ptr, const std::string &value) Set the value of the attribute. Definition TextInterfaceEmbed.h:552
Size size Method of V that returns size of vector. Definition TextInterfaceEmbed.h:239
std::string get_name() const Get the name of the attribute. Definition TextInterfaceEmbed.h:203
std::string range Range parsed from name during matches. Definition TextInterfaceEmbed.h:245
void set_modifiers(const std::string &mod) const Parse any modifiers that will alter the behaviour of the output stream. Definition TextInterfaceEmbed.h:226
std::string get_description() const Get the description of the attribute. Definition TextInterfaceEmbed.h:207
void set_description(const std::string &) Set the description of the attribute. Definition TextInterfaceEmbed.h:217
Generated using doxygen 1.14.0
|