[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kdecore/kconfig_compiler
From:       Albert Astals Cid <tsdgeos () terra ! es>
Date:       2009-07-02 19:27:06
Message-ID: 1246562826.756148.585.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 990590 by aacid:

noone vetoed for a week and it seems we don't have many kconfig_compiler experts let's commit it


 M  +62 -0     kconfig_compiler.cpp  


--- trunk/KDE/kdelibs/kdecore/kconfig_compiler/kconfig_compiler.cpp #990589:990590
@@ -363,7 +363,16 @@
   return result;
 }
 
+static QString getDefaultFunction(const QString &n, const QString &className = QString())
+{
+  QString result = "default"+n+"Value";
+  result[7] = result[7].toUpper();
 
+  if ( !className.isEmpty() )
+    result = className + "::" + result;
+  return result;
+}
+
 static QString getFunction(const QString &n, const QString &className = QString())
 {
   QString result = n;
@@ -1144,6 +1153,19 @@
   return result;
 }
 
+// returns the member get default implementation
+// which should go in the h file if inline
+// or the cpp file if not inline
+QString memberGetDefaultBody( CfgEntry *e )
+{
+  QString result = e->code();
+  QTextStream out(&result, QIODevice::WriteOnly);
+
+  out << "  return " << e->defaultValue() << ";" << endl;
+
+  return result;
+}
+
 // returns the item accesor implementation
 // which should go in the h file if inline
 // or the cpp file if not inline
@@ -1582,6 +1604,34 @@
       h << ";" << endl;
     }
 
+    // Default value Accessor
+    if (!(*itEntry)->defaultValue().isEmpty()) {
+      h << endl;
+      h << "    /**" << endl;
+      h << "      Get " << (*itEntry)->label() << " default value" << endl;
+      h << "    */" << endl;
+      if (staticAccessors)
+        h << "    static" << endl;
+      h << "    ";
+      if (useEnumTypes && t == "Enum")
+        h << enumType(*itEntry);
+      else
+        h << cppType(t);
+      h << " " << getDefaultFunction(n) << "()" << Const;
+      // function body inline only if not using dpointer
+      // for BC mode
+      if ( !dpointer )
+      {
+        h << endl << "    {" << endl;
+        h << indent(memberGetDefaultBody(*itEntry), 4 );
+        h << "    }" << endl;
+      }
+      else
+      {
+        h << ";" << endl;
+      }
+    }
+
     // Item accessor
     if ( itemAccessors ) {
       h << endl;
@@ -2045,6 +2095,18 @@
       cpp << indent(memberAccessorBody( *itEntry ), 2);
       cpp << "}" << endl << endl;
 
+      // Default value Accessor
+      if (!(*itEntry)->defaultValue().isEmpty()) {
+        if (useEnumTypes && t == "Enum")
+          cpp << enumType(*itEntry);
+        else
+          cpp << cppType(t);
+        cpp << " " << getDefaultFunction(n, className) << "()" << Const;
+        cpp << endl << "{" << endl;
+        cpp << memberGetDefaultBody(*itEntry);
+        cpp << "}" << endl << endl;
+      }
+
       // Item accessor
       if ( itemAccessors )
       {
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic