mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-22 21:23:04 +01:00
Rename misleading TriStateType class name to Nullable
This commit is contained in:
parent
36f092fe0e
commit
3197757f00
132
src/common/classes/Nullable.h
Normal file
132
src/common/classes/Nullable.h
Normal file
@ -0,0 +1,132 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Initial
|
||||
* Developer's Public License Version 1.0 (the "License");
|
||||
* you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
||||
*
|
||||
* Software distributed under the License is distributed AS IS,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing rights
|
||||
* and limitations under the License.
|
||||
*
|
||||
* The Original Code was created by Adriano dos Santos Fernandes
|
||||
* for the Firebird Open Source RDBMS project.
|
||||
*
|
||||
* Copyright (c) 2010 Adriano dos Santos Fernandes <adrianosf@gmail.com>
|
||||
* and all contributors signed below.
|
||||
*
|
||||
* All Rights Reserved.
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
#ifndef CLASSES_NULLABLE_H
|
||||
#define CLASSES_NULLABLE_H
|
||||
|
||||
#include "firebird.h"
|
||||
#include "../common/classes/fb_string.h"
|
||||
#include "../common/classes/MetaName.h"
|
||||
|
||||
|
||||
// Auxiliary template to build a empty value.
|
||||
template <typename T> // Generic NullableClear
|
||||
class NullableClear
|
||||
{
|
||||
public:
|
||||
static void clear(T& v)
|
||||
{
|
||||
v = 0;
|
||||
}
|
||||
};
|
||||
|
||||
// NullableClear specializations.
|
||||
|
||||
template <>
|
||||
class NullableClear<Firebird::string> // string especialization for NullableClear
|
||||
{
|
||||
public:
|
||||
static void clear(Firebird::string& v)
|
||||
{
|
||||
v = "";
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class NullableClear<Firebird::MetaName> // MetaName especialization for NullableClear
|
||||
{
|
||||
public:
|
||||
static void clear(Firebird::MetaName& v)
|
||||
{
|
||||
v = "";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Nullable support without constructor, to allow usage in unions (used in the parser).
|
||||
template <typename T> class BaseNullable
|
||||
{
|
||||
public:
|
||||
static BaseNullable<T> val(const T& v)
|
||||
{
|
||||
BaseNullable<T> nullable;
|
||||
nullable.value = v;
|
||||
nullable.specified = true;
|
||||
return nullable;
|
||||
}
|
||||
|
||||
static BaseNullable<T> empty()
|
||||
{
|
||||
BaseNullable<T> nullable;
|
||||
NullableClear<T>::clear(nullable.value);
|
||||
nullable.specified = false;
|
||||
return nullable;
|
||||
}
|
||||
|
||||
bool operator ==(const BaseNullable<T>& o) const
|
||||
{
|
||||
return (!specified && !o.specified) || (specified == o.specified && value == o.value);
|
||||
}
|
||||
|
||||
public:
|
||||
T value;
|
||||
bool specified;
|
||||
};
|
||||
|
||||
|
||||
// Actual Nullable template.
|
||||
template <typename T> class Nullable : public BaseNullable<T>
|
||||
{
|
||||
public:
|
||||
explicit Nullable<T>(const T& v)
|
||||
{
|
||||
this->value = v;
|
||||
this->specified = true;
|
||||
}
|
||||
|
||||
Nullable<T>(const Nullable<T>& o)
|
||||
{
|
||||
this->value = o.value;
|
||||
this->specified = o.specified;
|
||||
}
|
||||
|
||||
Nullable<T>()
|
||||
{
|
||||
NullableClear<T>::clear(this->value);
|
||||
this->specified = false;
|
||||
}
|
||||
|
||||
void operator =(const BaseNullable<T>& o)
|
||||
{
|
||||
this->value = o.value;
|
||||
this->specified = o.specified;
|
||||
}
|
||||
|
||||
void operator =(const T& v)
|
||||
{
|
||||
this->value = v;
|
||||
this->specified = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // CLASSES_NULLABLE_H
|
@ -29,107 +29,6 @@
|
||||
#ifndef CLASSES_TRISTATE_H
|
||||
#define CLASSES_TRISTATE_H
|
||||
|
||||
#include "firebird.h"
|
||||
#include "../common/classes/fb_string.h"
|
||||
#include "../common/classes/MetaName.h"
|
||||
|
||||
|
||||
// Do not have constructor to allow usage in unions (used in the parser).
|
||||
template <typename T> class TriStateRawType
|
||||
{
|
||||
public:
|
||||
static TriStateRawType<T> val(const T& v)
|
||||
{
|
||||
TriStateRawType<T> triState;
|
||||
triState.value = v;
|
||||
triState.specified = true;
|
||||
return triState;
|
||||
}
|
||||
|
||||
static TriStateRawType<T> empty()
|
||||
{
|
||||
TriStateRawType<T> triState;
|
||||
triState.value = (T) 0;
|
||||
triState.specified = false;
|
||||
return triState;
|
||||
}
|
||||
|
||||
bool operator ==(const TriStateRawType<T>& o) const
|
||||
{
|
||||
return (!specified && !o.specified) || (specified == o.specified && value == o.value);
|
||||
}
|
||||
|
||||
public:
|
||||
T value;
|
||||
bool specified;
|
||||
};
|
||||
|
||||
|
||||
template <typename T> // Generic TriStateClear
|
||||
class TriStateClear
|
||||
{
|
||||
public:
|
||||
static void clear(T& v)
|
||||
{
|
||||
v = 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class TriStateClear<Firebird::string> // string especialization for TriStateClear
|
||||
{
|
||||
public:
|
||||
static void clear(Firebird::string& v)
|
||||
{
|
||||
v = "";
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
class TriStateClear<Firebird::MetaName> // MetaName especialization for TriStateClear
|
||||
{
|
||||
public:
|
||||
static void clear(Firebird::MetaName& v)
|
||||
{
|
||||
v = "";
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename T> class TriStateType : public TriStateRawType<T>
|
||||
{
|
||||
public:
|
||||
explicit TriStateType<T>(const T& v)
|
||||
{
|
||||
this->value = v;
|
||||
this->specified = true;
|
||||
}
|
||||
|
||||
TriStateType<T>(const TriStateType<T>& o)
|
||||
{
|
||||
this->value = o.value;
|
||||
this->specified = o.specified;
|
||||
}
|
||||
|
||||
TriStateType<T>()
|
||||
{
|
||||
TriStateClear<T>::clear(this->value);
|
||||
this->specified = false;
|
||||
}
|
||||
|
||||
void operator =(const TriStateRawType<T>& o)
|
||||
{
|
||||
this->value = o.value;
|
||||
this->specified = o.specified;
|
||||
}
|
||||
|
||||
void operator =(const T& v)
|
||||
{
|
||||
this->value = v;
|
||||
this->specified = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class TriState
|
||||
{
|
||||
|
@ -1079,7 +1079,7 @@ void CommentOnNode::execute(thread_db* tdbb, jrd_tra* transaction)
|
||||
return;
|
||||
}
|
||||
|
||||
TriStateType<string> description;
|
||||
Nullable<string> description;
|
||||
if (!text.isEmpty())
|
||||
description = attachment->stringToMetaCharSet(tdbb, text, textCharSet);
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
#include "../dsql/Nodes.h"
|
||||
#include "../common/classes/array.h"
|
||||
#include "../common/classes/ByteChunk.h"
|
||||
#include "../common/classes/TriState.h"
|
||||
#include "../common/classes/Nullable.h"
|
||||
#include "../dsql/errd_proto.h"
|
||||
|
||||
namespace Jrd {
|
||||
@ -470,9 +470,9 @@ protected:
|
||||
public:
|
||||
Firebird::MetaName name;
|
||||
Firebird::MetaName relationName;
|
||||
TriStateType<FB_UINT64> type;
|
||||
TriStateType<bool> active;
|
||||
TriStateType<int> position;
|
||||
Nullable<FB_UINT64> type;
|
||||
Nullable<bool> active;
|
||||
Nullable<int> position;
|
||||
ExternalClause* external;
|
||||
Firebird::string source;
|
||||
Firebird::ByteChunk blrData;
|
||||
@ -791,7 +791,7 @@ public:
|
||||
dsql_nod* setDefault;
|
||||
Firebird::MetaName renameTo;
|
||||
Firebird::AutoPtr<TypeClause> type;
|
||||
TriStateType<bool> nullFlag; // true = NULL / false = NOT NULL
|
||||
Nullable<bool> nullFlag; // true = NULL / false = NOT NULL
|
||||
};
|
||||
|
||||
|
||||
@ -1199,9 +1199,9 @@ public:
|
||||
|
||||
Firebird::MetaName relation;
|
||||
Firebird::ObjectsArray<Firebird::MetaName> columns;
|
||||
TriStateType<bool> unique;
|
||||
TriStateType<bool> descending;
|
||||
TriStateType<bool> inactive;
|
||||
Nullable<bool> unique;
|
||||
Nullable<bool> descending;
|
||||
Nullable<bool> inactive;
|
||||
SSHORT type;
|
||||
bid expressionBlr;
|
||||
bid expressionSource;
|
||||
|
@ -99,19 +99,19 @@ namespace
|
||||
MetaName fieldSource;
|
||||
MetaName fieldName;
|
||||
MetaName relationName;
|
||||
TriStateType<SSHORT> collationId;
|
||||
TriStateType<SSHORT> nullFlag;
|
||||
Nullable<SSHORT> collationId;
|
||||
Nullable<SSHORT> nullFlag;
|
||||
SSHORT mechanism;
|
||||
TriStateType<SSHORT> fieldLength;
|
||||
TriStateType<SSHORT> fieldScale;
|
||||
TriStateType<SSHORT> fieldType;
|
||||
TriStateType<SSHORT> fieldSubType;
|
||||
TriStateType<SSHORT> fieldSegmentLength;
|
||||
TriStateType<SSHORT> fieldNullFlag;
|
||||
TriStateType<SSHORT> fieldCharLength;
|
||||
TriStateType<SSHORT> fieldCollationId;
|
||||
TriStateType<SSHORT> fieldCharSetId;
|
||||
TriStateType<SSHORT> fieldPrecision;
|
||||
Nullable<SSHORT> fieldLength;
|
||||
Nullable<SSHORT> fieldScale;
|
||||
Nullable<SSHORT> fieldType;
|
||||
Nullable<SSHORT> fieldSubType;
|
||||
Nullable<SSHORT> fieldSegmentLength;
|
||||
Nullable<SSHORT> fieldNullFlag;
|
||||
Nullable<SSHORT> fieldCharLength;
|
||||
Nullable<SSHORT> fieldCollationId;
|
||||
Nullable<SSHORT> fieldCharSetId;
|
||||
Nullable<SSHORT> fieldPrecision;
|
||||
|
||||
// Not compared
|
||||
bid defaultSource;
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "../dsql/WinNodes.h"
|
||||
#include "../dsql/PackageNodes.h"
|
||||
#include "../dsql/StmtNodes.h"
|
||||
#include "../common/classes/TriState.h"
|
||||
#include "../common/classes/Nullable.h"
|
||||
#include "../common/classes/stack.h"
|
||||
|
||||
#define _yacc_defines_keywords
|
||||
@ -167,7 +167,7 @@ private:
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void setClause(TriStateType<T>& clause, const char* duplicateMsg, const T& value)
|
||||
void setClause(Nullable<T>& clause, const char* duplicateMsg, const T& value)
|
||||
{
|
||||
using namespace Firebird;
|
||||
if (clause.specified)
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "../dsql/PackageNodes.h"
|
||||
#include "../dsql/StmtNodes.h"
|
||||
#include "../dsql/WinNodes.h"
|
||||
#include "../common/classes/TriState.h"
|
||||
#include "../common/classes/Nullable.h"
|
||||
#include "dsql.tab.h"
|
||||
#include "Parser.h"
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include "../dsql/PackageNodes.h"
|
||||
#include "../dsql/StmtNodes.h"
|
||||
#include "../dsql/WinNodes.h"
|
||||
#include "../common/classes/TriState.h"
|
||||
#include "../common/classes/Nullable.h"
|
||||
#include "dsql.tab.h"
|
||||
#include "keywords.h"
|
||||
|
||||
|
@ -609,15 +609,14 @@ inline void check_copy_incr(char*& to, const char ch, const char* const string)
|
||||
|
||||
%union
|
||||
{
|
||||
TriStateRawType<int> triIntVal;
|
||||
TriStateRawType<bool> triBoolVal;
|
||||
BaseNullable<int> nullableIntVal;
|
||||
BaseNullable<bool> nullableBoolVal;
|
||||
bool boolVal;
|
||||
int intVal;
|
||||
unsigned uintVal;
|
||||
SLONG int32Val;
|
||||
FB_UINT64 uint64Val;
|
||||
TriStateRawType<unsigned> triUintVal;
|
||||
TriStateRawType<FB_UINT64> triUint64Val;
|
||||
BaseNullable<FB_UINT64> nullableUint64Val;
|
||||
Jrd::dsql_nod* legacyNode;
|
||||
Jrd::dsql_str* legacyStr;
|
||||
Jrd::dsql_fld* legacyField;
|
||||
@ -848,12 +847,12 @@ inline void check_copy_incr(char*& to, const char ch, const char* const string)
|
||||
%type alter_domain_ops(<alterDomainNode>)
|
||||
%type alter_domain_op(<alterDomainNode>)
|
||||
|
||||
%type <triBoolVal> trigger_active
|
||||
%type <nullableBoolVal> trigger_active
|
||||
%type <uint64Val> trigger_db_type trigger_ddl_type trigger_ddl_type_items trigger_type
|
||||
%type <uint64Val> trigger_type_prefix trigger_type_suffix
|
||||
%type <triUint64Val> trigger_type_opt
|
||||
%type <nullableUint64Val> trigger_type_opt
|
||||
%type <createAlterTriggerNode> alter_trigger_clause replace_trigger_clause trigger_clause
|
||||
%type <triIntVal> trigger_position
|
||||
%type <nullableIntVal> trigger_position
|
||||
|
||||
%type <legacyNode> symbol_package_name
|
||||
%type <createAlterPackageNode> alter_package_clause package_clause replace_package_clause
|
||||
@ -2920,11 +2919,11 @@ replace_trigger_clause
|
||||
|
||||
trigger_active
|
||||
: ACTIVE
|
||||
{ $$ = TriStateRawType<bool>::val(true); }
|
||||
{ $$ = Nullable<bool>::val(true); }
|
||||
| INACTIVE
|
||||
{ $$ = TriStateRawType<bool>::val(false); }
|
||||
{ $$ = Nullable<bool>::val(false); }
|
||||
|
|
||||
{ $$ = TriStateRawType<bool>::empty(); }
|
||||
{ $$ = Nullable<bool>::empty(); }
|
||||
;
|
||||
|
||||
trigger_type
|
||||
@ -3045,9 +3044,9 @@ trigger_type_suffix
|
||||
|
||||
trigger_position
|
||||
: POSITION nonneg_short_integer
|
||||
{ $$ = TriStateRawType<int>::val($2); }
|
||||
{ $$ = Nullable<int>::val($2); }
|
||||
|
|
||||
{ $$ = TriStateRawType<int>::empty(); }
|
||||
{ $$ = Nullable<int>::empty(); }
|
||||
;
|
||||
|
||||
// ALTER statement
|
||||
@ -3424,9 +3423,9 @@ alter_trigger_clause
|
||||
|
||||
trigger_type_opt // we do not allow alter database triggers, hence we do not use trigger_type here
|
||||
: trigger_type_prefix trigger_type_suffix
|
||||
{ $$ = TriStateRawType<FB_UINT64>::val($1 + $2 - 1); }
|
||||
{ $$ = Nullable<FB_UINT64>::val($1 + $2 - 1); }
|
||||
|
|
||||
{ $$ = TriStateRawType<FB_UINT64>::empty(); }
|
||||
{ $$ = Nullable<FB_UINT64>::empty(); }
|
||||
;
|
||||
|
||||
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "../common/classes/auto.h"
|
||||
#include "../common/classes/fb_string.h"
|
||||
#include "../common/classes/MetaName.h"
|
||||
#include "../common/classes/TriState.h"
|
||||
#include "../common/classes/Nullable.h"
|
||||
|
||||
namespace Jrd {
|
||||
|
||||
@ -101,7 +101,7 @@ public:
|
||||
public:
|
||||
// Output variables.
|
||||
|
||||
template <typename T> OutputParam operator ()(const char* chunk, TriStateType<T>& param)
|
||||
template <typename T> OutputParam operator ()(const char* chunk, Nullable<T>& param)
|
||||
{
|
||||
OutputParam ret = (*this)(chunk, param.value);
|
||||
outputSlots[outputSlots.getCount() - 1].specifiedAddress = ¶m.specified;
|
||||
@ -132,7 +132,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T> Builder& operator <<(const TriStateType<T>& param)
|
||||
template <typename T> Builder& operator <<(const Nullable<T>& param)
|
||||
{
|
||||
*this << param.value;
|
||||
inputSlots[inputSlots.getCount() - 1].specifiedAddress = ¶m.specified;
|
||||
|
Loading…
Reference in New Issue
Block a user