8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-02-02 10:00:38 +01:00

More const correctness

This commit is contained in:
asfernandes 2010-07-06 11:09:32 +00:00
parent ee99b63cc6
commit 2da3eee4e5
7 changed files with 68 additions and 39 deletions

View File

@ -503,7 +503,7 @@ void AggregatedStream::finiDistinct(thread_db* tdbb, jrd_req* request) const
}
SlidingWindow::SlidingWindow(thread_db* aTdbb, BaseBufferedStream* aStream, jrd_nod* aGroup,
SlidingWindow::SlidingWindow(thread_db* aTdbb, const BaseBufferedStream* aStream, jrd_nod* aGroup,
jrd_req* aRequest)
: tdbb(aTdbb), // Note: instanciate the class only as local variable
stream(aStream),

View File

@ -84,17 +84,17 @@ BufferedStream::BufferedStream(CompilerScratch* csb, RecordSource* next)
}
const size_t count = fields.getCount();
m_format = Format::newFormat(csb->csb_pool, count);
Format* format = Format::newFormat(csb->csb_pool, count);
ULONG offset = FLAG_BYTES(count);
for (size_t i = 0; i < count; i++)
{
dsc& desc = m_format->fmt_desc[i] = fields[i];
dsc& desc = format->fmt_desc[i] = fields[i];
if (desc.dsc_dtype >= dtype_aligned)
{
offset = FB_ALIGN(offset, type_alignments[desc.dsc_dtype]);
}
desc.dsc_address = (UCHAR *)(IPTR) offset;
desc.dsc_address = (UCHAR*)(IPTR) offset;
offset += desc.dsc_length;
}
@ -103,7 +103,8 @@ BufferedStream::BufferedStream(CompilerScratch* csb, RecordSource* next)
status_exception::raise(Arg::Gds(isc_imp_exc) << Arg::Gds(isc_blktoobig));
}
m_format->fmt_length = offset;
format->fmt_length = offset;
m_format = format;
}
void BufferedStream::open(thread_db* tdbb) const
@ -329,7 +330,7 @@ void BufferedStream::restoreRecords(thread_db* tdbb) const
m_next->restoreRecords(tdbb);
}
void BufferedStream::locate(thread_db* tdbb, FB_UINT64 position)
void BufferedStream::locate(thread_db* tdbb, FB_UINT64 position) const
{
jrd_req* const request = tdbb->getRequest();
Impure* const impure = request->getImpure<Impure>(m_impure);

View File

@ -103,8 +103,8 @@ bool NestedLoopJoin::getRecord(thread_db* tdbb) const
{
fb_assert(m_args.getCount() == 2);
RecordSource* const outer = m_args[0];
RecordSource* const inner = m_args[1];
const RecordSource* const outer = m_args[0];
const RecordSource* const inner = m_args[1];
if (impure->irsb_flags & irsb_first)
{
@ -289,7 +289,7 @@ void NestedLoopJoin::restoreRecords(thread_db* tdbb) const
bool NestedLoopJoin::fetchRecord(thread_db* tdbb, size_t n) const
{
RecordSource* const arg = m_args[n];
const RecordSource* const arg = m_args[n];
if (arg->getRecord(tdbb))
{

View File

@ -156,7 +156,7 @@ bool ProcedureScan::getRecord(thread_db* tdbb) const
}
jrd_req* const proc_request = impure->irsb_req_handle;
Format* const rec_format = m_format;
const Format* const rec_format = m_format;
const Format* const msg_format = (Format*) m_procedure->prc_output_msg->nod_arg[e_msg_format];
if (!impure->irsb_message)

View File

@ -132,7 +132,35 @@ namespace Jrd
protected:
const UCHAR m_stream;
Format* const m_format;
const Format* const m_format;
};
// Helper class to make const-correct nested record sources
template <typename T = RecordSource>
class NestedSource
{
public:
NestedSource(T* source)
: m_source(source)
{
}
NestedSource<T>& operator =(T* source)
{
m_source = source;
return *this;
}
operator T*() { return m_source; }
operator const T*() const { return m_source; }
T* operator ->() { return m_source; }
const T* operator ->() const { return m_source; }
private:
T* m_source;
};
@ -300,7 +328,7 @@ namespace Jrd
const UCHAR* msg, const dsc* to_desc, SSHORT to_id, Record* record) const;
const Firebird::string m_name;
jrd_prc* const m_procedure;
const jrd_prc* const m_procedure;
jrd_nod* const m_inputs;
jrd_nod* const m_message;
};
@ -331,7 +359,7 @@ namespace Jrd
void restoreRecords(thread_db* tdbb) const;
private:
RecordSource* const m_next;
NestedSource<> m_next;
};
class LockedStream : public RecordSource
@ -357,7 +385,7 @@ namespace Jrd
void restoreRecords(thread_db* tdbb) const;
private:
RecordSource* const m_next;
NestedSource<> m_next;
};
class FirstRowsStream : public RecordSource
@ -388,7 +416,7 @@ namespace Jrd
void restoreRecords(thread_db* tdbb) const;
private:
RecordSource* const m_next;
NestedSource<> m_next;
jrd_nod* const m_value;
};
@ -420,7 +448,7 @@ namespace Jrd
void restoreRecords(thread_db* tdbb) const;
private:
RecordSource* const m_next;
NestedSource<> m_next;
jrd_nod* const m_value;
};
@ -459,7 +487,7 @@ namespace Jrd
private:
bool evaluateBoolean(thread_db* tdbb) const;
RecordSource* const m_next;
NestedSource<> m_next;
jrd_nod* const m_boolean;
jrd_nod* m_anyBoolean;
bool m_ansiAny;
@ -555,22 +583,22 @@ namespace Jrd
private:
Sort* init(thread_db* tdbb) const;
RecordSource* const m_next;
SortMap* const m_map;
NestedSource<> m_next;
const SortMap* const m_map;
};
// Make moves in a window without going out of partition boundaries.
class SlidingWindow
{
public:
SlidingWindow(thread_db* aTdbb, BaseBufferedStream* aStream, jrd_nod* aGroup, jrd_req* aRequest);
SlidingWindow(thread_db* aTdbb, const BaseBufferedStream* aStream, jrd_nod* aGroup, jrd_req* aRequest);
~SlidingWindow();
bool move(SINT64 delta);
private:
thread_db* tdbb;
BaseBufferedStream* stream;
const BaseBufferedStream* const stream;
jrd_nod* group;
jrd_req* request;
Firebird::Array<impure_value> partitionKeys;
@ -621,8 +649,8 @@ namespace Jrd
State evaluateGroup(thread_db* tdbb, State state) const;
void finiDistinct(thread_db* tdbb, jrd_req* request) const;
BaseBufferedStream* m_bufferedStream;
RecordSource* const m_next;
NestedSource<BaseBufferedStream> m_bufferedStream;
NestedSource<> m_next;
jrd_nod* const m_group;
jrd_nod* const m_map;
jrd_nod* const m_order;
@ -652,15 +680,15 @@ namespace Jrd
void restoreRecords(thread_db* tdbb) const;
private:
BufferedStream* m_next;
RecordSource* m_joinedStream;
NestedSource<BufferedStream> m_next;
NestedSource<> m_joinedStream;
};
// Abstract class for different implementations of buffered streams.
class BaseBufferedStream : public RecordSource
{
public:
virtual void locate(thread_db* tdbb, FB_UINT64 position) = 0;
virtual void locate(thread_db* tdbb, FB_UINT64 position) const = 0;
virtual FB_UINT64 getCount(jrd_req* request) const = 0;
virtual FB_UINT64 getPosition(jrd_req* request) const = 0;
};
@ -712,7 +740,7 @@ namespace Jrd
void saveRecords(thread_db* tdbb) const;
void restoreRecords(thread_db* tdbb) const;
void locate(thread_db* tdbb, FB_UINT64 position);
void locate(thread_db* tdbb, FB_UINT64 position) const;
FB_UINT64 getCount(jrd_req* request) const;
FB_UINT64 getPosition(jrd_req* request) const
@ -722,9 +750,9 @@ namespace Jrd
}
private:
RecordSource* m_next;
NestedSource<> m_next;
Firebird::HalfStaticArray<FieldMap, OPT_STATIC_ITEMS> m_map;
Format* m_format;
const Format* m_format;
};
@ -760,7 +788,7 @@ namespace Jrd
const bool m_outerJoin;
const bool m_semiJoin;
const bool m_antiJoin;
Firebird::Array<RecordSource*> m_args;
Firebird::Array<NestedSource<> > m_args;
jrd_nod* const m_boolean;
};
@ -787,8 +815,8 @@ namespace Jrd
void restoreRecords(thread_db* tdbb) const;
private:
RecordSource* const m_arg1;
RecordSource* const m_arg2;
NestedSource<> m_arg1;
NestedSource<> m_arg2;
};
class HashJoin : public RecordSource

