Nebula
Loading...
Searching...
No Matches
reader.h
Go to the documentation of this file.
1#ifndef DB_READER_H
2#define DB_READER_H
3//------------------------------------------------------------------------------
13#include "core/refcounted.h"
14#include "attr/attribute.h"
15#include "db/dataset.h"
16#include "db/valuetable.h"
17#include "util/guid.h"
18#include "util/blob.h"
19#include "db/database.h"
20
21//------------------------------------------------------------------------------
22namespace Db
23{
25{
27public:
29 Reader();
31 virtual ~Reader();
32
34 void SetDatabase(const Ptr<Database>& db);
36 void SetTableName(const Util::String& n);
38 void AddFilterAttr(const Attr::Attribute& attr);
39
41 bool Open();
43 bool IsOpen() const;
45 void Close();
46
48 int GetNumRows() const;
50 void SetToRow(int rowIndex);
52 int GetCurrentRowIndex() const;
53
55 bool HasAttr(Attr::AttrId attrId) const;
57 bool GetBool(Attr::BoolAttrId attrId) const;
59 int GetInt(Attr::IntAttrId attrId) const;
61 float GetFloat(Attr::FloatAttrId attrId) const;
63 const Util::String& GetString(Attr::StringAttrId attrId) const;
65 const Math::vec4 GetVec4(Attr::Vec4AttrId attrId) const;
67 const Math::mat4 GetMat4(Attr::Mat4AttrId attrId) const;
69 const Util::Guid& GetGuid(Attr::GuidAttrId attrId) const;
71 const Util::Blob& GetBlob(Attr::BlobAttrId attrId) const;
74
75private:
76 bool isOpen;
83};
84
85//------------------------------------------------------------------------------
88inline void
90{
91 this->database = db;
92}
93
94//------------------------------------------------------------------------------
97inline bool
99{
100 return this->isOpen;
101}
102
103//------------------------------------------------------------------------------
106inline const Ptr<Db::ValueTable>&
108{
109 return this->valueTable;
110}
111
112//------------------------------------------------------------------------------
116inline void
118{
119 this->tableName = t;
120}
121
122//------------------------------------------------------------------------------
127inline void
129{
130 this->filterAttrs.Append(attr);
131}
132
133//------------------------------------------------------------------------------
137inline int
139{
140 n_assert(this->isOpen);
141 return this->dataset->Values()->GetNumRows();
142}
143
144//------------------------------------------------------------------------------
148inline void
149Reader::SetToRow(int rowIndex)
150{
151 n_assert(this->isOpen);
152 n_assert((rowIndex >= 0) && (rowIndex < this->GetNumRows()));
153 this->curRowIndex = rowIndex;
154}
155
156//------------------------------------------------------------------------------
159inline int
161{
162 return this->curRowIndex;
163}
164
165}; // namespace Db
166//------------------------------------------------------------------------------
167#endif
168
An attribute ID is used to carry attribute types (no values) around.
Definition attrid.h:20
A compiletime-typesafe key/value pair.
Definition attribute.h:32
Typed attribute id for blob type.
Definition blobattrid.h:18
Typed attribute id for bool type.
Definition boolattrid.h:18
Typed attribute id for float type.
Definition floatattrid.h:18
Typed attribute id for guid type.
Definition guidattrid.h:18
Typed attribute id for integer type.
Definition intattrid.h:18
Typed attribute id for mat4 type.
Definition mat4attrid.h:18
Typed attribute id for string type.
Definition stringattrid.h:18
Typed attribute id for vec4 type.
Definition vec4attrid.h:18
The common base class of Nebula.
Definition refcounted.h:38
Wrapper to bulk-read the contents of a database table.
Definition reader.h:25
virtual ~Reader()
destructor
Definition reader.cc:27
const Math::mat4 GetMat4(Attr::Mat4AttrId attrId) const
return mat4 attribute value
Definition reader.cc:158
bool isOpen
Definition reader.h:76
const Util::Blob & GetBlob(Attr::BlobAttrId attrId) const
return blob attribute value
Definition reader.cc:178
int GetNumRows() const
get number of rows in the result
Definition reader.h:138
Reader()
constructor
Definition reader.cc:17
Ptr< Database > database
Definition reader.h:77
Util::Array< Attr::Attribute > filterAttrs
Definition reader.h:79
const Math::vec4 GetVec4(Attr::Vec4AttrId attrId) const
return vec4 attribute value
Definition reader.cc:148
void SetTableName(const Util::String &n)
set the database table name
Definition reader.h:117
bool HasAttr(Attr::AttrId attrId) const
return true if attribute exists at current row
Definition reader.cc:98
Ptr< ValueTable > valueTable
Definition reader.h:81
bool Open()
open the reader, this will perform a query on the database
Definition reader.cc:41
void Close()
close the reader
Definition reader.cc:84
const Util::Guid & GetGuid(Attr::GuidAttrId attrId) const
return guid attribute value
Definition reader.cc:168
const Ptr< Db::ValueTable > & GetValueTable() const
get direct pointer to value table
Definition reader.h:107
IndexT curRowIndex
Definition reader.h:82
Util::String tableName
Definition reader.h:78
const Util::String & GetString(Attr::StringAttrId attrId) const
return string attribute value
Definition reader.cc:138
void SetToRow(int rowIndex)
set read cursor to specified row
Definition reader.h:149
void SetDatabase(const Ptr< Database > &db)
set database object
Definition reader.h:89
int GetInt(Attr::IntAttrId attrId) const
return int attribute value
Definition reader.cc:118
bool IsOpen() const
return true if reader is open
Definition reader.h:98
bool GetBool(Attr::BoolAttrId attrId) const
return bool attribute value
Definition reader.cc:108
__DeclareClass(Reader)
int GetCurrentRowIndex() const
get current row index
Definition reader.h:160
void AddFilterAttr(const Attr::Attribute &attr)
add an optional filter/WHERE attribute
Definition reader.h:128
float GetFloat(Attr::FloatAttrId attrId) const
return float attribute value
Definition reader.cc:128
Ptr< Dataset > dataset
Definition reader.h:80
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula's dynamic array class.
Definition array.h:60
void Append(const TYPE &first, const ELEM_TYPE &... elements)
Append multiple elements to the end of the array.
Definition array.h:1332
The Util::Blob class encapsulates a chunk of raw memory into a C++ object which can be copied,...
Definition blob.h:22
Implements a GUID.
#define n_assert(exp)
Definition debug.h:50
Definition column.cc:10
A 4x4 single point precision float matrix.
Definition mat4.h:47
A 4D vector.
Definition vec4.h:24
Nebula's universal string class.
Definition string.h:50
int IndexT
Definition types.h:48