PLearn 0.1
Public Types | Public Member Functions | Private Attributes
PLearn::Row Class Reference

#include <SimpleDB.h>

Collaboration diagram for PLearn::Row:
Collaboration graph
[legend]

List of all members.

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 SchemagetSchema () 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 Schemaschema

Detailed Description

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.


Member Typedef Documentation

high-class cheating!

Definition at line 1047 of file SimpleDB.h.

-- 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.


Constructor & Destructor Documentation

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.

: rawrow(), schema(0) { }
PLearn::Row::Row ( const Row r) [inline]

Definition at line 1056 of file SimpleDB.h.

: rawrow(r.rawrow), schema(r.schema) { }
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
}

Here is the call graph for this function:

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.

        : rawrow(raw), schema(s) { }

Member Function Documentation

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().

                     {
        return iterator(0, raw(), schema);
    }

Here is the caller graph for this function:

iterator PLearn::Row::bind ( const FieldPtr p) const [inline]

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);
    }

Here is the caller graph for this function:

bool PLearn::Row::empty ( ) const [inline]

Definition at line 1092 of file SimpleDB.h.

                       {
        return (schema && schema->empty()) || !schema;
    }
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);
    }

Here is the caller graph for this function:

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.

                               {
        return (size_type)rawrow.size();
    }
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;
}

Here is the call graph for this function:

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;
}

Here is the call graph for this function:

unsigned char* PLearn::Row::raw ( ) [inline]

Definition at line 1104 of file SimpleDB.h.

                         {
        if (rawrow.size())
            return &rawrow[0];
        else
            return 0;
    }
const unsigned char* PLearn::Row::raw ( ) const [inline]
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;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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().

                           {
        return (size_type)rawrow.size();
    }

Here is the caller graph for this function:


Member Data Documentation

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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines