PLearn 0.1
Public Member Functions | Private Attributes
PLearn::RowIterator Class Reference

#include <SimpleDB.h>

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

List of all members.

Public Member Functions

 RowIterator ()
 RowIterator (const RowIterator &x)
bool operator== (const RowIterator &x)
bool operator!= (const RowIterator &x)
 RowIterator (int curf, unsigned char *curp, const Schema *sc)
 Non-trivial ctor.
RowIteratoroperator= (const RowIterator &x)
 Default destructor is being used.
void copyFrom (const RowIterator &it)
 Copying of value.
FieldRowRef operator* () const
 Dereference.
RowIteratoroperator++ ()
RowIterator operator++ (int)
 Post-increment is expressed as a pre-increment.
RowIterator operator[] (int i)
 Permit limited random access from an iterator (positive directions only!)
FieldType getFieldType () const
bool isString () const
bool isCharacter () const
bool isSignedChar () const
bool isShort () const
bool isInt () const
bool isFloat () const
bool isDouble () const
bool isDate () const
char * asString ()
unsigned char * asCharacter ()
signed char * asSignedChar ()
short * asShort ()
intasInt ()
float * asFloat ()
double * asDouble ()
PDateasDate ()
const char * asString () const
const unsigned char * asCharacter () const
const signed char * asSignedChar () const
const short * asShort () const
const intasInt () const
const float * asFloat () const
const double * asDouble () const
const PDateasDate () const
double toDouble () const
string toString () const
bool isMissing () const
void setMissing ()
string name () const
 Return the name of the current field, or "" if not currently pointing to any valid field.
int precision () const
 Return the precision of the current field (number of bytes), or -1 if not currently pointing to any valid field.
int char_width () const
 Return the size in characters required to print out the current field.
unsigned char * raw ()
 Return the physical address of the iterator.
const unsigned char * raw () const
FieldPtr makePtr () const

Private Attributes

unsigned curfield
 current field number in schema
unsigned char * curptr
 current ptr in rawrow
const Schemaschema

Detailed Description

Definition at line 737 of file SimpleDB.h.


Constructor & Destructor Documentation

PLearn::RowIterator::RowIterator ( ) [inline]

-- Requirements from trivial iterator

Definition at line 740 of file SimpleDB.h.

: curfield(0), curptr(0), schema(0) { }
PLearn::RowIterator::RowIterator ( const RowIterator x) [inline]

Definition at line 741 of file SimpleDB.h.

References curfield, curptr, and schema.

                                      {
        curfield = x.curfield;
        curptr = x.curptr;
        schema = x.schema;
    }
PLearn::RowIterator::RowIterator ( int  curf,
unsigned char *  curp,
const Schema sc 
) [inline]

Non-trivial ctor.

Definition at line 757 of file SimpleDB.h.

        : curfield(curf), curptr(curp), schema(sc)
    { }

Member Function Documentation

unsigned char* PLearn::RowIterator::asCharacter ( ) [inline]

Definition at line 881 of file SimpleDB.h.

Referenced by PLearn::AutoSDBVMatrix::getNewRow(), isMissing(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), setMissing(), toDouble(), and toString().

                                 {
        return isCharacter()?
            reinterpret_cast<unsigned char*>(curptr) : 0;
    }

Here is the caller graph for this function:

const unsigned char* PLearn::RowIterator::asCharacter ( ) const [inline]

Definition at line 922 of file SimpleDB.h.

                                             {
        return isCharacter()?
            reinterpret_cast<const unsigned char*>(curptr) : 0;
    }
const PDate* PLearn::RowIterator::asDate ( ) const [inline]

Definition at line 948 of file SimpleDB.h.

                                {
        return isDate()? reinterpret_cast<const PDate*>(curptr) : 0;
    }
PDate* PLearn::RowIterator::asDate ( ) [inline]

Definition at line 907 of file SimpleDB.h.

Referenced by isMissing(), PLearn::SimpleDB< KeyType, QueryResult >::memoryToDisk(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), setMissing(), toDouble(), and toString().

                    {
        return isDate()? reinterpret_cast<PDate*>(curptr) : 0;
    }

