|
Contents:
Search: |
SheafOverviewThe sheaf is the datastructure returned by the "SELECT (ALL|FOCUS) OBJECTS" query. See the MQL User's Guide Chapter 4 for a description of the sheaf. Briefly, a sheaf is a list of straws. A straw is a list of matched_objects. A matched_object may have an inner sheaf, which makes the datastructure recursive. A matched_object corresponds to an object_block(_first) or (opt_)gap_block in a topographic MQL query. A straw corresponds to a block_string. A sheaf corresponds to a blocks. Java-style iterators are provided. C++ interface
#include <emdros/mql_sheaf.h>
typedef enum {
kMOKNIL_mo, // Used only while building sheaf, never in finished sheaf
kMOKEMPTY_mo, // Used only while building sheaf, never in finished sheaf
kMOKID_D, // Match of object_block(_first)
kMOKID_M // Match of (opt_)gap_block
} eMOKind;
class CMatched_object {
public:
CMatched_object(const CMatched_object{PREAMP} other);
~CMatched_object();
const CSet_of_monad_ms{PREAMP} get_monads(void) const;
id_d_t get_id_d(void) const;
const CSheaf* get_sheaf(void) const;
bool sheaf_is_empty(void) const;
eMOKind get_kind(void) const;
bool get_focus(void) const;
CMatched_object{PREAMP} operator=(const CMatched_object{PREAMP} other); // Not SWIG-wrapped
short int get_object_type_index(void) const { return m_object_type_index; };
void put_Console(CEMdFOutput *pOut) const;
void put_XML(CEMdFOutput* pOut) const;
};
class StrawConstIterator {
public:
StrawConstIterator(const CStraw *pMotherStraw);
StrawConstIterator();
StrawConstIterator(const StrawConstIterator{PREAMP} other);
~StrawConstIterator();
bool hasNext() const; // Is the iterator == end iterator? Doesn't alter iterator
const CMatched_object* next(); // Gets current and advances iterator afterwards
const CMatched_object* previous(); // Regresses iterator and then gets current
const CMatched_object* current(); // Gets current without altering iterator
};
class CStraw {
private:
friend class StrawConstIterator;
monad_m m_last;
MOList m_list;
public:
~CStraw();
CStraw(const CStraw{PREAMP} other);
StrawConstIterator const_iterator() const;
CStraw{PREAMP} operator=(const CStraw{PREAMP} other); // Not SWIG-wrapped
monad_m get_last(void) const { return m_last; };
void put_Console(CEMdFOutput *pOut) const;
void put_XML(CEMdFOutput* pOut) const;
};
class SheafIterator {
public:
SheafIterator(CList_of_straws *pMotherList);
SheafIterator();
SheafIterator(const SheafIterator{PREAMP} other);
~SheafIterator();
bool hasNext() const; // Is the iterator == end iterator? Doesn't alter iterator
CStraw* next(); // Gets current and advances iterator afterwards
CStraw* previous(); // Regresses iterator and then gets current
CStraw* current(); // Gets current without altering iterator
};
class SheafConstIterator {
public:
SheafConstIterator(const CList_of_straws *pMotherList);
SheafConstIterator();
SheafConstIterator(const SheafConstIterator{PREAMP} other);
~SheafConstIterator();
bool hasNext() const; // Is the iterator == end iterator? Doesn't alter iterator
const CStraw* next(); // Gets current and advances iterator afterwards
const CStraw* previous(); // Regresses iterator and then gets current
const CStraw* current(); // Gets current without altering iterator
};
class CList_of_straws {
public:
~CList_of_straws();
CList_of_straws(const CList_of_straws{PREAMP} other);
SheafIterator iterator();
SheafConstIterator const_iterator() const;
bool is_empty() const;
void put_Console(CEMdFOutput *pOut) const;
void put_XML(CEMdFOutput* pOut) const;
};
class CSheaf {
public:
CSheaf(const CSheaf{PREAMP} other);
~CSheaf();
bool is_fail(void) const;
SheafIterator iterator();
SheafConstIterator const_iterator() const;
const CList_of_straws* get_plist(void) const { return m_plist; };
CSheaf{PREAMP} operator=(const CSheaf{PREAMP} other); // Not SWIG-wrapped
void put_Console(CEMdFOutput *pOut) const;
void put_XML(CEMdFOutput* pOut) const;
// Print sheaf's contribution to DTD
static void print_DTD(CEMdFOutput* pOut);
};
ExampleThe iterators are used like this:
CSheaf *pSheaf; // Assumed to be initialized from somewhere
SheafConstIterator sci = pSheaf->const_iterator();
while (sci.hasNext()) {
const CStraw *pStraw = sci.current();
// Process pStraw ...
sci.next();
}
// Or like this:
SheafIterator si = pSheaf->iterator();
while (si.hasNext()) {
CStraw *pStraw = si.next();
// Process pStraw ...
// Note how there is no si.next() again, since next()
// first gets current element and then advances iterator.
// NOTE: This is also possible with the const iterators.
}
|