25 #include <tqtextstream.h>
27 #include <tqstringlist.h>
39 void generateStub(
const TQString& idl,
const TQString& filename, TQDomElement de)
41 TQFile stub( filename );
42 if ( !stub.open( IO_WriteOnly ) )
43 tqFatal(
"Could not write to %s", filename.local8Bit().data() );
45 TQTextStream str( &stub );
47 str <<
"/****************************************************************************" <<
endl;
49 str <<
"** DCOP Stub Definition created by dcopidl2cpp from " << idl <<
endl;
51 str <<
"** WARNING! All changes made in this file will be lost!" <<
endl;
53 str <<
"*****************************************************************************/" <<
endl;
56 TQString ifdefstring = idl.upper();
57 int pos = idl.findRev(
'.' );
59 ifdefstring = ifdefstring.left( pos );
61 TQString ifdefsuffix =
"_STUB__";
62 str <<
"#ifndef __" << ifdefstring << ifdefsuffix <<
endl;
63 str <<
"#define __" << ifdefstring << ifdefsuffix <<
endl <<
endl;
65 str <<
"#include <dcopstub.h>" <<
endl;
67 TQStringList includeslist, all_includes;
68 TQDomElement e = de.firstChild().toElement();
69 for( ; !e.isNull(); e = e.nextSibling().toElement() ) {
70 if ( e.tagName() ==
"INCLUDE" ) {
73 includeslist.prepend( e.firstChild().toText().data());
76 if( !includeslist.empty()) {
77 for( TQStringList::ConstIterator it = includeslist.begin();
78 it != includeslist.end();
80 str <<
"#include <" << ( *it ) <<
">" <<
endl;
81 all_includes.append( *it );
85 if ( e.tagName() !=
"CLASS" )
90 TQDomElement n = e.firstChild().toElement();
91 Q_ASSERT( n.tagName() ==
"NAME" );
92 TQString className = n.firstChild().toText().data() + (
"_stub" );
95 n = n.nextSibling().toElement();
97 if (n.tagName()==
"LINK_SCOPE") {
98 linkScope = n.firstChild().toText().data() +
" ";
99 n = n.nextSibling().toElement();
104 for( ; !n.isNull(); n = n.nextSibling().toElement() ) {
105 if ( n.tagName() ==
"SUPER" )
106 DCOPParent = n.firstChild().toText().data();
109 if( DCOPParent !=
"DCOPObject" ) {
110 if( all_includes.contains( DCOPParent +
".h" ))
111 str <<
"#include <" << DCOPParent <<
"_stub.h>" <<
endl;
112 else if( all_includes.contains( DCOPParent.lower() +
".h" ))
113 str <<
"#include <" << DCOPParent.lower() <<
"_stub.h>" <<
endl;
115 TQString stub_h = all_includes.last();
116 unsigned int pos = stub_h.find(
".h" );
118 stub_h = stub_h.remove( pos, 100000 );
119 str <<
"#include <" << stub_h <<
"_stub.h>" <<
endl;
122 str <<
"#include <" << stub_h <<
">" <<
endl;
126 TQString classNameFull = className;
128 int namespace_count = 0;
129 TQString namespace_tmp = className;
131 int pos = namespace_tmp.find(
"::" );
133 className = namespace_tmp;
136 str <<
"namespace " << namespace_tmp.left( pos ) <<
" {" <<
endl;
138 namespace_tmp = namespace_tmp.mid( pos + 2 );
144 str <<
"class " << linkScope << className;
147 if ( !DCOPParent.isEmpty() && DCOPParent !=
"DCOPObject" ) {
149 str <<
"virtual public " << DCOPParent <<
"_stub";
151 str <<
" : virtual public DCOPStub";
156 str <<
"public:" <<
endl;
159 str <<
" " << className <<
"( const TQCString& app, const TQCString& id );" <<
endl;
160 str <<
" " << className <<
"( DCOPClient* client, const TQCString& app, const TQCString& id );" <<
endl;
161 str <<
" explicit " << className <<
"( const DCOPRef& ref );" <<
endl;
163 n = e.firstChild().toElement();
164 for( ; !n.isNull(); n = n.nextSibling().toElement() ) {
165 if (n.tagName() !=
"FUNC")
167 TQDomElement r = n.firstChild().toElement();
171 r = r.nextSibling().toElement();
172 Q_ASSERT ( r.tagName() ==
"NAME" );
173 str << r.firstChild().toText().data() <<
"(";
176 r = r.nextSibling().toElement();
177 for( ; !r.isNull(); r = r.nextSibling().toElement() ) {
183 Q_ASSERT( r.tagName() ==
"ARG" );
184 TQDomElement a = r.firstChild().toElement();
186 a = a.nextSibling().toElement();
187 if ( a.tagName() ==
"NAME" )
188 str << a.firstChild().toText().data();
201 str <<
"protected:" <<
endl;
202 str <<
" " << className <<
"() : DCOPStub( never_use ) {}" <<
endl;
207 for(; namespace_count > 0; --namespace_count )
208 str <<
"} // namespace" <<
endl;
212 str <<
"#endif" <<
endl;
kndbgstream & endl(kndbgstream &s)