Here is the caller graph for this function:

const double* PLearn::RowIterator::asDouble ( ) const [inline]

Definition at line 944 of file SimpleDB.h.

                                   {
        return isDouble()? reinterpret_cast<const double*>(curptr) : 0;
    }
double* PLearn::RowIterator::asDouble ( ) [inline]

Definition at line 903 of file SimpleDB.h.

Referenced by isMissing(), PLearn::SimpleDB< KeyType, QueryResult >::memoryToDisk(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), setMissing(), toDouble(), and toString().

                       {
        return isDouble()? reinterpret_cast<double*>(curptr) : 0;
    }

Here is the caller graph for this function:

float* PLearn::RowIterator::asFloat ( ) [inline]

Definition at line 899 of file SimpleDB.h.

Referenced by isMissing(), PLearn::SimpleDB< KeyType, QueryResult >::memoryToDisk(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), setMissing(), toDouble(), and toString().

                     {
        return isFloat()? reinterpret_cast<float*>(curptr) : 0;
    }

Here is the caller graph for this function:

const float* PLearn::RowIterator::asFloat ( ) const [inline]

Definition at line 940 of file SimpleDB.h.

                                 {
        return isFloat()? reinterpret_cast<const float*>(curptr) : 0;
    }
int* PLearn::RowIterator::asInt ( ) [inline]

Definition at line 895 of file SimpleDB.h.

Referenced by isMissing(), PLearn::SimpleDB< KeyType, QueryResult >::memoryToDisk(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), setMissing(), toDouble(), and toString().

                 {
        return isInt()? reinterpret_cast<int*>(curptr) : 0;
    }

Here is the caller graph for this function:

const int* PLearn::RowIterator::asInt ( ) const [inline]

Definition at line 936 of file SimpleDB.h.

                             {
        return isInt()? reinterpret_cast<const int*>(curptr) : 0;
    }
short* PLearn::RowIterator::asShort ( ) [inline]

Definition at line 891 of file SimpleDB.h.

Referenced by isMissing(), PLearn::SimpleDB< KeyType, QueryResult >::memoryToDisk(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), setMissing(), toDouble(), and toString().

                     {
        return isShort()? reinterpret_cast<short*>(curptr) : 0;
    }

Here is the caller graph for this function:

const short* PLearn::RowIterator::asShort ( ) const [inline]

Definition at line 932 of file SimpleDB.h.

                                 {
        return isShort()? reinterpret_cast<const short*>(curptr) : 0;
    }
signed char* PLearn::RowIterator::asSignedChar ( ) [inline]

Definition at line 886 of file SimpleDB.h.

Referenced by isMissing(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), setMissing(), toDouble(), and toString().

                                {
        return isSignedChar()?
            reinterpret_cast<signed char*>(curptr) : 0;
    }

Here is the caller graph for this function:

const signed char* PLearn::RowIterator::asSignedChar ( ) const [inline]

Definition at line 927 of file SimpleDB.h.

                                            {
        return isSignedChar()?
            reinterpret_cast<const signed char*>(curptr) : 0;
    }
char* PLearn::RowIterator::asString ( ) [inline]

-- Return a pointer to the CURRENT element, as the correct type. Return 0 element if the wrong type is specified. The current element may be modified through this pointer.

Definition at line 872 of file SimpleDB.h.

Referenced by PLearn::AutoSDBVMatrix::getNewRow(), isMissing(), PLearn::FieldRowRef::operator FieldValue(), PLearn::operator<<(), PLearn::FieldRowRef::operator=(), PLearn::Row::sanitize(), setMissing(), toDouble(), and toString().

                     {
        bool iss = isString();
        if (iss)
            return reinterpret_cast<char*>(curptr);
        else 
            return 0;
        //return isString()? reinterpret_cast<char*>(curptr) : 0;
    }

Here is the caller graph for this function:

const char* PLearn::RowIterator::asString ( ) const [inline]

-- CONST VERSIONS. Return a pointer to the CURRENT element, as the correct type. Return 0 element if the wrong type is specified. The current element may be modified through this pointer.

