[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: Re: kdelibs/kdecore/kconfig_compiler
From: Reinhold Kainhofer <reinhold () kainhofer ! com>
Date: 2004-06-26 9:50:33
Message-ID: 200406261150.33609.reinhold () kainhofer ! com
[Download RAW message or body]
Am Samstag, 26. Juni 2004 10:47 schrieb Reinhold Kainhofer:
> This might be done by something along the lines
> h<< enumName()+"MaxVal = 0xFFFF";
>
> I'd still like to add this, in particular since Zack's KConfigXT tutorial
> (http://developer.kde.org/documentation/tutorials/kconfigxt/kconfigxt.html)
> says:
> "Enum - This indicates an enumeration. The possible enum values should be
> provided via the <choices> tag. Enum values are accessed as integers by the
> application but stored as string in the configuration file. This makes it
> possible to add more values at a later date without breaking compatibility.
> "
Attached is a patch that does exactly this. It adds COUNT and MaxVal (or
enumNameCount and enumNameMaxVal if global enums are used).
The patch also adds the count to param enum, and I add checks in the mutators
to prevent reading elements from the array that don't exist.
I'd like to add these checks (given param value < available param values) also
to the accessors, but I don't know how to implement it. The accessor needs to
return a value, but which one in that case?
And third, the patch adjusts the checks (removes DQT_NO_CAST_ASCII from the
checks), so they validate again. Using DQT_NO_CAST_ASCII is just not possible
for the time being, so at least check for everything else.
Do you see any problems with this patch?
Reinhold
--
------------------------------------------------------------------
Reinhold Kainhofer, Vienna, Austria
email: reinhold@kainhofer.com, http://reinhold.kainhofer.com/
* Financial and Actuarial Mathematics, TU Wien, http://www.fam.tuwien.ac.at
* Deltasoft mathematics, http://www.deltasoft.at/
["2004-06-26_KConfigCompiler_MaxVal_CheckCount.diff" (text/x-diff)]
Index: kconfig_compiler.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/kconfig_compiler.cpp,v
retrieving revision 1.51
diff -u -p -3 -r1.51 kconfig_compiler.cpp
--- kconfig_compiler.cpp 25 Jun 2004 18:27:05 -0000 1.51
+++ kconfig_compiler.cpp 26 Jun 2004 09:43:53 -0000
@@ -930,19 +930,22 @@ int main( int argc, char **argv )
values.append( (*itChoice).name );
}
if ( globalEnums ) {
- h << " enum { " << values.join( ", " ) << " };" << endl;
+ h << " enum { " << values.join( ", " ) << ", " <<
+ enumName(e->name()) << "Count, " <<
+ enumName(e->name()) << "MaxVal = 0xFFFF };" << endl;
} else {
h << " class " << enumName(e->name()) << endl;
h << " {" << endl;
h << " public:" << endl;
- h << " enum { " << values.join( ", " ) << ", COUNT };" << endl;
+ h << " enum { " << values.join( ", " ) << ", COUNT, MaxVal = 0xFFFF };" \
<< endl; h << " };" << endl;
}
}
QStringList values = e->paramValues();
if ( !values.isEmpty() ) {
if ( globalEnums ) {
- h << " enum { " << values.join( ", " ) << ", COUNT };" << endl;
+ h << " enum { " << values.join( ", " ) << ", " <<
+ enumName(e->param()) << "Count };" << endl;
h << " static const char* const " << enumName(e->param()) << \
"ToString[];" << endl;
cppPreamble += "const char* const " + className + "::" + \
enumName(e->param()) + "ToString[] = " + "{ \"" + values.join( "\", \"" ) + "\" \
};\n"; @@ -1005,13 +1008,23 @@ int main( int argc, char **argv )
h << cppType(e->paramType()) << " i, ";
h << param( t ) << " v )" << endl;
h << " {" << endl;
+ if (!e->param().isEmpty()) {
+ if ( e->paramType() == "Enum" ) {
+ if (globalEnums)
+ h << " if (i<" << enumName(e->param()) << "Count) return;" << endl;
+ else
+ h << " if (i<" << enumName(e->param()) << "::COUNT) return;" << \
endl; + } else {
+ h << " if (i<=" << e->paramMax() << ") return;" << endl;
+ }
+ }
h << " if (!" << This << "isImmutable( QString::fromLatin1( \"";
if (!e->param().isEmpty()) {
h << e->paramName().replace("$("+e->param()+")", "%1") << "\" ).arg( ";
if ( e->paramType() == "Enum" ) {
h << "QString::fromLatin1( ";
if (globalEnums)
- h << enumName(e->name()) << "ToString[i]";
+ h << enumName(e->param()) << "ToString[i]";
else
h << enumName(e->param()) << "::enumToString[i]";
h << " )";
Index: tests/Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/tests/Makefile.am,v
retrieving revision 1.8
diff -u -p -3 -r1.8 Makefile.am
--- tests/Makefile.am 30 Mar 2004 17:03:16 -0000 1.8
+++ tests/Makefile.am 26 Jun 2004 09:43:53 -0000
@@ -1,4 +1,5 @@
-AM_CPPFLAGS = -I$(top_srcdir)/kdecore $(all_includes) -DQT_NO_CAST_ASCII
+AM_CPPFLAGS = -I$(top_srcdir)/kdecore $(all_includes)
+## -DQT_NO_CAST_ASCII
check_PROGRAMS = test1 test2 test3 test4
Index: tests/test1.cpp.ref
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/tests/test1.cpp.ref,v
retrieving revision 1.7
diff -u -p -3 -r1.7 test1.cpp.ref
--- tests/test1.cpp.ref 28 Mar 2004 00:34:25 -0000 1.7
+++ tests/test1.cpp.ref 26 Jun 2004 09:43:53 -0000
@@ -40,7 +40,7 @@ Test1::Test1( const QString &transport,
setCurrentGroup( QString::fromLatin1( "MyOptions" ) );
KConfigSkeleton::ItemString *itemMyString;
- itemMyString = new KConfigSkeleton::ItemString( currentGroup(), \
QString::fromLatin1( "MyString" ), mMyString, QString::fromLatin1( "Default String" ) \
); + itemMyString = new KConfigSkeleton::ItemString( currentGroup(), \
QString::fromLatin1( "MyString" ), mMyString, "Default String" ); addItem( \
itemMyString, QString::fromLatin1( "MyString" ) ); KConfigSkeleton::ItemPath \
*itemMyPath; itemMyPath = new KConfigSkeleton::ItemPath( currentGroup(), \
QString::fromLatin1( "MyPath" ), mMyPath, \
QDir::homeDirPath()+QString::fromLatin1(".hidden_file") );
Index: tests/test1.h.ref
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/tests/test1.h.ref,v
retrieving revision 1.5
diff -u -p -3 -r1.5 test1.h.ref
--- tests/test1.h.ref 28 Mar 2004 00:40:43 -0000 1.5
+++ tests/test1.h.ref 26 Jun 2004 09:43:53 -0000
@@ -11,7 +11,7 @@ class Test1 : public KConfigSkeleton
class EnumListOption
{
public:
- enum { One, Two, Three, COUNT };
+ enum { One, Two, Three, COUNT, MaxVal = 0xFFFF };
};
Test1( const QString &transport, const QString &folder );
Index: tests/test2.h.ref
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/tests/test2.h.ref,v
retrieving revision 1.5
diff -u -p -3 -r1.5 test2.h.ref
--- tests/test2.h.ref 24 Jun 2004 20:00:30 -0000 1.5
+++ tests/test2.h.ref 26 Jun 2004 09:43:53 -0000
@@ -10,7 +10,7 @@
class Test2 : public MyPrefs
{
public:
- enum { standardDestination, askDestination, argl1, argl2, argl3, COUNT };
+ enum { standardDestination, askDestination, argl1, argl2, argl3, \
EnumDestinationCount, EnumDestinationMaxVal = 0xFFFF };
Test2( );
~Test2();
Index: tests/test3.cpp.ref
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/tests/test3.cpp.ref,v
retrieving revision 1.4
diff -u -p -3 -r1.4 test3.cpp.ref
--- tests/test3.cpp.ref 28 Mar 2004 00:34:25 -0000 1.4
+++ tests/test3.cpp.ref 26 Jun 2004 09:43:53 -0000
@@ -17,7 +17,7 @@ Test3::Test3( )
mBlubbItem = new KConfigSkeleton::ItemInt( currentGroup(), QString::fromLatin1( \
"Blubb" ), mBlubb, 10 ); addItem( mBlubbItem, QString::fromLatin1( "Blubb" ) );
- mBlahBlahItem = new KConfigSkeleton::ItemString( currentGroup(), \
QString::fromLatin1( "BlahBlah" ), mBlahBlah, QString::fromLatin1( "a string" ) ); + \
mBlahBlahItem = new KConfigSkeleton::ItemString( currentGroup(), QString::fromLatin1( \
"BlahBlah" ), mBlahBlah, "a string" ); addItem( mBlahBlahItem, QString::fromLatin1( \
"BlahBlah" ) ); mMyPasswordItem = new KConfigSkeleton::ItemPassword( currentGroup(), \
QString::fromLatin1( "MyPassword" ), mMyPassword ); addItem( mMyPasswordItem, \
QString::fromLatin1( "MyPassword" ) );
Index: tests/test4.h.ref
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/tests/test4.h.ref,v
retrieving revision 1.5
diff -u -p -3 -r1.5 test4.h.ref
--- tests/test4.h.ref 24 Jun 2004 20:00:30 -0000 1.5
+++ tests/test4.h.ref 26 Jun 2004 09:43:53 -0000
@@ -11,7 +11,7 @@ class Test4 : public KConfigSkeleton
class EnumMouseAction
{
public:
- enum { Encrypt, Decrypt, CrashNBurn, PumpNDump, COUNT };
+ enum { Encrypt, Decrypt, CrashNBurn, PumpNDump, COUNT, MaxVal = 0xFFFF };
};
class EnumButton
{
@@ -29,6 +29,7 @@ class Test4 : public KConfigSkeleton
static
void setColor( int i, const QColor & v )
{
+ if (i<=3) return;
if (!self()->isImmutable( QString::fromLatin1( "Color%1" ).arg( i ) ))
self()->mColor[i] = v;
}
@@ -48,6 +49,7 @@ class Test4 : public KConfigSkeleton
static
void setMouseAction( int i, int v )
{
+ if (i<EnumButton::COUNT) return;
if (!self()->isImmutable( QString::fromLatin1( "MouseAction%1" ).arg( \
QString::fromLatin1( EnumButton::enumToString[i] ) ) )) self()->mMouseAction[i] = v;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic