21 #ifndef TCL_OBJ_TEMPLATES_H 22 #define TCL_OBJ_TEMPLATES_H 28 int TCL_obj_template_not_included() {
return 0;}
35 typename enable_if<Not<is_container<T> >,
void>::T
36 TCL_objp(TCL_obj_t& t,
const classdesc::string& desc, T& arg, dummy<0> d=0)
45 void TCL_obj(TCL_obj_t& t,
const classdesc::string& desc, T& arg)
47 TCL_obj_register(t,desc,arg);
55 void TCL_obj_onbase(TCL_obj_t& t,
const classdesc::string& desc, T& arg)
57 TCL_obj_register(t,desc,arg,
true);
73 int TCL_obj_init(T& x)
85 #define make_model(x) \ 87 DEFINE_ECOLAB_LIBRARY; \ 88 int TCL_obj_##x=(ecolab::TCL_obj_init(x),TCL_obj(ecolab::null_TCL_obj,(std::string)#x,x),1); \ 92 #define register(x) static int \ 93 TCL_obj_register_##x=(ecolab::TCL_obj_register(ecolab::null_TCL_obj,(string)#x,x), \ 94 TCL_obj(ecolab::null_TCL_obj,(string)#x,x),1) 97 #define TCLTYPE(x) TCLTYPEBASE(x,x,) 98 #define TCLTYPEARGS(x) TCLTYPEBASE(x,x,(largv)) 99 #define TCLPOLYTYPE(x,itf) TCLTYPEBASE(x,itf,) 100 #define TCLPOLYTYPEARGS(x,itf) TCLTYPEBASE(x,itf,(largv)) 102 #define TCLTYPEBASE(x,itf,contructorArgs) \ 103 namespace x_tcltype_##x { \ 104 DEFINE_ECOLAB_LIBRARY; \ 106 int deleteobject(ClientData cd, Tcl_Interp *interp, int argc, const char **argv) \ 108 assert( strcmp(argv[0]+strlen(argv[0])-strlen(".delete"), \ 110 std::string s(argv[0]); \ 111 ecolab::TCL_obj_deregister(s.substr(0,s.length()-strlen(".delete"))); \ 116 int createobject(ClientData cd, Tcl_Interp *interp, int argc, Tcl_Obj *const*argv) \ 118 if (argc<2) throw ecolab::error("object name not specified"); \ 119 std::string name=Tcl_GetString(argv[1]); \ 121 ecolab::TCL_args largv(1,argv); \ 122 for (int i=2; i<argc; ++i) largv.pushObj(argv[i]); \ 123 x *object=new x contructorArgs; \ 124 ecolab::eraseAllNamesStartingWith(name); \ 125 TCL_obj(ecolab::null_TCL_obj,name,*object); \ 126 assert(ecolab::TCL_newcommand((name+".delete").c_str())); \ 127 Tcl_CreateCommand(ecolab::interp(), \ 128 (name+".delete").c_str(), \ 129 (Tcl_CmdProc*)deleteobject, \ 130 (ClientData)object,NULL); \ 136 Tcl_CreateObjCommand \ 137 (ecolab::interp(),#x, \ 138 (Tcl_ObjCmdProc*)createobject,NULL,NULL),1); \ 147 inline void tclret(
const T&) {}
149 inline void tclret(
const char& x) {tclreturn() << x;}
150 inline void tclret(
const signed char& x) {tclreturn() << x;}
151 inline void tclret(
const unsigned char& x) {tclreturn() << x;}
152 inline void tclret(
const int& x) {tclreturn() << x;}
153 inline void tclret(
const unsigned int& x) {tclreturn() << x;}
154 inline void tclret(
const long& x) {tclreturn() << x;}
155 inline void tclret(
const unsigned long& x) {tclreturn() << x;}
156 inline void tclret(
const short& x) {tclreturn() << x;}
157 inline void tclret(
const unsigned short& x) {tclreturn() << x;}
158 inline void tclret(
const bool& x) {tclreturn() << x;}
159 inline void tclret(
const float& x) {tclreturn() << x;}
160 inline void tclret(
const double& x) {tclreturn() << x;}
161 inline void tclret(
const long double& x) {tclreturn() << x;}
162 #if defined(__GNUC__) 163 inline void tclret(
const long long& x) {tclreturn() << x;}
164 inline void tclret(
const unsigned long long& x) {tclreturn() << x;}
168 inline void asgtclret(T& x,TCL_args& y) {}
173 inline void asgtclret(
int& x, TCL_args& y) {x=y;tclreturn() << x;}
174 inline void asgtclret(
unsigned int& x, TCL_args& y) {x=y;tclreturn() << x;}
175 inline void asgtclret(
long& x, TCL_args& y) {x=y;tclreturn() << x;}
179 inline void asgtclret(
bool& x, TCL_args& y) {x=y;tclreturn() << x;}
180 inline void asgtclret(
float& x, TCL_args& y) {x=y;tclreturn() << x;}
181 inline void asgtclret(
double& x, TCL_args& y) {x=y;tclreturn() << x;}
183 #if defined(__GNUC__) 189 inline bool is_simpletype(
const T& x) {
return false;}
191 inline bool is_simpletype(
const char& x) {
return true;}
192 inline bool is_simpletype(
const signed char& x) {
return true;}
193 inline bool is_simpletype(
const unsigned char& x) {
return true;}
194 inline bool is_simpletype(
const int& x) {
return true;}
195 inline bool is_simpletype(
const unsigned int& x) {
return true;}
196 inline bool is_simpletype(
const long& x) {
return true;}
197 inline bool is_simpletype(
const unsigned long& x) {
return true;}
198 inline bool is_simpletype(
const short& x) {
return true;}
199 inline bool is_simpletype(
const unsigned short& x) {
return true;}
200 inline bool is_simpletype(
const bool& x) {
return true;}
201 inline bool is_simpletype(
const float& x) {
return true;}
202 inline bool is_simpletype(
const double& x) {
return true;}
203 inline bool is_simpletype(
const long double& x) {
return true;}
204 #if defined(__GNUC__) 205 inline bool is_simpletype(
const long long& x) {
return true;}
206 inline bool is_simpletype(
const unsigned long long& x) {
return true;}
209 template <
class Object>
212 std::vector<int> dims;
217 for (i=0, idx=0; i<dims.size(); i++)
222 if (is_simpletype(o[idx]))
229 name=name.substr(0,name.rfind(
'.'));
231 name+=(
const char*)a[0];
232 for (
size_t i=1; i<dims.size(); i++)
235 name+=(
const char*)a[i];
245 for (i=0, idx=0; i<dims.size(); i++)
250 if (is_simpletype(o[idx]) )
273 for (
int i=0; i<dims; i++) ah->dims.push_back(va_arg(ap,
int));
279 get->name=desc+
".get";
280 TCL_OBJ_DBG(printf(
"registering %s\n",get->name.c_str()));
281 Tcl_CreateObjCommand(
interp(),get->name.c_str(),TCL_oproc,(ClientData)
get,NULL);
286 set->name=desc+
".set";
287 TCL_OBJ_DBG(printf(
"registering %s\n",set->name.c_str()));
288 Tcl_CreateObjCommand(
interp(),set->name.c_str(),TCL_oproc,(ClientData)
set,NULL);
294 {
if (arg) TCL_obj(targ,desc,*arg);}
298 {
if (arg) TCL_obj(targ,desc,*arg);}
301 template<
class T,
class CharT,
class Traits>
305 operator>>(std::basic_istream<CharT,Traits>& x,T& y)
307 throw error(
"operator>> not implemented for %s",
typeid(T).name());
311 template<
class T,
class CharT,
class Traits>
313 operator>>(std::basic_istream<CharT,Traits>& x,T& y)
333 {
if (a) o|*a;
return o;}
342 #if (defined(__osf__)) 347 s=
new char[strlen(s)+2]; strcpy((
char*)s,(
char*)os);
348 strcat((
char*)s,
" ");
351 std::istringstream r(s); r>>*memberptr;
353 #if (defined(__osf__)) 377 std::istream& operator>>(std::istream& s, std::string& x)
379 return std::operator>>(s,x);
385 if (!datum) name.clear();
387 if (name.length()) ::pack(buf,
"",*datum);
391 ::unpack(buf,
"",name);
394 ::unpack(buf,
"",*datum);
400 {std::istringstream s((
char*)a); s>>x;
return a;}
An RAII class for returning values to TCL.
Definition: tcl++.h:563
a slightly safer way of referring to registered objects than bare pointers
Definition: TCL_obj_base.h:449
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
classdesc::TCL_obj_t null_TCL_obj
a null TCL_obj_t suitable for nothing if needed.
Definition: TCL_obj_base.h:624
Definition: TCL_obj_base.h:330
Definition: TCL_obj_base.h:267
class to allow access to private members
Definition: classdesc_access.h:21
Definition: TCL_obj_base.h:632
Definition: TCL_obj_base.h:327
Definition: TCL_obj_stl.h:185
Definition: TCL_obj_templates.h:210
bool isa(const trialT &x, const baseT &y)
Definition: isa_base.h:69
Definition: TCL_obj_base.h:511
class to allow access to private members
Definition: classdesc_access.h:22
void TCL_obj_custom_register(const string &desc, T &arg)
a 'hook' to allow registrations to occur for TCL_objects (overriding base classes) ...
Definition: TCL_obj_base.h:668
controlled template specialisation: stolen from boost::enable_if.
Definition: TCL_obj_base.h:250
Represent arguments to TCL commands.
Definition: TCL_obj_base.h:138
Definition: TCL_obj_base.h:315
Definition: TCL_obj_templates.h:64
Definition: TCL_obj_base.h:364
Contains definitions related to classdesc functionality.
Definition: arrays.h:2514
Definition: pack_base.h:124
Definition: TCL_obj_base.h:124
_OPENMP
Definition: accessor.h:16
TCL_obj descriptor object.
Definition: TCL_obj_base.h:327
Definition: TCL_obj_base.h:27
Contains access_* structs, and nothing else. These structs are used to gain access to private members...
Definition: accessor.h:55
Definition: TCL_obj_base.h:631
Definition: TCL_obj_base.h:702