Definition at line 918 of file SimpleDB.h.

                                 {
        return isString()? reinterpret_cast<const char*>(curptr) : 0;
    }
int PLearn::RowIterator::char_width ( ) const

Return the size in characters required to print out the current field.

Definition at line 602 of file SimpleDB.cc.

References curfield, isCharacter(), isDate(), isDouble(), isFloat(), isInt(), isShort(), isSignedChar(), isString(), PLearn::max(), name(), PLERROR, precision(), and w.

Referenced by PLearn::operator<<(), and PLearn::printFieldName().

{
    int w = 0;
    if (isString())
        w = precision()-1;                   // minus terminating null
    else if (isCharacter())
        w = 1;                               // 'A'
    else if (isSignedChar())
        w = 4;                               // -127
    else if (isShort())
        w = 6;                               // -32767
    else if (isInt())
        w = 11;                              // -2 billion
    else if (isFloat())
        w = 8;                               // -precision + decimal point
    else if (isDouble())
        w = 8;                               // -precision + decimal point
    else if (isDate())
        w = 10;                              // YYYY/MM/DD
    else
        PLERROR("Unknown type for iterator, field %d (%s)",curfield,name().c_str());

    return std::max(int(w),int(name().size()));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::RowIterator::copyFrom ( const RowIterator it) [inline]

Copying of value.

Definition at line 776 of file SimpleDB.h.

References std::copy(), getFieldType(), PLERROR, precision(), PLearn::raw, and raw().

    {
#ifdef BOUNDCHECK
        if(it.precision()!=precision() || it.getFieldType()!=getFieldType())
            PLERROR("In Row::iterator::copyFrom Source and destination fields not of same type or precision");
#endif
        copy(it.raw(),it.raw()+it.precision(),raw());
    }

Here is the call graph for this function:

FieldType PLearn::RowIterator::getFieldType ( ) const [inline]

Definition at line 820 of file SimpleDB.h.

Referenced by PLearn::SDBWithStats::computeStats(), and copyFrom().

    { return (*schema)[curfield].field_type; }

Here is the caller graph for this function:

bool PLearn::RowIterator::isCharacter ( ) const [inline]

Definition at line 831 of file SimpleDB.h.

References PLearn::CharacterType.

Referenced by char_width(), and PLearn::AutoSDBVMatrix::getNewRow().

                             {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == CharacterType;
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::isDate ( ) const [inline]

Definition at line 861 of file SimpleDB.h.

References PLearn::DateType.

Referenced by char_width().

                        {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == DateType;
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::isDouble ( ) const [inline]

Definition at line 856 of file SimpleDB.h.

References PLearn::DoubleType.

Referenced by char_width().

                          {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == DoubleType;
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::isFloat ( ) const [inline]

Definition at line 851 of file SimpleDB.h.

References PLearn::FloatType.

Referenced by char_width().

                         {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == FloatType;
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::isInt ( ) const [inline]

Definition at line 846 of file SimpleDB.h.

References PLearn::IntType.

Referenced by char_width().

                       {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == IntType;
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::isMissing ( ) const

-- The following functions deal with missing values

Definition at line 560 of file SimpleDB.cc.

References asCharacter(), asDate(), asDouble(), asFloat(), asInt(), asShort(), asSignedChar(), asString(), PLearn::MissingCharacter, PLearn::MissingDate, PLearn::MissingInt, PLearn::MissingShort, PLearn::MissingSignedChar, PLearn::MissingString, and x.

Referenced by PLearn::SDBWithStats::computeStats(), PLearn::AutoSDBVMatrix::getNewRow(), PLearn::operator<<(), toDouble(), and toString().

{
    if (const char* x = asString())
        return x[0] == MissingString;
    else if (const unsigned char* x = asCharacter())
        return x[0] == MissingCharacter;
    else if (const signed char* x = asSignedChar())
        return x[0] == MissingSignedChar;
    else if (const short* x = asShort())
        return *x == MissingShort;
    else if (const int* x = asInt())
        return *x == MissingInt;
    else if (const float* x = asFloat())
        return isnan(*x);
    else if (const double* x = asDouble())
        return isnan(*x);
    else if (const PDate* x = asDate())
        return *x == MissingDate;
    else
        return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool PLearn::RowIterator::isShort ( ) const [inline]

Definition at line 841 of file SimpleDB.h.

References PLearn::ShortType.

Referenced by char_width().

                         {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == ShortType;
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::isSignedChar ( ) const [inline]

Definition at line 836 of file SimpleDB.h.

References PLearn::SignedCharType.

Referenced by char_width().

                              {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == SignedCharType;
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::isString ( ) const [inline]

-- Predicates to test whether current element is of a certain type. Always false for null or past-end iterators.

Definition at line 826 of file SimpleDB.h.

References PLearn::StringType.

Referenced by char_width(), and PLearn::AutoSDBVMatrix::getNewRow().

                          {
        return schema && curptr && curfield < schema->size() &&
            (*schema)[curfield].field_type == StringType;
    }

Here is the caller graph for this function:

FieldPtr PLearn::RowIterator::makePtr ( ) const [inline]

Make a FieldPtr from the current iterator position (this operation is not extremely fast, since we must loop from the beginning of the row)

Definition at line 995 of file SimpleDB.h.

                             {
        return schema->findColumn(curfield);
    }
string PLearn::RowIterator::name ( ) const [inline]

Return the name of the current field, or "" if not currently pointing to any valid field.

Definition at line 966 of file SimpleDB.h.

Referenced by char_width(), PLearn::AutoSDBVMatrix::getNewRow(), and PLearn::printFieldName().

                        {
        return (schema && curfield < schema->size())?
            (*schema)[curfield].name : string("");
    }

Here is the caller graph for this function:

bool PLearn::RowIterator::operator!= ( const RowIterator x) [inline]

Definition at line 752 of file SimpleDB.h.

References x.

                                          {
        return !((*this) == x);
    }
FieldRowRef PLearn::RowIterator::operator* ( ) const [inline]

Dereference.

Definition at line 1187 of file SimpleDB.h.

{
    return FieldRowRef(*this);
}
RowIterator& PLearn::RowIterator::operator++ ( ) [inline]

-- Requirements from input iterator

Preincrement : the distance of the increment depends on the current field size. And end() iterator has a current field number that is 1 beyond the maximum number of field. A null iterator has everything equal to zero.

Definition at line 795 of file SimpleDB.h.

References precision().

                              {
        if (schema && curptr && curfield < schema->size()) {
            curptr += (*schema)[curfield].precision;
            ++curfield;
        }
        return *this;
    }

Here is the call graph for this function:

RowIterator PLearn::RowIterator::operator++ ( int  ) [inline]

Post-increment is expressed as a pre-increment.

Definition at line 804 of file SimpleDB.h.

References x.

                                {
        RowIterator x = *this;
        ++(*this);
        return x;
    }
RowIterator& PLearn::RowIterator::operator= ( const RowIterator x) [inline]

Default destructor is being used.

Assignment

Definition at line 764 of file SimpleDB.h.

References curfield, curptr, and schema.

    {
        if (&x != this) 
        {
            curfield = x.curfield;
            curptr   = x.curptr;
            schema   = x.schema;
        }
        return *this;
    }
bool PLearn::RowIterator::operator== ( const RowIterator x) [inline]

Definition at line 746 of file SimpleDB.h.

References curfield, curptr, and schema.

                                          {
        return
            curfield==x.curfield &&
            curptr  ==x.curptr   &&
            schema  ==x.schema;
    }
RowIterator PLearn::RowIterator::operator[] ( int  i) [inline]

Permit limited random access from an iterator (positive directions only!)

Definition at line 812 of file SimpleDB.h.

References PLASSERT.

                                  {
        PLASSERT(i >= 0);
        RowIterator it = *this;
        while (i--)
            ++it;
        return it;
    }
int PLearn::RowIterator::precision ( ) const [inline]

Return the precision of the current field (number of bytes), or -1 if not currently pointing to any valid field.

Definition at line 973 of file SimpleDB.h.

Referenced by char_width(), copyFrom(), operator++(), PLearn::FieldRowRef::operator=(), and PLearn::Row::sanitize().

                          {
        return (schema && curfield < schema->size())?
            (*schema)[curfield].precision : -1;
    }

Here is the caller graph for this function:

const unsigned char* PLearn::RowIterator::raw ( ) const [inline]

Definition at line 987 of file SimpleDB.h.

                                     {
        return curptr;
    }
unsigned char* PLearn::RowIterator::raw ( ) [inline]

Return the physical address of the iterator.

Definition at line 983 of file SimpleDB.h.

Referenced by copyFrom().

                         {
        return curptr;
    }

Here is the caller graph for this function:

void PLearn::RowIterator::setMissing ( )

Definition at line 582 of file SimpleDB.cc.

References asCharacter(), asDate(), asDouble(), asFloat(), asInt(), asShort(), asSignedChar(), asString(), PLearn::MissingCharacter, PLearn::MissingDate, PLearn::MissingDouble, PLearn::MissingFloat, PLearn::MissingInt, PLearn::MissingShort, PLearn::MissingSignedChar, PLearn::MissingString, and x.

{
    if (char* x = asString())
        *x = MissingString;
    else if (unsigned char* x = asCharacter())
        *x = MissingCharacter;
    else if (signed char* x = asSignedChar())
        *x = MissingSignedChar;
    else if (short* x = asShort())
        *x = MissingShort;
    else if (int* x = asInt())
        *x = MissingInt;
    else if (float* x = asFloat())
        *x = MissingFloat;
    else if (double* x = asDouble())
        *x = MissingDouble;
    else if (PDate* x = asDate())
        *x = MissingDate;
}

Here is the call graph for this function:

double PLearn::RowIterator::toDouble ( ) const

-- GENERIC CONVERSIONS. To string and to double, from nearly any type of field

Definition at line 627 of file SimpleDB.cc.

References asCharacter(), asDate(), asDouble(), asFloat(), asInt(), asShort(), asSignedChar(), asString(), PLearn::date_to_float(), isMissing(), MISSING_VALUE, PLERROR, and x.

Referenced by PLearn::AutoSDBVMatrix::getNewRow(), and PLearn::todouble().

{
    if (isMissing())
        return MISSING_VALUE;
    if (asString())
        PLERROR("Cannot convert string to double");
    if (asCharacter())
        PLERROR("Cannot convert character to double");
    if (const signed char* x = asSignedChar())
        return double(*x);
    if (const short* x = asShort())
        return double(*x);
    if (const int* x = asInt())
        return double(*x);
    if (const float* x = asFloat())
        return double(*x);
    if (const double* x = asDouble())
        return *x;
    if (const PDate* x = asDate())
        return double(date_to_float(*x));    
    return MISSING_VALUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string PLearn::RowIterator::toString ( ) const

Definition at line 650 of file SimpleDB.cc.

References asCharacter(), asDate(), asDouble(), asFloat(), asInt(), asShort(), asSignedChar(), asString(), isMissing(), PLearn::space_to_underscore(), PLearn::tostring(), and x.

Referenced by PLearn::tostring().

{
    if (isMissing())
        return "";
    if (const char* x = asString())
        return space_to_underscore(x);
    if (const unsigned char* x = asCharacter())
        return string(1,char(*x));
    if (const signed char* x = asSignedChar())
        return tostring(int(*x));
    if (const short* x = asShort())
        return tostring(*x);
    if (const int* x = asInt())
        return tostring(*x);
    if (const float* x = asFloat())
        return tostring(*x);
    if (const double* x = asDouble())
        return tostring(*x);
    if (const PDate* x = asDate())
        return x->info();
    return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

unsigned PLearn::RowIterator::curfield [private]

current field number in schema

Definition at line 1000 of file SimpleDB.h.

Referenced by char_width(), operator=(), operator==(), and RowIterator().

unsigned char* PLearn::RowIterator::curptr [private]

current ptr in rawrow

Definition at line 1001 of file SimpleDB.h.

Referenced by operator=(), operator==(), and RowIterator().

Definition at line 1002 of file SimpleDB.h.

Referenced by operator=(), operator==(), and RowIterator().


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