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 ) {