trick/trick_source/trick_swig/swig_extend_str.i
2015-02-26 09:02:31 -06:00

37 lines
799 B
OpenEdge ABL

/*
This extend directive allows users to print entire structs/classes with one command.
*/
%define %struct_str(TYPE)
%extend TYPE {
char * __str__() {
extern Trick::MemoryManager* trick_MM;
extern ATTRIBUTES attr##TYPE[] ;
std::stringstream os ;
Trick::PythonPrint pp ;
static char * temp = NULL ;
os.str("") ;
os << "[\n" ;
trick_MM->set_CheckPointAgent(&pp) ;
trick_MM->write_composite_var( os , (char *)self , attr##TYPE ) ;
trick_MM->reset_CheckPointAgent() ;
os << "]" ;
temp = (char *)realloc( (void *)temp , os.str().length() + 1 ) ;
strncpy(temp , os.str().c_str(), os.str().length()) ;
temp[os.str().length()] = '\0' ;
return temp ;
}
}
%enddef