28 inline int null_proc() {
return TCL_OK;}
34 virtual string operator()(
const char* index)=0;
35 virtual void keys_of()=0;
38 static void del_obj(ClientData c)
41 template <
class T> std::string quoteTCL(
const T& x);
45 template <
class F,
class S>
46 std::ostream& operator<<(std::ostream& o, const std::pair<F,S>& p)
47 {
return o<<quoteTCL(p.first)<<
" "<<quoteTCL(p.second);}
50 std::ostream& ContainerOut(std::ostream& o,
const T& c)
52 for (
typename T::const_iterator i=c.begin(); i!=c.end(); i++)
54 if (i!=c.begin()) o<<
" ";
62 std::istream& ContainerIn(std::istream& i, T& c)
65 typename T::value_type v;
68 #if defined(__cplusplus) && __cplusplus>=201103L 69 c.push_back(std::move(v));
78 template <
class T,
class CharT,
class Traits>
80 operator<<(std::basic_ostream<CharT,Traits>& o,
const T& v)
81 {
return ContainerOut(o,v);}
87 std::ostringstream tmp;
94 template <
class T,
class CharT,
class Traits>
96 operator>>(std::basic_istream<CharT,Traits>& i, T& v)
97 {
return ContainerIn(i,v);}
101 std::string quoteTCL(
const T& x)
106 for (
size_t i=0; i<os.str().length(); ++i)
108 if (strchr(
"{}\\\"", os.str()[i])!=NULL)
112 if (r.find(
' ')!=std::string::npos)
118 template <
class T>
struct is_map:
public false_type
120 static string keys() {
return ".#members";}
121 static string type() {
return ".@is_set";}
126 static string keys() {
return ".#keys";}
127 static string type() {
return ".@is_map";}
131 template <
class K,
class V,
class C,
class A>
struct is_map<
std::map<K,V,C,A> >:
134 #if defined(__cplusplus) && __cplusplus>=201103L 135 template <
class K,
class V,
class C,
class A>
struct is_map<std::unordered_map<K,V,C,A> >:
141 readIn(std::istream& i)
142 {
typename T::value_type v; i>>v;
return v;}
146 readIn(std::istream& i)
148 typename remove_const<typename T::value_type::first_type>::type k;
149 typename T::value_type::second_type v;
151 return typename T::value_type(k,v);
154 template <
class T,
class CharT,
class Traits>
156 operator>>(std::basic_istream<CharT,Traits>& i, T& s)
161 typename T::value_type v=readIn<T>(i);
168 static int elem(ClientData v, Tcl_Interp *
interp,
int argc,
174 r <<
"insufficient arguments";
181 static int keys(ClientData v, Tcl_Interp *interp,
int argc,
185 template <
class T>
struct idx 186 {T operator()(
const char *x) {
throw error(
"invalid index type");}};
188 template <>
struct idx<int>
189 {
int operator()(
const char *x){
return atoi(x);}};
191 template <>
struct idx<unsigned int>
192 {
int operator()(
const char *x){
return atoi(x);}};
194 template <>
struct idx<long>
195 {
long operator()(
const char *x){
return atol(x);}};
197 template <>
struct idx<unsigned long>
198 {
long operator()(
const char *x){
return atol(x);}};
200 template <>
struct idx<const char *>
201 {
const char* operator()(
const char *x){
return x;}};
203 template <>
struct idx<std::string>
204 {std::string operator()(
const char *x){
return std::string(x);}};
206 template <
class T>
struct idx<const T>:
public idx<T> {};
216 for (
typename T::const_iterator i=o.begin(); i!=o.end(); i++)
225 for (
typename T::const_iterator i=o.begin(); i!=o.end(); i++)
234 typedef std::vector<bool>::reference R;
235 std::vector<bool> defaultDummy;
237 member_entry(): defaultDummy(1), memberptr(defaultDummy[0]) {}
239 inline void get() {
tclreturn() << (bool)memberptr;}
240 inline void put(
const char *s) {
tclreturn() << s; memberptr=atoi(s);}
243 template <
class T,
class idx_t>
249 TCL_obj_of(T& o,
const string& d): obj(o), desc(d) {}
250 string operator()(
const char* index)
252 string elname=desc+
"("+index+
")";
257 TCL_obj_properties().erase(elname);
261 void keys_of() {ecolab::keys_of(obj);}
264 template <
class T,
class idx_t>
271 string operator()(
const char* index)
273 string elname=desc+
"("+index+
")";
274 TCL_obj_properties().erase(elname);
275 typename T::reference r(obj[
idx<idx_t>()(index)]);
279 void keys_of() {ecolab::keys_of(obj);}
282 template <
class idx_t>
286 TCL_obj_of(std::vector<bool>& o,
const string& d):
290 template <
class idx_t>
294 TCL_obj_of(
const std::vector<bool>& o,
const string& d):
306 TCL_obj_of(T& o,
const string& d): obj(o), desc(d) {}
307 string operator()(
const char* index)
309 string elname=desc+
"("+index+
")";
310 TCL_obj_properties().erase(elname);
311 typename T::iterator j;
313 for (i=0, j=obj.begin(); i<atoi(index); i++, j++);
317 void keys_of() {ecolab::keys_of(obj);}
323 makeTCL_obj_of(T& o,
const string& d)
328 makeTCL_obj_of(T& o,
const string& d)
332 template <
class T,
class idx_t>
339 string operator()(
const char* index)
341 void keys_of() {ecolab::keys_of(obj);}
350 void proc(
int argc, Tcl_Obj *
const argv[]) {
351 x.resize((
size_t)
TCL_args(argc, argv));
353 static void createInTCL(S& x,
const string& d) {
354 Tcl_CreateObjCommand(
interp(),(d+
".resize").c_str(), TCL_oproc,
356 TCL_cmd_data_delete);
358 void proc(
int,
const char **) {}
362 void TCL_obj_const_sequence(
TCL_obj_t& targ,
const string& desc, V& arg)
364 TCL_obj_register(targ,desc,arg);
365 TCL_obj(targ,desc+
".size",arg,&V::size);
366 Tcl_CreateCommand(
interp(),(desc+
".@is_sequence").c_str(),
367 (Tcl_CmdProc*)null_proc,NULL,NULL);
369 Tcl_CreateCommand(
interp(),(desc+
".@elem").c_str(),(Tcl_CmdProc*)elem,c,
370 (Tcl_CmdDeleteProc*)del_obj);
375 void TCL_obj_const_vector(
TCL_obj_t& targ,
const string& desc, V& arg)
377 TCL_obj_register(targ,desc,arg);
378 TCL_obj(targ,desc+
".size",arg,&V::size);
379 Tcl_CreateCommand(
interp(),(desc+
".@is_vector").c_str(),
380 (Tcl_CmdProc*)null_proc,NULL,NULL);
382 Tcl_CreateCommand(
interp(),(desc+
".@elem").c_str(),(Tcl_CmdProc*)elem,c,
383 (Tcl_CmdDeleteProc*)del_obj);
387 void TCL_obj_sequence(
TCL_obj_t& targ,
const string& desc, V& arg)
389 ecolab::TCL_obj_const_sequence(targ,desc,arg);
391 TCL_obj(targ,desc+
".clear",arg,&V::clear);
394 template <
class T,
class A>
395 void TCL_obj_sequence(
TCL_obj_t& targ,
const string& desc, std::vector<T,A>& arg)
397 ecolab::TCL_obj_const_vector(targ,desc,arg);
399 TCL_obj(targ,desc+
".clear",arg,&std::vector<T,A>::clear);
402 template <
class T,
class A>
403 void TCL_obj_sequence(
TCL_obj_t& targ,
const string& desc,
const std::vector<T,A>& arg)
405 ecolab::TCL_obj_const_vector(targ,desc,arg);
409 template <
class VT>
struct KeyName:
public std::string
410 {
KeyName(): std::string(
".#members") {}};
411 template <
class K,
class V>
struct KeyName<std::pair<K,V> >:
public std::string
412 {
KeyName(): std::string(
".#keys") {}};
415 void TCL_obj_associative_container(
TCL_obj_t& targ,
const string& desc, T& arg)
417 TCL_obj_register(targ,desc,arg);
418 TCL_obj(targ,desc+
".size",arg,&T::size);
420 (Tcl_CmdProc*)null_proc,NULL,NULL);
421 ClientData c=(ClientData)makeTCL_obj_of(arg,desc);
422 Tcl_CreateCommand(
interp(),(desc+
".@elem").c_str(),(Tcl_CmdProc*)elem,c,
423 (Tcl_CmdDeleteProc*)del_obj);
424 c=(ClientData)makeTCL_obj_of(arg,desc);
426 (Tcl_CmdDeleteProc*)del_obj);
428 Tcl_CreateCommand(
interp(),(desc+
".count").c_str(),(Tcl_CmdProc*)elem,c,
429 (Tcl_CmdDeleteProc*)del_obj);
436 TCL_obj_sequence(t,desc,arg);
443 TCL_obj_associative_container(t,desc,arg);
447 using ecolab::TCL_obj;
451 using ecolab::operator<<;
Definition: TCL_obj_stl.h:333
Definition: TCL_obj_base.h:251
An RAII class for returning values to TCL.
Definition: tcl++.h:563
Definition: TCL_obj_stl.h:346
An EcoLab string stream class.
Definition: eco_strstream.h:64
EcoLab exception class.
Definition: error.h:25
Tcl_Interp * interp()
default interpreter. Set to NULL when interp() is destroyed
Definition: tcl++.h:222
Definition: TCL_obj_stl.h:301
classdesc::TCL_obj_t null_TCL_obj
a null TCL_obj_t suitable for nothing if needed.
Definition: TCL_obj_base.h:267
Definition: TCL_obj_stl.h:30
Definition: TCL_obj_stl.h:299
Definition: TCL_obj_stl.h:409
TCL_obj support for STL containers.
Definition: TCL_obj_stl.h:185
Definition: TCL_obj_base.h:511
Represent arguments to TCL commands.
Definition: TCL_obj_base.h:138
Definition: TCL_obj_stl.h:449
distinguish between maps and sets based on value_type of container
Definition: TCL_obj_base.h:1131
controlled template specialisation: stolen from boost::enable_if.
Definition: classdesc.h:249
_OPENMP
Definition: accessor.h:16
TCL_obj descriptor object.
Definition: TCL_obj_base.h:327
Definition: TCL_obj_stl.h:244
Definition: TCL_obj_stl.h:265
Definition: TCL_obj_stl.h:124