PLearn 0.1
|
#include <SimpleDB.h>
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. | |
RowIterator & | operator= (const RowIterator &x) |
Default destructor is being used. | |
void | copyFrom (const RowIterator &it) |
Copying of value. | |
FieldRowRef | operator* () const |
Dereference. | |
RowIterator & | operator++ () |
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 () |
int * | asInt () |
float * | asFloat () |
double * | asDouble () |
PDate * | asDate () |
const char * | asString () const |
const unsigned char * | asCharacter () const |
const signed char * | asSignedChar () const |
const short * | asShort () const |
const int * | asInt () const |
const float * | asFloat () const |
const double * | asDouble () const |
const PDate * | asDate () 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 Schema * | schema |
Definition at line 737 of file SimpleDB.h.
PLearn::RowIterator::RowIterator | ( | ) | [inline] |
-- Requirements from trivial iterator
Definition at line 740 of file SimpleDB.h.
PLearn::RowIterator::RowIterator | ( | const RowIterator & | x | ) | [inline] |
Non-trivial ctor.
Definition at line 757 of file SimpleDB.h.
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; }
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.
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().
const double* PLearn::RowIterator::asDouble | ( | ) | const [inline] |
Definition at line 944 of file SimpleDB.h.
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().
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().
const float* PLearn::RowIterator::asFloat | ( | ) | const [inline] |
Definition at line 940 of file SimpleDB.h.
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().
const int* PLearn::RowIterator::asInt | ( | ) | const [inline] |
Definition at line 936 of file SimpleDB.h.
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().
const short* PLearn::RowIterator::asShort | ( | ) | const [inline] |
Definition at line 932 of file SimpleDB.h.
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; }
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; }
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.
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())); }
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()); }
FieldType PLearn::RowIterator::getFieldType | ( | ) | const [inline] |
Definition at line 820 of file SimpleDB.h.
Referenced by PLearn::SDBWithStats::computeStats(), and copyFrom().
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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.
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().
bool PLearn::RowIterator::operator!= | ( | const RowIterator & | x | ) | [inline] |
FieldRowRef PLearn::RowIterator::operator* | ( | ) | const [inline] |
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; }
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] |
bool PLearn::RowIterator::operator== | ( | const RowIterator & | x | ) | [inline] |
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().
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; }
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; }
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; }
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 ""; }
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().
const Schema* PLearn::RowIterator::schema [private] |
Definition at line 1002 of file SimpleDB.h.
Referenced by operator=(), operator==(), and RowIterator().