KConfigXT: min/max checks in setters
Aaron J. Seigo
aseigo at kde.org
Sat Feb 19 19:42:43 GMT 2005
hi...
in the past kicker has had problems with dealing with configuration values
that were out of range. thankfully, the hand-written checks i did several
releases ago are no longer necessary as KConfigXT manages that via things
like min and max values.
however, i was concerned to notice that in the generated setters that these
min/max values are ignored. this is obviously suboptimal and can easily lead
to errors.
the attached patch resolves this issue. zack has had a quick look at it the
other day and didn't immediately die from shock. this is a good thing.
i do consider this a bug, and i'd like to get this in for 3.4 ... there is one
thing to note however, now the headers defined as needed in the kcfg[c] files
are now included in the generated header. this is to ensure that min/max
checks that us enums defined elsewhere continue to work (as is the case in
kicker).
please review.
--
Aaron J. Seigo
GPG Fingerprint: 8B8B 2209 0C6F 7C47 B1EA EE75 D6B7 2EB1 A7F1 DB43
-------------- next part --------------
Index: kconfig_compiler.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/kconfig_compiler.cpp,v
retrieving revision 1.63
diff -u -3 -d -p -r1.63 kconfig_compiler.cpp
--- kconfig_compiler.cpp 16 Feb 2005 19:59:11 -0000 1.63
+++ kconfig_compiler.cpp 18 Feb 2005 20:42:23 -0000
@@ -966,7 +966,14 @@ int main( int argc, char **argv )
if ( !singleton && cfgFileNameArg && parameters.isEmpty() )
h << "#include <kglobal.h>" << endl;
- h << "#include <kconfigskeleton.h>" << endl << endl;
+ h << "#include <kconfigskeleton.h>" << endl;
+ h << "#include <kdebug.h>" << endl << endl;
+
+ // Includes
+ for( it = includes.begin(); it != includes.end(); ++it ) {
+ h << "#include <" << *it << ">" << endl;
+ }
+
if ( !nameSpace.isEmpty() )
h << "namespace " << nameSpace << " {" << endl << endl;
@@ -1064,6 +1071,29 @@ int main( int argc, char **argv )
h << cppType(e->paramType()) << " i, ";
h << param( t ) << " v )" << endl;
h << " {" << endl;
+
+ if (!e->minValue().isEmpty())
+ {
+ h << " if (v < " << e->minValue() << ")" << endl;
+ h << " {" << endl;
+ h << " kdDebug() << \"" << setFunction(n);
+ h << ": value \" << v << \" is less than the minimum value of ";
+ h << e->minValue()<< "\" << endl;" << endl;
+ h << " return;" << endl;
+ h << " }" << endl;
+ }
+
+ if (!e->maxValue().isEmpty())
+ {
+ h << " if (v > " << e->maxValue() << ")" << endl;
+ h << " {" << endl;
+ h << " kdDebug() << \"" << setFunction(n);
+ h << ": value \" << v << \" is greater than the minimum value of ";
+ h << e->maxValue()<< "\" << endl;" << endl;
+ h << " return;" << endl;
+ h << " }" << endl;
+ }
+
h << " if (!" << This << "isImmutable( QString::fromLatin1( \"";
if (!e->param().isEmpty()) {
h << e->paramName().replace("$("+e->param()+")", "%1") << "\" ).arg( ";
@@ -1215,11 +1245,6 @@ int main( int argc, char **argv )
if ( setUserTexts ) cpp << "#include <klocale.h>" << endl << endl;
- // Includes
- for( it = includes.begin(); it != includes.end(); ++it ) {
- cpp << "#include <" << *it << ">" << endl;
- }
-
// Header required by singleton implementation
if ( singleton )
cpp << "#include <kstaticdeleter.h>" << endl << endl;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20050219/dc0ede2c/attachment.sig>
More information about the kde-core-devel
mailing list