|
@@ -18,6 +18,11 @@
|
|
|
#ifndef ECLHELPER_BASE_HPP
|
|
|
#define ECLHELPER_BASE_HPP
|
|
|
|
|
|
+// NOTE: this file must not be included OTHER than from generated code, unless inside a namespace,
|
|
|
+// since it is important that the correct implementation of selectInterface (the one from the generated DLL) is used.
|
|
|
+// Only the base classes for Activity helpers - CHThorArg and derived classes - should be included in this file.
|
|
|
+// All code should be implemented inline.
|
|
|
+
|
|
|
//Don't #include any files here - because sometimes included inside a namespace, and that generates confusion.
|
|
|
|
|
|
/*
|
|
@@ -28,305 +33,6 @@ Doesn't include jlib.hpp yet, so different implementation of CInterface (RtlCInt
|
|
|
*/
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
-// Record size handling.
|
|
|
-
|
|
|
-class CGlobalHelperClass : public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- inline CGlobalHelperClass(unsigned _activityId) { activityId = _activityId; ctx = NULL; }
|
|
|
-
|
|
|
- inline void onCreate(ICodeContext * _ctx) { ctx = _ctx; }
|
|
|
-
|
|
|
-protected:
|
|
|
- ICodeContext * ctx;
|
|
|
- unsigned activityId;
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
-class COutputRowSerializer : implements IOutputRowSerializer, public CGlobalHelperClass
|
|
|
-{
|
|
|
-public:
|
|
|
- inline COutputRowSerializer(unsigned _activityId) : CGlobalHelperClass(_activityId) { }
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
- virtual void serialize(IRowSerializerTarget & out, const byte * self) = 0;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-class COutputRowDeserializer : implements IOutputRowDeserializer, public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- inline COutputRowDeserializer(unsigned _activityId) { activityId = _activityId; ctx = NULL; }
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
- inline void onCreate(ICodeContext * _ctx) { ctx = _ctx; }
|
|
|
-
|
|
|
- virtual size32_t deserialize(ARowBuilder & rowBuilder, IRowDeserializerSource & in) = 0;
|
|
|
-
|
|
|
-protected:
|
|
|
- ICodeContext * ctx;
|
|
|
- unsigned activityId;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-class CSourceRowPrefetcher : implements ISourceRowPrefetcher, public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- inline CSourceRowPrefetcher(unsigned _activityId) { activityId = _activityId; ctx = NULL; }
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
- inline void onCreate(ICodeContext * _ctx) { ctx = _ctx; }
|
|
|
-
|
|
|
- virtual void readAhead(IRowDeserializerSource & in) = 0;
|
|
|
-
|
|
|
-protected:
|
|
|
- ICodeContext * ctx;
|
|
|
- unsigned activityId;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-class CFixedOutputRowSerializer : public COutputRowSerializer
|
|
|
-{
|
|
|
-public:
|
|
|
- inline CFixedOutputRowSerializer(unsigned _activityId, unsigned _fixedSize) : COutputRowSerializer(_activityId) { fixedSize = _fixedSize; }
|
|
|
-
|
|
|
- virtual void serialize(IRowSerializerTarget & out, const byte * self) { out.put(fixedSize, self); }
|
|
|
-
|
|
|
-protected:
|
|
|
- size32_t fixedSize;
|
|
|
-};
|
|
|
-
|
|
|
-class CFixedOutputRowDeserializer : public COutputRowDeserializer
|
|
|
-{
|
|
|
-public:
|
|
|
- inline CFixedOutputRowDeserializer(unsigned _activityId, unsigned _fixedSize) : COutputRowDeserializer(_activityId) { fixedSize = _fixedSize; }
|
|
|
-
|
|
|
- virtual size32_t deserialize(ARowBuilder & rowBuilder, IRowDeserializerSource & in) { in.read(fixedSize, rowBuilder.getSelf()); return fixedSize; }
|
|
|
-
|
|
|
-protected:
|
|
|
- size32_t fixedSize;
|
|
|
-};
|
|
|
-
|
|
|
-class CFixedSourceRowPrefetcher : public CSourceRowPrefetcher
|
|
|
-{
|
|
|
-public:
|
|
|
- inline CFixedSourceRowPrefetcher(unsigned _activityId, unsigned _fixedSize) : CSourceRowPrefetcher(_activityId) { fixedSize = _fixedSize; }
|
|
|
-
|
|
|
- virtual void readAhead(IRowDeserializerSource & in) { in.skip(fixedSize); }
|
|
|
-
|
|
|
-protected:
|
|
|
- size32_t fixedSize;
|
|
|
-};
|
|
|
-
|
|
|
-class CVariableOutputRowSerializer : public COutputRowSerializer
|
|
|
-{
|
|
|
-public:
|
|
|
- inline CVariableOutputRowSerializer(unsigned _activityId, IOutputMetaData * _meta) : COutputRowSerializer(_activityId) { meta = _meta; }
|
|
|
-
|
|
|
- virtual void serialize(IRowSerializerTarget & out, const byte * self)
|
|
|
- {
|
|
|
- unsigned size = meta->getRecordSize(self);
|
|
|
- out.put(size, self);
|
|
|
- }
|
|
|
-
|
|
|
-protected:
|
|
|
- IOutputMetaData * meta;
|
|
|
-};
|
|
|
-
|
|
|
-class COutputMetaData : implements IOutputMetaData, public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
- virtual void toXML(const byte * self, IXmlWriter & out) {
|
|
|
- const RtlTypeInfo * type = queryTypeInfo();
|
|
|
- if (type)
|
|
|
- {
|
|
|
- RtlFieldStrInfo dummyField("",NULL,type);
|
|
|
- type->toXML(self, self, &dummyField, out);
|
|
|
- }
|
|
|
- }
|
|
|
- virtual unsigned getVersion() const { return OUTPUTMETADATA_VERSION; }
|
|
|
- virtual unsigned getMetaFlags() { return MDFhasserialize|MDFhasxml; }
|
|
|
-
|
|
|
- virtual void destruct(byte * self) {}
|
|
|
- virtual IOutputMetaData * querySerializedDiskMeta() { return this; }
|
|
|
- virtual IOutputRowSerializer * createDiskSerializer(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return new CVariableOutputRowSerializer(activityId, this);
|
|
|
- }
|
|
|
- virtual ISourceRowPrefetcher * createDiskPrefetcher(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- ISourceRowPrefetcher * fetcher = defaultCreateDiskPrefetcher(ctx, activityId);
|
|
|
- if (fetcher)
|
|
|
- return fetcher;
|
|
|
- //Worse case implementation using a deserialize
|
|
|
- return new CSimpleSourceRowPrefetcher(*this, ctx, activityId);
|
|
|
- }
|
|
|
- //Default internal serializers are the same as the disk versions
|
|
|
- virtual IOutputRowSerializer * createInternalSerializer(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return createDiskSerializer(ctx, activityId);
|
|
|
- }
|
|
|
- virtual IOutputRowDeserializer * createInternalDeserializer(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return createDiskDeserializer(ctx, activityId);
|
|
|
- }
|
|
|
- virtual void walkIndirectMembers(const byte * self, IIndirectMemberVisitor & visitor) { }
|
|
|
- virtual IOutputMetaData * queryChildMeta(unsigned i) { return NULL; }
|
|
|
-
|
|
|
-protected:
|
|
|
- //This is the prefetch function that is actually generated by the code generator
|
|
|
- virtual CSourceRowPrefetcher * doCreateDiskPrefetcher(unsigned activityId) { return NULL; }
|
|
|
-
|
|
|
- inline ISourceRowPrefetcher * defaultCreateDiskPrefetcher(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- if (getMetaFlags() & MDFneedserializedisk)
|
|
|
- return querySerializedDiskMeta()->createDiskPrefetcher(ctx, activityId);
|
|
|
- CSourceRowPrefetcher * fetcher = doCreateDiskPrefetcher(activityId);
|
|
|
- if (fetcher)
|
|
|
- {
|
|
|
- fetcher->onCreate(ctx);
|
|
|
- return fetcher;
|
|
|
- }
|
|
|
- return NULL;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-class CFixedOutputMetaData : public COutputMetaData
|
|
|
-{
|
|
|
-public:
|
|
|
- CFixedOutputMetaData(size32_t _fixedSize) { fixedSize = _fixedSize; }
|
|
|
-
|
|
|
- virtual size32_t getRecordSize(const void *rec) { return fixedSize; }
|
|
|
- virtual size32_t getMinRecordSize() const { return fixedSize; }
|
|
|
- virtual size32_t getFixedSize() const { return fixedSize; }
|
|
|
-
|
|
|
- virtual IOutputRowSerializer * createDiskSerializer(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return new CFixedOutputRowSerializer(activityId, fixedSize);
|
|
|
- }
|
|
|
- virtual IOutputRowDeserializer * createDiskDeserializer(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return new CFixedOutputRowDeserializer(activityId, fixedSize);
|
|
|
- }
|
|
|
- virtual ISourceRowPrefetcher * createDiskPrefetcher(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- ISourceRowPrefetcher * fetcher = defaultCreateDiskPrefetcher(ctx, activityId);
|
|
|
- if (fetcher)
|
|
|
- return fetcher;
|
|
|
- return new CFixedSourceRowPrefetcher(activityId, fixedSize);
|
|
|
- }
|
|
|
-
|
|
|
-protected:
|
|
|
- size32_t fixedSize;
|
|
|
-};
|
|
|
-
|
|
|
-class CVariableOutputMetaData : public COutputMetaData
|
|
|
-{
|
|
|
-public:
|
|
|
- CVariableOutputMetaData(size32_t _minSize) : minSize(_minSize) { }
|
|
|
-
|
|
|
- virtual size32_t getMinRecordSize() const { return minSize; }
|
|
|
- virtual size32_t getFixedSize() const { return 0; } // is variable
|
|
|
-
|
|
|
-protected:
|
|
|
- size32_t minSize;
|
|
|
-};
|
|
|
-
|
|
|
-class CActionOutputMetaData : public COutputMetaData
|
|
|
-{
|
|
|
-public:
|
|
|
- virtual size32_t getRecordSize(const void *) { return 0; }
|
|
|
- virtual size32_t getMinRecordSize() const { return 0; }
|
|
|
- virtual size32_t getFixedSize() const { return 0; } // is pseudo-variable
|
|
|
- virtual void toXML(const byte * self, IXmlWriter & out) { }
|
|
|
- virtual IOutputRowSerializer * createDiskSerializer(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return new CFixedOutputRowSerializer(activityId, 0);
|
|
|
- }
|
|
|
- virtual IOutputRowDeserializer * createDiskDeserializer(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return new CFixedOutputRowDeserializer(activityId, 0);
|
|
|
- }
|
|
|
- virtual ISourceRowPrefetcher * createDiskPrefetcher(ICodeContext * ctx, unsigned activityId)
|
|
|
- {
|
|
|
- return new CFixedSourceRowPrefetcher(activityId, 0);
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-
|
|
|
-class CXmlToRowTransformer : implements IXmlToRowTransformer, public CGlobalHelperClass
|
|
|
-{
|
|
|
-public:
|
|
|
- inline CXmlToRowTransformer(unsigned _activityId) : CGlobalHelperClass(_activityId) {}
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
-// Record size handling.
|
|
|
-
|
|
|
-class ThorHelper : public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- ThorHelper() { ctx = 0; }
|
|
|
-
|
|
|
-protected:
|
|
|
- ICodeContext * ctx;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
-class CNormalizeChildIterator : implements INormalizeChildIterator, public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- CNormalizeChildIterator(IOutputMetaData & _recordSize) : iter(0, NULL, _recordSize) {}
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
- virtual byte * first(const void * parentRecord) { init(parentRecord); return (byte *)iter.first(); }
|
|
|
- virtual byte * next() { return (byte *)iter.next(); }
|
|
|
- virtual void init(const void * parentRecord) = 0;
|
|
|
-
|
|
|
- inline void setDataset(size32_t len, const void * data) { iter.setDataset(len, data); }
|
|
|
-
|
|
|
-protected:
|
|
|
- RtlVariableDatasetCursor iter;
|
|
|
-};
|
|
|
-
|
|
|
-class CNormalizeLinkedChildIterator : implements INormalizeChildIterator, public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- CNormalizeLinkedChildIterator() : iter(0, NULL) {}
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
- virtual byte * first(const void * parentRecord) { init(parentRecord); return (byte *)iter.first(); }
|
|
|
- virtual byte * next() { return (byte *)iter.next(); }
|
|
|
- virtual void init(const void * parentRecord) = 0;
|
|
|
-
|
|
|
- inline void setDataset(unsigned _numRows, byte * * _rows) { iter.setDataset(_numRows, _rows); }
|
|
|
-
|
|
|
-protected:
|
|
|
- RtlSafeLinkedDatasetCursor iter;
|
|
|
-};
|
|
|
-
|
|
|
-class CNormalizeStreamedChildIterator : implements INormalizeChildIterator, public RtlCInterface
|
|
|
-{
|
|
|
-public:
|
|
|
- CNormalizeStreamedChildIterator() {}
|
|
|
- RTLIMPLEMENT_IINTERFACE
|
|
|
-
|
|
|
- virtual byte * first(const void * parentRecord) { init(parentRecord); return (byte *)iter.first(); }
|
|
|
- virtual byte * next() { return (byte *)iter.next(); }
|
|
|
- virtual void init(const void * parentRecord) = 0;
|
|
|
-
|
|
|
- inline void setDataset(IRowStream * _streamed) { iter.init(_streamed); }
|
|
|
-
|
|
|
-protected:
|
|
|
- RtlStreamedDatasetCursor iter;
|
|
|
-};
|
|
|
-
|
|
|
-//---------------------------------------------------------------------------
|
|
|
|
|
|
class CThorArg : public RtlCInterface
|
|
|
{
|