Home
Install
Use
Develop
Support
News
Credits
hosted by
|
12 #ifndef __TextInterfaceAttribute_h
13 #define __TextInterfaceAttribute_h
15 #include "TextInterfaceValue.h"
17 namespace TextInterface
22 class Attribute : public Value
43 virtual std::string get_value ( const C*) const = 0;
46 virtual void set_value (C*, const std::string& value) = 0;
66 mutable ToString tostr;
70 void set_modifiers ( const std::string& modifiers) const
73 std::cerr << "ToStringPolicy<Type=" << typeid(Type).name()
74 << ">::set_modifiers " << modifiers << " tostr=" << ( void*) &tostr << std::endl;
76 tostr.set_precision ( fromstring<unsigned>(modifiers) );
79 void reset_modifiers () const
81 tostr.reset_modifiers ();
84 std::string operator () ( const Type& t) const
87 std::cerr << "ToStringPolicy<Type=" << typeid(Type).name()
88 << ">::operator ()" << " tostr=" << ( void*) &tostr << std::endl;
96 template< class C, class Get>
97 class GetToStringPolicy : public ToStringPolicy<typename Get::result_type>
100 std::string operator () ( const C* ptr, Get get) const
103 std::cerr << "GetToStringPolicy<C=" << typeid(C).name()
104 << ">::operator (const C* ptr, Get get)" << " tostr=" << ( void*) &this->tostr << std::endl;
108 return this->tostr( get (ptr) );
112 template< class C, class P, class Type>
113 class GetToStringPolicy<C, Type (P::*)() const> : public ToStringPolicy<Type>
116 std::string operator () ( const C* ptr, Type (P::*get)() const) const
119 std::cerr << "GetToStringPolicy<C=" << typeid(C).name()
120 << ">::operator (const C* ptr, Type (P::*get)() const)" << " tostr=" << ( void*) &this->tostr << std::endl;
124 return this->tostr( (ptr->*get) () );
128 template< class C, class Type>
129 class GetToStringPolicy<C, Type (C*)> : public ToStringPolicy<Type>
132 std::string operator () ( const C* ptr, Type (*func)(C*)) const
135 std::cerr << "GetToStringPolicy<Type=" << typeid(Type).name()
136 << ">::operator (const C* ptr, Type (*func)(C*))" << " tostr=" << ( void*) &this->tostr << std::endl;
140 return this->tostr( (*func) (ptr) );
146 template< class C, class Set>
147 class SetFromStringPolicy
150 void operator () (C* ptr, Set set, const std::string& value)
151 { (set) (ptr, fromstring<typename Set::second_argument_type>(value)); }
154 template< class C, class P, class T>
158 void operator () (C* ptr, void (P::*set)( const T&), const std::string& val)
159 { (ptr->*set) (fromstring<T>(val)); }
162 template< class C, class P, class Type>
163 class SetFromStringPolicy<C, void (P::*)(Type)>
166 void operator () (C* ptr, void (P::*set)(Type), const std::string& value)
167 { (ptr->*set) (fromstring<Type>(value)); }
170 template< class C, class P, class T>
171 class SetFromStringPolicy<C, void (*)(P*, const T&)>
174 void operator () (C* ptr, void (*set)(P*, const T&), const std::string& val)
175 { (*set) (ptr, fromstring<T>(val)); }
178 template< class C, class P, class Type>
179 class SetFromStringPolicy<C, void (*)(P*,Type)>
182 void operator () (C* ptr, void (*set)(P*,Type), const std::string& value)
183 { (*set) (ptr, fromstring<Type>(value)); }
187 template< class C, class Get>
188 class AttributeGet : public Attribute<C>
218 std::string get_value ( const C* ptr) const
219 { return tostring (ptr, get); }
223 { throw Error (InvalidState, "AttributeGet::set_value",
224 name + " cannot be set"); }
227 { tostring.set_modifiers (modifiers); }
230 { tostring.reset_modifiers (); }
250 template< class C, class Type, class Get, class Set>
264 void set_value (C* ptr, const std::string& value)
265 { from_string (ptr, set, value); }
279 template< class C, class Type>
291 template< class Get, class Set>
299 operator () ( const std::string& n, const std::string& d, Get g)
302 get->set_description (d); return get;
306 template< class Get, class Set>
308 operator () ( const std::string& n, const std::string& d, Get g, Set s)
317 void parse_indeces (std::vector<unsigned>& indeces, const std::string&,
321 bool match ( const std::string& name, const std::string& text,
322 std::string* range, std::string* remainder = 0);
std::string get_name() const Get the name of the attribute. Definition: TextInterfaceAttribute.h:206
Reference::To< C, false > instance Pointer to the instance from which attribute value will be obtained. Definition: TextInterfaceAttribute.h:65
std::string description The description of the attribute. Definition: TextInterfaceAttribute.h:243
void set_value(C *ptr, const std::string &value) Set the value of the attribute. Definition: TextInterfaceAttribute.h:269
Attribute() Default constructor. Definition: TextInterfaceAttribute.h:38
void set_value(const std::string &value) Set the value of the attribute. Definition: TextInterfaceAttribute.h:46
Policy for converting a string to a value. Definition: TextInterfaceAttribute.h:152
Policy for converting a value to a string. Definition: TextInterfaceAttribute.h:67
virtual void set_description(const std::string &)=0 Set the description of the value.
A convenient exception handling class. Definition: Error.h:54
AttributeGet(const std::string &_name, Get _get) Constructor. Definition: TextInterfaceAttribute.h:199
std::string get_detailed_description() const Get the detailed description of the attribute. Definition: TextInterfaceAttribute.h:215
virtual Attribute * clone() const =0 Retun a newly constructed copy.
std::string detailed_description The detailed description of the attribute. Definition: TextInterfaceAttribute.h:246
std::string get_description() const Get the description of the attribute. Definition: TextInterfaceAttribute.h:209
void set_detailed_description(const std::string &d) Get the detailed description of the attribute. Definition: TextInterfaceAttribute.h:219
Interface to a class attribute with an accessor method, C::Get() Definition: TextInterfaceAttribute.h:193
AttributeGetSet(const std::string &_name, Get _get, Set _set) Constructor. Definition: TextInterfaceAttribute.h:262
Set set The set method. Definition: TextInterfaceAttribute.h:275
Get get The get method. Definition: TextInterfaceAttribute.h:249
AttributeGet< C, Get > * operator()(const std::string &n, Get g) Generate a new AttributeGet instance. Definition: TextInterfaceAttribute.h:292
void reset_modifiers() const Reset any output stream modifiers. Definition: TextInterfaceAttribute.h:234
Interface to a class attribute with an accessor and modifier methods. Definition: TextInterfaceAttribute.h:256
std::string get_value() const Get the value of the attribute. Definition: TextInterfaceAttribute.h:42
void set_modifiers(const std::string &modifiers) const Parse any modifiers that will alter the behaviour of the output stream. Definition: TextInterfaceAttribute.h:231
std::string name The name of the attribute. Definition: TextInterfaceAttribute.h:240
AttributeGet and AttributeGetSet factory. Definition: TextInterfaceAttribute.h:285
void set_value(C *, const std::string &) Set the value of the attribute. Definition: TextInterfaceAttribute.h:227
void set_description(const std::string &d) Get the description of the attribute. Definition: TextInterfaceAttribute.h:212
Attribute< C > * clone() const Return a clone. Definition: TextInterfaceAttribute.h:203
Policy for converting a value to a string. Definition: TextInterfaceAttribute.h:102
Text interface to a class attribute. Definition: TextInterfaceAttribute.h:27
Attribute< C > * clone() const Return a clone. Definition: TextInterfaceAttribute.h:266
virtual void set_detailed_description(const std::string &)=0 Set the detailed description of the value.
Generated using doxygen 1.8.17
|