12#ifndef __TextInterfaceProxy_h
13#define __TextInterfaceProxy_h
15#include "TextInterfaceAttribute.h"
16#include "TextInterfaceAdapter.h"
21namespace TextInterface
25 template<
class C,
class P>
37 { this->
value = copy.value->clone(); }
45 {
if (!ptr)
return "null";
46 return this->
value->get_value (ptr); }
50 {
if (ptr) this->value->set_value (ptr,
value); }
55 template<
class C,
class M,
class Get>
67 { this->
value=copy.value->clone();
get=copy.get;
prefix=copy.prefix; }
79 return this->
value->get_name();
84 {
if (!ptr)
return "null";
85 return this->
value->get_value ((
const_cast<C*
>(ptr)->*
get)()); }
89 {
if (ptr) this->
value->set_value ((ptr->*
get)(), val); }
92 bool matches (
const std::string& name)
const
93 {
return TextInterface::matches (name,
prefix, this->
value); }
108 template<
class V,
class E,
class Get,
class Size>
120 { this->
value=copy.value->clone();
129 {
return prefix +
"*:" + this->
value->get_name(); }
132 std::string
get_value (
const V* ptr)
const;
138 bool matches (
const std::string& name)
const;
160 template<
class M,
class K,
class E,
class Get>
172 {
prefix=copy.prefix; this->
value=copy.value->clone();
get=copy.get; }
182 {
return prefix +
"?:" + this->
value->get_name(); }
185 std::string
get_value (
const M* ptr)
const;
191 bool matches (
const std::string& name)
const;
206 const std::string& param)
const;
212template<
class V,
class E,
class G,
class S>
216 std::vector<unsigned> ind;
217 parse_indeces (ind,
range, (ptr->*
size)());
221 throw Error (InvalidState,
"VectorOfProxy["+
prefix+
"]",
"no parent");
223 for (
unsigned i=0; i<ind.size(); i++)
227 result += this->parent->get_delimiter();
230 if (label_elements && ind.size() > 1)
231 result += tostring(ind[i]) +
")";
233 E* element = (
const_cast<V*
>(ptr)->*
get)(ind[i]);
235 std::cerr <<
"VectorOfProxy[" <<
prefix <<
"]::get_value ("
236 << ptr <<
") element=" << element << std::endl;
238 result += this->
value->get_value (element);
244template<
class V,
class E,
class G,
class S>
246 const std::string& val)
248 std::vector<unsigned> ind;
249 parse_indeces (ind,
range, (ptr->*
size)());
251 for (
unsigned i=0; i<ind.size(); i++) {
252 E* element = (ptr->*
get)(ind[i]);
254 std::cerr <<
"VectorOfProxy[" <<
prefix <<
"]::set_value ("
255 << ptr <<
"," << val <<
")" << std::endl;
257 this->
value->set_value (element, val);
262template<
class C,
class M,
class Get,
class Size>
264 (
const std::string& name)
const
267 std::cerr <<
"TextInterface::VectorOfProxy::matches" << std::endl;
270 std::string remainder;
274 return this->
value->matches (remainder);
279template<
class M,
class K,
class E,
class G>
288 throw Error (InvalidState,
"MapOfProxy["+
prefix+
"]",
"no parent");
290 for (
unsigned i=0; i<ind.size(); i++)
294 result += this->parent->get_delimiter();
297 if (label_elements && ind.size() > 1)
298 result += tostring(ind[i]) +
")";
300 E* element = (
const_cast<M*
>(ptr)->*
get) (ind[i]);
302 result += this->
value->get_value (element);
308template<
class M,
class K,
class E,
class G>
310 const std::string& val)
315 for (
unsigned i=0; i<ind.size(); i++)
316 this->
value->set_value ((ptr->*
get)(ind[i]), val);
319template<
class M,
class K,
class E,
class G>
322 const std::string& par)
const
325 std::cerr <<
"MapOfProxy::get_indeces " << par << std::endl;
328 std::string::size_type length = par.length();
330 std::string
range = par;
333 if (par[0] !=
'[' || par[length-1] !=
']')
335 range = par.substr (1, length-2);
340 std::vector<std::string> key_str;
341 separate (
range, key_str,
", ");
343 indeces.resize (key_str.size());
344 for (
unsigned i=0; i<key_str.size(); i++)
345 indeces[i] = fromstring<K>(key_str[i]);
348template<
class M,
class K,
class E,
class G>
350 (
const std::string& name)
const
353 std::cerr <<
"TextInterface::MapOfProxy::matches" << std::endl;
356 std::string remainder;
360 return this->
value->matches (remainder);
A convenient exception handling class.
Definition Error.h:54
Reference::To< Attribute< P > > value
Definition TextInterfaceAdapter.h:54
Can be used as an Adapter (IsA != HasA) or a Decorator (IsA == HasA)
Definition TextInterfaceAdapter.h:79
Text interface to a class attribute.
Definition TextInterfaceAttribute.h:23
std::string get_value() const
Definition TextInterfaceAttribute.h:31
virtual Attribute * clone() const =0
Retun a newly constructed copy.
std::string get_value(const C *ptr) const
Get the value of the attribute.
Definition TextInterfaceProxy.h:83
bool matches(const std::string &name) const
Return true if the name argument matches.
Definition TextInterfaceProxy.h:92
HasAProxy(const HasAProxy ©)
Copy constructor.
Definition TextInterfaceProxy.h:66
std::string get_name() const
Get the name of the attribute.
Definition TextInterfaceProxy.h:74
HasAProxy(const std::string &pre, const Attribute< M > *pa, Get g)
Construct from a pointer to member attribute interface.
Definition TextInterfaceProxy.h:62
Get get
Method of C that returns M*.
Definition TextInterfaceProxy.h:98
Attribute< C > * clone() const
Retun a newly constructed copy.
Definition TextInterfaceProxy.h:70
std::string prefix
The name of the M attribute within C.
Definition TextInterfaceProxy.h:101
void set_value(C *ptr, const std::string &val)
Set the value of the attribute.
Definition TextInterfaceProxy.h:88
std::string get_value(const C *ptr) const
Get the value of the attribute.
Definition TextInterfaceProxy.h:44
void set_value(C *ptr, const std::string &value)
Set the value of the attribute.
Definition TextInterfaceProxy.h:49
IsAProxy(const Attribute< P > *pa)
Construct from a pointer to parent class attribute interface.
Definition TextInterfaceProxy.h:32
IsAProxy(const IsAProxy ©)
Copy constructor.
Definition TextInterfaceProxy.h:36
Attribute< C > * clone() const
Retun a newly constructed copy.
Definition TextInterfaceProxy.h:40
std::string range
Range parsed from name during matches.
Definition TextInterfaceProxy.h:202
MapOfProxy(const std::string &pre, const Attribute< E > *pa, Get g)
Construct from a pointer to parent class attribute interface.
Definition TextInterfaceProxy.h:167
void get_indeces(std::vector< K > &keys, const std::string ¶m) const
Worker function parses keys for get_value and set_value.
Definition TextInterfaceProxy.h:321
Get get
Method of M that returns E*, given K.
Definition TextInterfaceProxy.h:196
Attribute< M > * clone() const
Set the prefix to be added before attribute name.
Definition TextInterfaceProxy.h:177
std::string prefix
The name of the map instance.
Definition TextInterfaceProxy.h:199
bool matches(const std::string &name) const
Return true if the name argument matches.
Definition TextInterfaceProxy.h:350
std::string get_name() const
Get the name of the attribute.
Definition TextInterfaceProxy.h:181
void set_value(M *ptr, const std::string &value)
Set the value of the attribute.
Definition TextInterfaceProxy.h:309
MapOfProxy(const MapOfProxy ©)
Copy constructor.
Definition TextInterfaceProxy.h:171
virtual std::string get_value() const =0
Get the value as text.
Size size
Method of V that returns size of vector.
Definition TextInterfaceProxy.h:146
std::string get_name() const
Get the name of the attribute.
Definition TextInterfaceProxy.h:128
std::string prefix
The name of the vector instance.
Definition TextInterfaceProxy.h:149
void set_value(V *ptr, const std::string &value)
Set the value of the attribute.
Definition TextInterfaceProxy.h:245
bool matches(const std::string &name) const
Return true if the name argument matches.
Definition TextInterfaceProxy.h:264
std::string range
Range parsed from name during matches.
Definition TextInterfaceProxy.h:152
Get get
Method of V that returns E*.
Definition TextInterfaceProxy.h:143
Attribute< V > * clone() const
Retun a newly constructed copy.
Definition TextInterfaceProxy.h:124
VectorOfProxy(const std::string &p, const Attribute< E > *a, Get g, Size s)
Construct from a pointer to element attribute interface.
Definition TextInterfaceProxy.h:115
VectorOfProxy(const VectorOfProxy ©)
Copy constructor.
Definition TextInterfaceProxy.h:119