View File

@ -195,7 +195,7 @@ Sort* SortedStream::init(thread_db* tdbb) const
// Be careful to null field all unused bytes in the sort key.
const SortMap::Item* const end_item = m_map->items.begin() + m_map->items.getCount();
for (SortMap::Item* item = m_map->items.begin(); item < end_item; item++)
for (const SortMap::Item* item = m_map->items.begin(); item < end_item; item++)
{
to = item->desc;
to.dsc_address = data + (IPTR) to.dsc_address;
@ -271,7 +271,7 @@ Sort* SortedStream::init(thread_db* tdbb) const
SSHORT stream = -1;
const SortMap::Item* const end_item = m_map->items.begin() + m_map->items.getCount();
for (SortMap::Item* item = m_map->items.begin(); item < end_item; item++)
for (const SortMap::Item* item = m_map->items.begin(); item < end_item; item++)
{
if (item->node && item->node->nod_type != nod_field)
continue;
@ -309,7 +309,7 @@ void SortedStream::mapData(thread_db* tdbb, jrd_req* request, UCHAR* data) const
const SortMap::Item* const end_item = m_map->items.begin() + m_map->items.getCount();
for (SortMap::Item* item = m_map->items.begin(); item < end_item; item++)
for (const SortMap::Item* item = m_map->items.begin(); item < end_item; item++)
{
const UCHAR flag = *(data + item->flagOffset);
from = item->desc;

View File

@ -68,7 +68,7 @@ namespace
void saveRecords(thread_db* tdbb) const;
void restoreRecords(thread_db* tdbb) const;
void locate(thread_db* tdbb, FB_UINT64 position)
void locate(thread_db* tdbb, FB_UINT64 position) const
{
jrd_req* const request = tdbb->getRequest();
Impure* const impure = request->getImpure<Impure>(m_impure);
@ -87,7 +87,7 @@ namespace
}
public:
BufferedStream* m_next;
NestedSource<BufferedStream> m_next;
};
// Make join between outer stream and already sorted (aggregated) partition.
@ -421,12 +421,12 @@ namespace
// ------------------------------
WindowedStream::WindowedStream(CompilerScratch* csb, const jrd_nod* nodWindows, RecordSource* next)
: m_joinedStream(NULL)
: m_next(FB_NEW(csb->csb_pool) BufferedStream(csb, next)),
m_joinedStream(NULL)
{
thread_db* tdbb = JRD_get_thread_data();
m_impure = CMP_impure(csb, sizeof(Impure));
m_next = FB_NEW(csb->csb_pool) BufferedStream(csb, next);
// Process the unpartioned and unordered map, if existent.