PLearn 0.1
|
#include <SimpleDB.h>
Public Types | |
typedef RowIterator | iterator |
typedef iterator | const_iterator |
high-class cheating! | |
typedef long | size_type |
number of elements in a row | |
Public Member Functions | |
Row () | |
Row (const Row &r) | |
Row (const Schema *s) | |
Construct an empty row given only a schema. | |
Row (const vector< unsigned char > &raw, const Schema *s) | |
Construct a row given a schema and a full vector of bytes. | |
iterator | begin () |
Default destructor and assignment operator are being used. | |
iterator | end () |
size_type | size () const |
Return the size of a complete row in CHARS! | |
size_type | max_size () const |
bool | empty () const |
const unsigned char * | raw () const |
Return the raw data. | |
unsigned char * | raw () |
const Schema * | getSchema () const |
iterator | operator[] (int fieldNumber) |
iterator | operator[] (string fieldName) |
iterator | bind (const FieldPtr &p) const |
void | sanitize () const |
Private Attributes | |
vector< unsigned char > | rawrow |
const Schema * | schema |
A database row is fundamentally a fixed-width byte string. Since we don't want to give direct access to it, we define STL iterators that let us traverse the structure
Definition at line 1042 of file SimpleDB.h.
typedef iterator PLearn::Row::const_iterator |
high-class cheating!
Definition at line 1047 of file SimpleDB.h.
typedef RowIterator PLearn::Row::iterator |
-- Definition of public nested types
Definition at line 1046 of file SimpleDB.h.
typedef long PLearn::Row::size_type |
number of elements in a row
Definition at line 1048 of file SimpleDB.h.
PLearn::Row::Row | ( | ) | [inline] |
-- We are now in a position to define the Row public interface. This is fairly simple, since a lot of the work is delegated to the iterator.
Definition at line 1055 of file SimpleDB.h.
PLearn::Row::Row | ( | const Row & | r | ) | [inline] |
Definition at line 1056 of file SimpleDB.h.
PLearn::Row::Row | ( | const Schema * | s | ) |
Construct an empty row given only a schema.
Definition at line 781 of file SimpleDB.cc.
References end(), n, rawrow, and schema.
: schema(s) { // Compute the total size of a row int n=0; Schema::const_iterator it = schema->begin(), end = schema->end(); for ( ; it != end; ++it ) { n += it->precision; } rawrow.resize(n, '\0'); // zero-initialize it }
PLearn::Row::Row | ( | const vector< unsigned char > & | raw, |
const Schema * | s | ||
) | [inline] |
Construct a row given a schema and a full vector of bytes.
The vector is assumed to be in proper endianness.
Definition at line 1063 of file SimpleDB.h.
iterator PLearn::Row::begin | ( | ) | [inline] |
Default destructor and assignment operator are being used.
Container standard STL functions
Definition at line 1071 of file SimpleDB.h.
References PLearn::raw.
Referenced by PLearn::SDBWithStats::computeStats(), PLearn::AutoSDBVMatrix::getNewRow(), PLearn::SimpleDB< KeyType, QueryResult >::memoryToDisk(), PLearn::operator<<(), operator[](), PLearn::printFieldNames(), and sanitize().
Bind a FieldPtr to a row to produce a row iterator (this would actually be an opportunity to overload operator->*(), note the star, but use restraint and don't do it). Right now, we define binding a null pointer as an error.
Definition at line 1130 of file SimpleDB.h.
References PLearn::FieldPtr::field_index_, PLearn::FieldPtr::offset_, PLERROR, and PLearn::raw.
Referenced by PLearn::SDBVMFieldSumClaims::convertField(), PLearn::SDBVMFieldHasClaim::convertField(), and PLearn::SDBVMSource::getValue().
{ if (!p) PLERROR("Trying to dereference a null FieldPtr"); return iterator(p.field_index_, const_cast<unsigned char*>(raw()) + p.offset_, schema); }
bool PLearn::Row::empty | ( | ) | const [inline] |
Definition at line 1092 of file SimpleDB.h.
iterator PLearn::Row::end | ( | ) | [inline] |
Definition at line 1075 of file SimpleDB.h.
References PLearn::raw.
Referenced by PLearn::SimpleDB< KeyType, QueryResult >::memoryToDisk(), PLearn::operator<<(), operator[](), PLearn::printFieldNames(), Row(), and sanitize().
{ if (schema) return iterator(schema->size(), raw()+rawrow.size(), schema); else return iterator(0,0,0); }
const Schema* PLearn::Row::getSchema | ( | ) | const [inline] |
Definition at line 1111 of file SimpleDB.h.
{ return schema; }
size_type PLearn::Row::max_size | ( | ) | const [inline] |
Definition at line 1088 of file SimpleDB.h.
Row::iterator PLearn::Row::operator[] | ( | int | fieldNumber | ) |
A few utility operators. Note: contrarily to standard containers, operator[] does not return a reference to a type, but an iterator to the proper position within the row. This is done because of the intrinsic polymorphism of row elements. An iterator equal to end() is returned if the field could be accessed/found.
Definition at line 816 of file SimpleDB.cc.
References begin(), and end().
{ iterator it=this->begin(), end=this->end(); for (; fieldNumber && it != end; --fieldNumber, ++it) ; return it; }
Row::iterator PLearn::Row::operator[] | ( | string | fieldName | ) |
Definition at line 824 of file SimpleDB.cc.
References begin(), end(), and schema.
{ iterator it=this->begin(), end=this->end(); Schema::const_iterator scit=schema->begin(), scend=schema->end(); for(; it != end && scit != scend; ++it, ++scit) if (scit->name == fieldName) break; return it; }
unsigned char* PLearn::Row::raw | ( | ) | [inline] |
Definition at line 1104 of file SimpleDB.h.
const unsigned char* PLearn::Row::raw | ( | ) | const [inline] |
Return the raw data.
Definition at line 1097 of file SimpleDB.h.
Referenced by PLearn::SimpleDB< KeyType, QueryResult >::addRow(), PLearn::SimpleDB< KeyType, QueryResult >::findEqualLinear(), PLearn::SimpleDB< KeyType, QueryResult >::getInRow(), PLearn::SimpleDB< KeyType, QueryResult >::indexColumn(), and PLearn::SimpleDB< KeyType, QueryResult >::setRow().
void PLearn::Row::sanitize | ( | ) | const |
This should be called to perform some sanity checking on a row before writing it to disk. This function is marked const, but nevertheless makes invisible changes to the object.
Definition at line 792 of file SimpleDB.cc.
References PLearn::RowIterator::asString(), begin(), end(), PLearn::RowIterator::precision(), and x.
Referenced by PLearn::SimpleDB< KeyType, QueryResult >::addRow(), and PLearn::SimpleDB< KeyType, QueryResult >::setRow().
{ // The sanitization operation canonicalizes all fields in the row. // Should be called before writing it to disk. This enables indexing // and matching operations to find rows quickly simply by comparing // byte vectors. At the moment, the only sanity check is to zero-fill // all character strings beyond the initial null until the precision of // their field. Row* This = const_cast<Row*>(this); iterator it = This->begin(), end = This->end(); for ( ; it != end; ++it ) { if (char *x = it.asString()) { int prec = it.precision(); bool clearing = false; for ( ; prec; ++x, --prec) if (clearing) *x = '\0'; else if (*x == '\0') clearing = true; } } }
size_type PLearn::Row::size | ( | ) | const [inline] |
Return the size of a complete row in CHARS!
Definition at line 1084 of file SimpleDB.h.
Referenced by PLearn::SimpleDB< KeyType, QueryResult >::addRow(), PLearn::SimpleDB< KeyType, QueryResult >::getInRow(), PLearn::SimpleDB< KeyType, QueryResult >::setRow(), and PLearn::SimpleDB< KeyType, QueryResult >::setSchema().
vector<unsigned char> PLearn::Row::rawrow [private] |
Definition at line 1145 of file SimpleDB.h.
Referenced by Row().
const Schema* PLearn::Row::schema [private] |
Definition at line 1146 of file SimpleDB.h.
Referenced by operator[](), and Row().