Extending kconfig_compiler with some convenience method

Andreas Pakulat apaku at gmx.de
Thu Mar 29 21:26:40 BST 2007


Hi,

currently kconfig_compiler creates a instance(const char*) when using
args=true and a singleton. However I think most applications would have
the filename in a QString. The attached patch adds an instance(const
QString& ) to the generated class, which moves the needed

QByteArray b = filename.toLocal8Bit();
b.data()

into the generated class so users don't need to think about this.

Any objections against adding this?

Andreas

-- 
Your society will be sought by people of taste and refinement.
-------------- next part --------------
Index: kconfig_compiler.cpp
===================================================================
--- kconfig_compiler.cpp	(Revision 647263)
+++ kconfig_compiler.cpp	(Arbeitskopie)
@@ -1416,7 +1416,10 @@ int main( int argc, char **argv )
   } else {
     h << "    static " << className << " *self();" << endl;
     if (cfgFileNameArg)
+    {
       h << "    static void instance(const char * cfgfilename);" << endl;
+      h << "    static void instance(const QString& cfgfilename);" << endl;
+    }
   }
 
   // Destructor
@@ -1728,6 +1731,16 @@ int main( int argc, char **argv )
       cpp << "  static" << className << "Deleter.setObject( mSelf, new " << className << "(cfgfilename) );" << endl;
       cpp << "  mSelf->readConfig();" << endl;
       cpp << "}" << endl << endl;
+      cpp << "void " << className << "::instance(const QString& cfgfilename)" << endl;
+      cpp << "{" << endl;
+      cpp << "  if (mSelf) {" << endl;
+      cpp << "     kDebug() << \"" << className << "::instance called after the first use - ignoring\" << endl;" << endl;
+      cpp << "     return;" << endl;
+      cpp << "  }" << endl;
+      cpp << "  QByteArray filename = cfgfilename.toLocal8Bit();" << endl;
+      cpp << "  static" << className << "Deleter.setObject( mSelf, new " << className << "(filename.data()) );" << endl;
+      cpp << "  mSelf->readConfig();" << endl;
+      cpp << "}" << endl << endl;
     }
   }
 


More information about the kde-core-devel mailing list