Home
Install
Use
Develop
Support
News
Credits
hosted by
|
12 #ifndef __TextInterfaceEmbed_h
13 #define __TextInterfaceEmbed_h
15 #include "TextInterfaceAttribute.h"
18 namespace TextInterface
25 template< class C, class Type, class Get, class Set>
26 class OptionalInterface : public AttributeGetSet<C,Type,Get,Set>
36 std::cerr << "OptionalInterface name=" << t << std::endl;
45 std::string get_value ( const C* ptr) 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>
79 class GetParserPolicy<C, Parser* (P::*)()>
82 Parser* operator () ( const C* ptr, Parser* (P::*get)()) const
84 return ( const_cast<C* >(ptr)->*get)();
89 class GetParserPolicy<C, Parser* (C*)>
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>
99 class DirectInterface : public OptionalInterface<C,Type,Get,Set>
102 GetParserPolicy<C,GetParser> get_parser_policy;
107 DirectInterface ( const std::string& t, Get g, Set s, GetParser p)
111 Attribute<C>* clone () const
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>
130 class IndirectInterface : public OptionalInterface<C,Type,Get,Set>
136 IndirectInterface ( const std::string& t, Get g, Set s, GetParser p)
140 Attribute<C>* clone () const
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>
185 class VectorOfInterfaces : public Attribute<V>
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;
245 mutable std::string range;
259 template < class G, class S>
269 template< class M, class K, class Get>
270 class MapOfInterfaces : public Attribute<M>
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;
321 mutable std::string range;
328 const std::string& param) const;
334 template< class C, class T, class G, class S>
342 return "\n" + parser->help();
344 return "no text parser available";
348 return value->get_value();
357 template< 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";
371 template< 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";
462 template< 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";
487 template< class C, class T, class G, class S>
491 value->reset_modifiers ();
497 throw error += "TextInterface::OptionalInterface::reset_modifiers";
507 template< 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() );
533 if (remainder == "help")
534 result += "\n" + parser->help();
537 std::string pass_to_parser = remainder;
538 if (modifiers.length() > 0)
539 pass_to_parser += "%" + modifiers;
540 result += parser->get_value (pass_to_parser);
548 throw error += "TextInterface::VectorOfInterfaces::get_value";
551 template< 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++)
561 parser->set_value (remainder, val);
566 throw error += "TextInterface::VectorOfInterfaces::set_value";
569 template< class C, class Get, class Size>
571 ( const std::string& name) const try
574 std::cerr << "TextInterface::VectorOfInterfaces::matches" << std::endl;
577 if (!match (prefix, name, &range, &remainder))
580 if (remainder == "@")
583 if (remainder == "help")
589 std::vector<unsigned> ind;
590 parse_indeces (ind, range, (this->instance->*size)());
592 for ( unsigned i=0; i<ind.size(); i++)
594 C* ptr = this->instance.ptr();
596 if (! parser->found (remainder))
603 throw error += "TextInterface::VectorOfInterfaces::matches";
606 template< class M, class K, class G>
611 get_indeces (ind, range);
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() );
629 result += parser->get_value (remainder);
636 throw error += "TextInterface::MapOfInterfaces::get_value";
639 template< class M, class K, class G>
641 const std::string& val) try
644 get_indeces (ind, range);
646 for ( unsigned i=0; i<ind.size(); i++)
649 parser->set_value (remainder, val);
654 throw error += "TextInterface::MapOfInterfaces::set_value";
657 template< 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;
670 if (prefix.length()) {
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";
690 template< class M, class K, class G>
692 ( const std::string& name) const try
695 std::cerr << "TextInterface::MapOfInterfaces::matches" << std::endl;
698 if (!match (prefix, name, &range, &remainder))
701 if (remainder == "@")
708 get_indeces (ind, range);
710 for ( unsigned i=0; i<ind.size(); i++)
713 if (! parser->found (remainder))
720 throw error += "TextInterface::MapOfInterfaces::matches";
std::string remainder Remainder parsed from name during matches. Definition: TextInterfaceEmbed.h:253
MapOfInterfaces(const std::string &pre, Get g) Construct from a pointer to parent class attribute interface. Definition: TextInterfaceEmbed.h:281
bool matches(const std::string &name) const Return true if the name argument matches. Definition: TextInterfaceEmbed.h:373
std::string get_name() const Get the name of the attribute. Definition: TextInterfaceAttribute.h:206
void set_modifiers(const std::string &mod) const Parse any modifiers that will alter the behaviour of the output stream. Definition: TextInterfaceEmbed.h:231
std::string prefix The name of the vector instance. Definition: TextInterfaceEmbed.h:247
VectorOfInterfaces(const VectorOfInterfaces ©) Copy constructor. Definition: TextInterfaceEmbed.h:200
Attribute< V > * clone() const Retun a newly constructed copy. Definition: TextInterfaceEmbed.h:204
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
std::string range Range parsed from name during matches. Definition: TextInterfaceEmbed.h:326
OptionalInterface(const std::string &t, Get g, Set s) Construct from a pointer to element attribute interface. Definition: TextInterfaceEmbed.h:42
std::string get_name() const Get the name of the attribute. Definition: TextInterfaceEmbed.h:51
Attribute< M > * clone() const Set the prefix to be added before attribute name. Definition: TextInterfaceEmbed.h:291
A convenient exception handling class. Definition: Error.h:54
void set_value(M *ptr, const std::string &value) Set the value of the attribute. Definition: TextInterfaceEmbed.h:640
void set_detailed_description(const std::string &) Set the detailed description of the attribute. Definition: TextInterfaceEmbed.h:312
void set_detailed_description(const std::string &) Set the detailed description of the attribute. Definition: TextInterfaceEmbed.h:225
An array of Value interfaces. Definition: TextInterfaceParser.h:35
void reset_modifiers() const Reset any output stream modifiers. Definition: TextInterfaceEmbed.h:488
void reset_modifiers() const Reset any output stream modifiers. Definition: TextInterfaceEmbed.h:235
std::string modifiers Any modifiers set by caller. Definition: TextInterfaceEmbed.h:256
Template class manages Reference::Able objects. Definition: Reference.h:74
bool matches(const std::string &name) const Return true if the name argument matches. Definition: TextInterfaceEmbed.h:692
void set_value(C *ptr, const std::string &value) Set the value of the attribute. Definition: TextInterfaceEmbed.h:358
void set_value(V *ptr, const std::string &value) Set the value of the attribute. Definition: TextInterfaceEmbed.h:552
std::string get_name() const Get the name of the attribute. Definition: TextInterfaceEmbed.h:208
AttributeGetSet(const std::string &_name, Get _get, Set _set) Constructor. Definition: TextInterfaceAttribute.h:262
std::string get_description() const Get the description of the attribute. Definition: TextInterfaceEmbed.h:299
std::string range Range parsed from name during matches. Definition: TextInterfaceEmbed.h:250
Reference::To< Value > value Value found during match. Definition: TextInterfaceEmbed.h:71
std::string get_description() const Get the description of the attribute. Definition: TextInterfaceEmbed.h:212
Get get Method of V that returns E*. Definition: TextInterfaceEmbed.h:241
Interface to a class attribute with an accessor and modifier methods. Definition: TextInterfaceAttribute.h:256
VectorOfInterfaces(const std::string &p, Get g, Size s) Construct from a pointer to element attribute interface. Definition: TextInterfaceEmbed.h:196
Policy for getting a Parser. Definition: TextInterfaceEmbed.h:74
std::string get_value() const Get the value of the attribute. Definition: TextInterfaceAttribute.h:42
Size size Method of V that returns size of vector. Definition: TextInterfaceEmbed.h:244
void set_modifiers(const std::string &) const Parse any modifiers that will alter the behaviour of the output stream. Definition: TextInterfaceEmbed.h:463
void set_description(const std::string &) Set the description of the attribute. Definition: TextInterfaceEmbed.h:309
std::string name The name of the attribute. Definition: TextInterfaceAttribute.h:240
Embedded interface factory for TextInterface::To<C> Definition: TextInterfaceEmbed.h:261
bool matches(const std::string &name) const Return true if the name argument matches. Definition: TextInterfaceEmbed.h:571
Get get Method of M that returns element, given K. Definition: TextInterfaceEmbed.h:320
std::string remainder Remainder parsed from name during matches. Definition: TextInterfaceEmbed.h:329
void set_description(const std::string &) Set the description of the attribute. Definition: TextInterfaceEmbed.h:222
std::string prefix The name of the map instance. Definition: TextInterfaceEmbed.h:323
Dynamically embeds the interfaces of elements in a vector. Definition: TextInterfaceEmbed.h:190
std::string get_name() const Get the name of the attribute. Definition: TextInterfaceEmbed.h:295
Generated using doxygen 1.8.17
|