Make const string (arrays) in Kexi and CalligraDB really const

const char *x[] is still a variable, being an array of non-const pointers
to const chars, x[2] = anotherconststring; is still possible.
const char * const x[] is a const itself, x[2] = anotherconststring; no
longer possible. And is one indirection less when accessing the data,
because x is now the symbol of the actual data and not of the variable
keeping the address of the actual data.

REVIEW: 120326

Thanks Jarosław for review
parent f034826e
......@@ -357,7 +357,7 @@ QByteArray Driver::escapeIdentifier(const QByteArray& str, int options) const
}
}
void Driver::initDriverSpecificKeywords(const char** keywords)
void Driver::initDriverSpecificKeywords(const char* const* keywords)
{
d->driverSpecificSQLKeywords.setStrings(keywords);
}
......
......@@ -349,7 +349,7 @@ protected:
/*! Used to initialise the dictionary of driver-specific keywords.
Should be called by the Driver's constructor.
\a keywords should be 0-terminated array of null-terminated strings. */
void initDriverSpecificKeywords(const char** keywords);
void initDriverSpecificKeywords(const char* const* keywords);
/*! \return SQL statement @a sql modified by adding limiting command,
(if possible and if @add is true). Used for optimization for the server side.
......
......@@ -220,7 +220,7 @@ public:
front-end, even if they are not recognised by the backend to provide
UI consistency and to allow DB migration without changing the queries.
*/
static const char* kexiSQLKeywords[];
static const char* const kexiSQLKeywords[];
protected:
/*! Used by driver manager to initialize properties taken using internal
......
......@@ -80,7 +80,7 @@ protected:
SQLiteDriverPrivate * const dp;
private:
static const char *keywords[];
static const char * const keywords[];
};
......
......@@ -27,7 +27,7 @@
#include <sqlitedriver.h>
namespace KexiDB {
const char* SQLiteDriver::keywords[] = {
const char* const SQLiteDriver::keywords[] = {
"ABORT",
"ACTION",
"ADD",
......
......@@ -28,7 +28,7 @@
#include <driver_p.h>
namespace KexiDB {
const char* DriverPrivate::kexiSQLKeywords[] = {
const char* const DriverPrivate::kexiSQLKeywords[] = {
"AND",
"AS",
"ASC",
......
......@@ -1550,7 +1550,7 @@ public:
~Private() {
delete set;
}
const char** array;
const char* const * array;
QSet<QByteArray> *set;
};
......@@ -1559,7 +1559,7 @@ StaticSetOfStrings::StaticSetOfStrings()
{
}
StaticSetOfStrings::StaticSetOfStrings(const char* array[])
StaticSetOfStrings::StaticSetOfStrings(const char* const array[])
: d(new Private)
{
setStrings(array);
......@@ -1570,7 +1570,7 @@ StaticSetOfStrings::~StaticSetOfStrings()
delete d;
}
void StaticSetOfStrings::setStrings(const char* array[])
void StaticSetOfStrings::setStrings(const char* const array[])
{
delete d->set;
d->set = 0;
......@@ -1586,7 +1586,7 @@ bool StaticSetOfStrings::contains(const QByteArray& string) const
{
if (!d->set) {
d->set = new QSet<QByteArray>();
for (const char ** p = d->array;*p;p++) {
for (const char * const * p = d->array;*p;p++) {
d->set->insert(QByteArray::fromRawData(*p, qstrlen(*p)));
}
}
......
......@@ -536,9 +536,9 @@ class CALLIGRADB_EXPORT StaticSetOfStrings
{
public:
StaticSetOfStrings();
explicit StaticSetOfStrings(const char* array[]);
explicit StaticSetOfStrings(const char* const array[]);
~StaticSetOfStrings();
void setStrings(const char* array[]);
void setStrings(const char* const array[]);
bool isEmpty() const;
//! @return true if @a string can be found within set, comparison is case sensitive
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment