PLearn 0.1
|
#include <SimpleDB.h>
Classes | |
struct | DateVal_t |
Public Member Functions | |
FieldValue () | |
Default construction and copy construction. | |
FieldValue (const FieldValue &fv) | |
~FieldValue () | |
FieldValue (const char *) | |
Constructors from concrete values. | |
FieldValue (unsigned char) | |
FieldValue (signed char) | |
FieldValue (short) | |
FieldValue (int) | |
FieldValue (float) | |
FieldValue (double) | |
FieldValue (const PDate &) | |
bool | isMissing () const |
Missing value handling. | |
void | setMissing () |
string | toString () const |
Conversion to strings and doubles. | |
double | toDouble () const |
PDate | toDate () const |
operator double () const | |
operator float () const | |
operator int () const | |
operator string () const | |
operator PDate () const | |
FieldValue & | operator= (FieldValue) |
Assignment. | |
bool | operator== (const FieldValue &) const |
Relational (relational operations don't always make sense) | |
bool | operator< (const FieldValue &) const |
bool | operator!= (const FieldValue &rhs) const |
bool | operator<= (const FieldValue &rhs) const |
bool | operator> (const FieldValue &rhs) const |
bool | operator>= (const FieldValue &rhs) const |
FieldValue | operator+ (const FieldValue &) const |
Arithmetic (again, these don't always make sense) | |
FieldValue | operator- (const FieldValue &) const |
FieldValue | operator* (const FieldValue &) const |
FieldValue | operator/ (const FieldValue &) const |
void | swap (FieldValue &) |
Swap the guts of this with someone else. | |
bool | isString () const |
Some useful type-checking predicates. | |
bool | isIntegral () const |
bool | isFloating () const |
bool | isDate () const |
Private Attributes | |
FieldType | field_type_ |
int | precision_ |
union { | |
char * string_val_ | |
long long_val_ | |
double double_val_ | |
struct DateVal_t date_val_ | |
}; | |
Friends | |
class | FieldRowRef |
A FieldValue is intended to encapsulate all polyphormic operations (copy, comparison, conversion to/from string, double, etc.) on the values of a SimpleDB field.
Definition at line 231 of file SimpleDB.h.
PLearn::FieldValue::FieldValue | ( | ) |
Default construction and copy construction.
Definition at line 101 of file SimpleDB.cc.
Referenced by operator*(), operator+(), operator-(), and operator/().
: field_type_(Unknown), precision_(0) {}
PLearn::FieldValue::FieldValue | ( | const FieldValue & | fv | ) |
Definition at line 105 of file SimpleDB.cc.
References PLearn::CharacterType, date_val_, PLearn::DateType, double_val_, PLearn::DoubleType, field_type_, PLearn::FloatType, PLearn::IntType, long_val_, PLERROR, precision_, PLearn::ShortType, PLearn::SignedCharType, string_val_, PLearn::StringType, PLearn::strlen(), and PLearn::Unknown.
: field_type_(fv.field_type_), precision_(fv.precision_) { switch (field_type_) { case Unknown: break; case StringType: { int stringlen = (int)strlen(fv.string_val_); if (stringlen+1 != precision_) PLERROR("Strings in a database field must contain a terminating null"); string_val_ = new char[precision_]; strcpy(string_val_, fv.string_val_); } break; case CharacterType: case SignedCharType: case ShortType: case IntType: long_val_ = fv.long_val_; break; case FloatType: case DoubleType: double_val_ = fv.double_val_; break; case DateType: date_val_ = fv.date_val_; break; } }
PLearn::FieldValue::~FieldValue | ( | ) |
Definition at line 140 of file SimpleDB.cc.
References PLearn::CharacterType, PLearn::DateType, PLearn::DoubleType, field_type_, PLearn::FloatType, PLearn::IntType, PLearn::ShortType, PLearn::SignedCharType, string_val_, PLearn::StringType, and PLearn::Unknown.
{ switch(field_type_) { case StringType: delete[] string_val_; case Unknown: case CharacterType: case SignedCharType: case ShortType: case IntType: case FloatType: case DoubleType: case DateType: break; } }
PLearn::FieldValue::FieldValue | ( | const char * | str | ) | [explicit] |
Constructors from concrete values.
Definition at line 158 of file SimpleDB.cc.
References precision_, and string_val_.
: field_type_(StringType), precision_(strlen(str)+1) { string_val_ = new char[precision_]; strcpy(string_val_, str); }
PLearn::FieldValue::FieldValue | ( | unsigned char | x | ) | [explicit] |
Definition at line 165 of file SimpleDB.cc.
: field_type_(CharacterType), precision_(Field("",CharacterType).precision), long_val_(x) {}
PLearn::FieldValue::FieldValue | ( | signed char | x | ) | [explicit] |
Definition at line 171 of file SimpleDB.cc.
: field_type_(SignedCharType), precision_(Field("",SignedCharType).precision), long_val_(x) {}
PLearn::FieldValue::FieldValue | ( | short | x | ) | [explicit] |
Definition at line 177 of file SimpleDB.cc.
: field_type_(ShortType), precision_(Field("",ShortType).precision), long_val_(x) {}
PLearn::FieldValue::FieldValue | ( | int | x | ) | [explicit] |
Definition at line 183 of file SimpleDB.cc.
: field_type_(IntType), precision_(Field("",IntType).precision), long_val_(x) {}
PLearn::FieldValue::FieldValue | ( | float | x | ) | [explicit] |
Definition at line 189 of file SimpleDB.cc.
: field_type_(FloatType), precision_(Field("",FloatType).precision), double_val_(x) {}
PLearn::FieldValue::FieldValue | ( | double | x | ) | [explicit] |
Definition at line 195 of file SimpleDB.cc.
: field_type_(DoubleType), precision_(Field("",DoubleType).precision), double_val_(x) {}
PLearn::FieldValue::FieldValue | ( | const PDate & | x | ) | [explicit] |
Definition at line 201 of file SimpleDB.cc.
References date_val_, PLearn::PDate::day, PLearn::FieldValue::DateVal_t::day, PLearn::FieldValue::DateVal_t::month, PLearn::PDate::month, PLearn::FieldValue::DateVal_t::year, and PLearn::PDate::year.
bool PLearn::FieldValue::isDate | ( | ) | const [inline] |
Definition at line 315 of file SimpleDB.h.
References PLearn::DateType.
Referenced by PLearn::SDBVMFieldDateDiff::convertField(), and PLearn::FieldRowRef::operator=().
{ return field_type_ == DateType; }
bool PLearn::FieldValue::isFloating | ( | ) | const [inline] |
Definition at line 311 of file SimpleDB.h.
References PLearn::DoubleType, and PLearn::FloatType.
Referenced by operator*(), operator+(), operator-(), operator/(), operator<(), PLearn::FieldRowRef::operator=(), and operator==().
{ return field_type_ == FloatType || field_type_ == DoubleType; }
bool PLearn::FieldValue::isIntegral | ( | ) | const [inline] |
Definition at line 305 of file SimpleDB.h.
References PLearn::CharacterType, PLearn::IntType, PLearn::ShortType, and PLearn::SignedCharType.
Referenced by PLearn::SDBVMFieldDateDiff::convertField(), operator*(), operator+(), operator-(), operator/(), operator<(), PLearn::FieldRowRef::operator=(), and operator==().
{ return field_type_ == CharacterType || field_type_ == SignedCharType || field_type_ == ShortType || field_type_ == IntType; }
bool PLearn::FieldValue::isMissing | ( | ) | const |
Missing value handling.
Definition at line 210 of file SimpleDB.cc.
References PLearn::CharacterType, date_val_, PLearn::DateType, PLearn::PDate::day, PLearn::FieldValue::DateVal_t::day, double_val_, PLearn::DoubleType, field_type_, PLearn::FloatType, PLearn::IntType, long_val_, PLearn::MissingCharacter, PLearn::MissingDate, PLearn::MissingInt, PLearn::MissingShort, PLearn::MissingSignedChar, PLearn::MissingString, PLearn::FieldValue::DateVal_t::month, PLearn::PDate::month, PLearn::ShortType, PLearn::SignedCharType, string_val_, PLearn::StringType, PLearn::Unknown, PLearn::FieldValue::DateVal_t::year, and PLearn::PDate::year.
Referenced by PLearn::SDBVMFieldDateDiff::convertField(), PLearn::SDBVMFieldCodeAsIs::getDiscreteValue(), PLearn::SDBVMFieldRemapStrings::getDiscreteValue(), PLearn::SDBVMFieldDateGreater::getDiscreteValue(), PLearn::SDBVMFieldRemapReals::getDiscreteValue(), PLearn::SDBVMFieldRemapIntervals::getDiscreteValue(), toDouble(), and toString().
{ switch (field_type_) { case Unknown: return true; case StringType: return !string_val_ || string_val_[0] == MissingString; case CharacterType: return (unsigned char)long_val_ == MissingCharacter; case SignedCharType:return (signed char) long_val_ == MissingSignedChar; case ShortType: return (short) long_val_ == MissingShort; case IntType: return (int) long_val_ == MissingInt; case FloatType: case DoubleType: return isnan(double_val_); case DateType: return date_val_.year == MissingDate.year && date_val_.month == MissingDate.month && date_val_.day == MissingDate.day; } return false; }
bool PLearn::FieldValue::isString | ( | ) | const [inline] |
Some useful type-checking predicates.
Definition at line 301 of file SimpleDB.h.
References PLearn::StringType.
{ return field_type_ == StringType; }
PLearn::FieldValue::operator double | ( | ) | const [inline] |
Definition at line 260 of file SimpleDB.h.
{ return toDouble(); }
PLearn::FieldValue::operator float | ( | ) | const [inline] |
Definition at line 261 of file SimpleDB.h.
{ return float(toDouble()); }
PLearn::FieldValue::operator int | ( | ) | const [inline] |
Definition at line 262 of file SimpleDB.h.
PLearn::FieldValue::operator PDate | ( | ) | const [inline] |
Definition at line 264 of file SimpleDB.h.
{ return toDate(); }
PLearn::FieldValue::operator string | ( | ) | const [inline] |
Definition at line 263 of file SimpleDB.h.
{ return toString(); }
bool PLearn::FieldValue::operator!= | ( | const FieldValue & | rhs | ) | const [inline] |
Definition at line 275 of file SimpleDB.h.
{ return !(*this == rhs); }
FieldValue PLearn::FieldValue::operator* | ( | const FieldValue & | rhs | ) | const |
Definition at line 468 of file SimpleDB.cc.
References PLearn::CharacterType, PLearn::DateType, double_val_, field_type_, FieldValue(), isFloating(), isIntegral(), long_val_, PLERROR, and PLearn::StringType.
{ const FieldValue& lhs = *this; const FieldType& lhs_type = field_type_; const FieldType& rhs_type = rhs.field_type_; // Arithmetic addition is not defined for strings or dates or characters if (lhs_type == StringType || rhs_type == StringType) PLERROR("Strings cannot be multiplied"); else if (lhs_type == CharacterType || rhs_type == CharacterType) PLERROR("Characters cannot be multiplied"); else if (lhs_type == DateType || rhs_type == DateType) PLERROR("Dates cannot be multiplied"); // Twice the same type else if (lhs.isIntegral() && rhs.isIntegral()) return FieldValue(int(lhs.long_val_ * rhs.long_val_)); else if (lhs.isFloating() && rhs.isFloating()) return FieldValue(double(lhs.double_val_ * rhs.double_val_)); // Cross-numeric : convert to double else if (lhs.isIntegral() && rhs.isFloating()) return FieldValue(double(lhs.long_val_ * rhs.double_val_)); else if (lhs.isFloating() && rhs.isIntegral()) return FieldValue(double(lhs.double_val_ * rhs.long_val_)); // Otherwise, PLERROR(should not happen) else PLERROR("Unrecognized case in multiplication between FieldValues"); return FieldValue(); }
FieldValue PLearn::FieldValue::operator+ | ( | const FieldValue & | rhs | ) | const |
Arithmetic (again, these don't always make sense)
Definition at line 396 of file SimpleDB.cc.
References PLearn::CharacterType, PLearn::DateType, double_val_, field_type_, FieldValue(), isFloating(), isIntegral(), long_val_, PLERROR, and PLearn::StringType.
{ const FieldValue& lhs = *this; const FieldType& lhs_type = field_type_; const FieldType& rhs_type = rhs.field_type_; // Arithmetic addition is not defined for strings or dates or characters if (lhs_type == StringType || rhs_type == StringType) PLERROR("Strings cannot be added"); else if (lhs_type == CharacterType || rhs_type == CharacterType) PLERROR("Characters cannot be added"); else if (lhs_type == DateType || rhs_type == DateType) PLERROR("Dates cannot be added"); // Twice the same type else if (lhs.isIntegral() && rhs.isIntegral()) return FieldValue(int(lhs.long_val_ + rhs.long_val_)); else if (lhs.isFloating() && rhs.isFloating()) return FieldValue(double(lhs.double_val_ + rhs.double_val_)); // Cross-numeric : convert to double else if (lhs.isIntegral() && rhs.isFloating()) return FieldValue(double(lhs.long_val_ + rhs.double_val_)); else if (lhs.isFloating() && rhs.isIntegral()) return FieldValue(double(lhs.double_val_ + rhs.long_val_)); // Otherwise, PLERROR(should not happen) else PLERROR("Unrecognized case in addition between FieldValues"); return FieldValue(); }
FieldValue PLearn::FieldValue::operator- | ( | const FieldValue & | rhs | ) | const |
Definition at line 429 of file SimpleDB.cc.
References PLearn::CharacterType, date_val_, PLearn::DateType, PLearn::FieldValue::DateVal_t::day, double_val_, field_type_, FieldValue(), isFloating(), isIntegral(), long_val_, PLearn::FieldValue::DateVal_t::month, PLERROR, PLearn::StringType, and PLearn::FieldValue::DateVal_t::year.
{ const FieldValue& lhs = *this; const FieldType& lhs_type = field_type_; const FieldType& rhs_type = rhs.field_type_; // Arithmetic subtraction is not defined for strings or characters if (lhs_type == StringType || rhs_type == StringType) PLERROR("Strings cannot be subtracted"); else if (lhs_type == CharacterType || rhs_type == CharacterType) PLERROR("Characters cannot be subtracted"); // For dates, return the number of days between two dates else if (lhs_type == DateType && rhs_type == DateType) return FieldValue(int( PDate(lhs.date_val_.year, lhs.date_val_.month, lhs.date_val_.day) - PDate(rhs.date_val_.year, rhs.date_val_.month, rhs.date_val_.day))); else if (lhs_type == DateType || rhs_type == DateType) PLERROR("A date and a non-date cannot be subtracted"); // Twice the same type else if (lhs.isIntegral() && rhs.isIntegral()) return FieldValue(int(lhs.long_val_ - rhs.long_val_)); else if (lhs.isFloating() && rhs.isFloating()) return FieldValue(double(lhs.double_val_ - rhs.double_val_)); // Cross-numeric : convert to double else if (lhs.isIntegral() && rhs.isFloating()) return FieldValue(double(lhs.long_val_ - rhs.double_val_)); else if (lhs.isFloating() && rhs.isIntegral()) return FieldValue(double(lhs.double_val_ - rhs.long_val_)); // Otherwise, PLERROR(should not happen) else PLERROR("Unrecognized case in subtraction between FieldValues"); return FieldValue(); }
FieldValue PLearn::FieldValue::operator/ | ( | const FieldValue & | rhs | ) | const |
Definition at line 501 of file SimpleDB.cc.
References PLearn::CharacterType, PLearn::DateType, double_val_, field_type_, FieldValue(), isFloating(), isIntegral(), long_val_, PLERROR, and PLearn::StringType.
{ const FieldValue& lhs = *this; const FieldType& lhs_type = field_type_; const FieldType& rhs_type = rhs.field_type_; // Arithmetic addition is not defined for strings or dates or characters if (lhs_type == StringType || rhs_type == StringType) PLERROR("Strings cannot be divided"); else if (lhs_type == CharacterType || rhs_type == CharacterType) PLERROR("Characters cannot be divided"); else if (lhs_type == DateType || rhs_type == DateType) PLERROR("Dates cannot be divided"); // Twice the same type else if (lhs.isIntegral() && rhs.isIntegral()) return FieldValue(int(lhs.long_val_ / rhs.long_val_)); else if (lhs.isFloating() && rhs.isFloating()) return FieldValue(double(lhs.double_val_ / rhs.double_val_)); // Cross-numeric : convert to double else if (lhs.isIntegral() && rhs.isFloating()) return FieldValue(double(lhs.long_val_ / rhs.double_val_)); else if (lhs.isFloating() && rhs.isIntegral()) return FieldValue(double(lhs.double_val_ / rhs.long_val_)); // Otherwise, PLERROR(should not happen) else PLERROR("Unrecognized case in division between FieldValues"); return FieldValue(); }
bool PLearn::FieldValue::operator< | ( | const FieldValue & | rhs | ) | const |
Definition at line 355 of file SimpleDB.cc.
References date_val_, PLearn::DateType, PLearn::FieldValue::DateVal_t::day, double_val_, field_type_, if(), isFloating(), isIntegral(), long_val_, PLearn::FieldValue::DateVal_t::month, PLERROR, string_val_, PLearn::StringType, and PLearn::FieldValue::DateVal_t::year.
{ const FieldValue& lhs = *this; const FieldType& lhs_type = field_type_; const FieldType& rhs_type = rhs.field_type_; // Strings if (lhs_type == StringType && rhs_type == StringType) return strcmp(lhs.string_val_, rhs.string_val_) < 0; else if (lhs_type == StringType || rhs_type == StringType) PLERROR("A string can be relationally compared only with another string"); // Dates else if (lhs_type == DateType && rhs_type == DateType) return PDate(lhs.date_val_.year, lhs.date_val_.month, lhs.date_val_.day) < PDate(rhs.date_val_.year, rhs.date_val_.month, rhs.date_val_.day); else if (lhs_type == DateType || rhs_type == DateType) PLERROR("A date can be relationally compared only with another date"); // Two integrals else if (lhs.isIntegral() && rhs.isIntegral()) return lhs.long_val_ < rhs.long_val_; // Two floating else if (lhs.isFloating() && rhs.isFloating()) return lhs.double_val_ < rhs.double_val_; // Cross-numeric else if (lhs.isIntegral() && rhs.isFloating()) return lhs.long_val_ < rhs.double_val_; else if (lhs.isFloating() && lhs.isIntegral()) return lhs.double_val_ < rhs.long_val_; // Otherwise, PLERROR(should not happen) else PLERROR("Unrecognized case in relational testing between FieldValues"); return false; // shut up the compiler }
bool PLearn::FieldValue::operator<= | ( | const FieldValue & | rhs | ) | const [inline] |
Definition at line 279 of file SimpleDB.h.
{ return (*this == rhs) || (*this < rhs); }
FieldValue & PLearn::FieldValue::operator= | ( | FieldValue | rhs | ) |
Assignment.
--- Pseudo-polymorphic operations
Definition at line 308 of file SimpleDB.cc.
References swap().
{ swap(rhs); return *this; }
bool PLearn::FieldValue::operator== | ( | const FieldValue & | rhs | ) | const |
Relational (relational operations don't always make sense)
Definition at line 314 of file SimpleDB.cc.
References date_val_, PLearn::DateType, PLearn::FieldValue::DateVal_t::day, double_val_, field_type_, if(), isFloating(), isIntegral(), long_val_, PLearn::FieldValue::DateVal_t::month, PLERROR, string_val_, PLearn::StringType, and PLearn::FieldValue::DateVal_t::year.
{ const FieldValue& lhs = *this; const FieldType& lhs_type = field_type_; const FieldType& rhs_type = rhs.field_type_; // Strings if (lhs_type == StringType && rhs_type == StringType) return !strcmp(lhs.string_val_, rhs.string_val_); else if (lhs_type == StringType || rhs_type == StringType) PLERROR("A string can be compared for equality only with another string"); // Dates else if (lhs_type == DateType && rhs_type == DateType) return PDate(lhs.date_val_.year, lhs.date_val_.month, lhs.date_val_.day) == PDate(rhs.date_val_.year, rhs.date_val_.month, rhs.date_val_.day); else if (lhs_type == DateType || rhs_type == DateType) PLERROR("A date can be compared for equality only with another date"); // Two integrals else if (lhs.isIntegral() && rhs.isIntegral()) return lhs.long_val_ == rhs.long_val_; // Two floating else if (lhs.isFloating() && rhs.isFloating()) return lhs.double_val_ == rhs.double_val_; // Cross-numeric else if (lhs.isIntegral() && rhs.isFloating()) return lhs.long_val_ == rhs.double_val_; else if (lhs.isFloating() && lhs.isIntegral()) return lhs.double_val_ == rhs.long_val_; // Otherwise, PLERROR(should not happen) else PLERROR("Unrecognized case in equality testing between FieldValues"); return false; // shut up the compiler }
bool PLearn::FieldValue::operator> | ( | const FieldValue & | rhs | ) | const [inline] |
Definition at line 283 of file SimpleDB.h.
{ return !(*this <= rhs); }
bool PLearn::FieldValue::operator>= | ( | const FieldValue & | rhs | ) | const [inline] |
Definition at line 287 of file SimpleDB.h.
{ return !(*this < rhs); }
void PLearn::FieldValue::setMissing | ( | ) |
Definition at line 229 of file SimpleDB.cc.
References PLearn::CharacterType, date_val_, PLearn::DateType, PLearn::PDate::day, PLearn::FieldValue::DateVal_t::day, double_val_, PLearn::DoubleType, field_type_, PLearn::FloatType, PLearn::IntType, long_val_, PLearn::MissingCharacter, PLearn::MissingDate, PLearn::MissingDouble, PLearn::MissingInt, PLearn::MissingShort, PLearn::MissingSignedChar, PLearn::MissingString, PLearn::FieldValue::DateVal_t::month, PLearn::PDate::month, PLearn::ShortType, PLearn::SignedCharType, string_val_, PLearn::StringType, PLearn::Unknown, PLearn::FieldValue::DateVal_t::year, and PLearn::PDate::year.
Referenced by PLearn::SDBVMFieldDateDiff::convertField().
{ switch (field_type_) { case Unknown: break; case StringType: if (string_val_) string_val_[0] = MissingString; break; case CharacterType: long_val_ = long(MissingCharacter); break; case SignedCharType:long_val_ = long(MissingSignedChar); break; case ShortType: long_val_ = long(MissingShort); break; case IntType: long_val_ = long(MissingInt); break; case FloatType: case DoubleType: double_val_ = MissingDouble; break; case DateType: date_val_.year = MissingDate.year; date_val_.month = MissingDate.month; date_val_.day = MissingDate.day; break; } }
void PLearn::FieldValue::swap | ( | FieldValue & | rhs | ) |
Swap the guts of this with someone else.
Definition at line 534 of file SimpleDB.cc.
References PLearn::CharacterType, date_val_, PLearn::DateType, double_val_, PLearn::DoubleType, field_type_, PLearn::FloatType, PLearn::IntType, long_val_, precision_, PLearn::ShortType, PLearn::SignedCharType, string_val_, PLearn::StringType, and PLearn::Unknown.
Referenced by operator=().
{ std::swap(field_type_, rhs.field_type_); std::swap(precision_, rhs.precision_); switch(field_type_) { case Unknown: break; case StringType: std::swap(string_val_, rhs.string_val_); break; case CharacterType: case SignedCharType: case ShortType: case IntType: std::swap(long_val_, rhs.long_val_); break; case FloatType: case DoubleType: std::swap(double_val_, rhs.double_val_); break; case DateType: std::swap(date_val_, rhs.date_val_); break; } }
PDate PLearn::FieldValue::toDate | ( | ) | const |
Definition at line 296 of file SimpleDB.cc.
References date_val_, PLearn::DateType, PLearn::FieldValue::DateVal_t::day, field_type_, PLearn::FieldValue::DateVal_t::month, PLERROR, and PLearn::FieldValue::DateVal_t::year.
Referenced by PLearn::SDBVMFieldICBCTargets::convertField(), PLearn::SDBVMFieldDateDiff::convertField(), and PLearn::SDBVMFieldDateGreater::getDiscreteValue().
{ switch(field_type_) { case DateType: return PDate(date_val_.year, date_val_.month, date_val_.day); default: PLERROR("Cannot convert non-date field type to a date"); } return PDate(); }
double PLearn::FieldValue::toDouble | ( | ) | const |
Definition at line 267 of file SimpleDB.cc.
References PLearn::CharacterType, PLearn::date_to_float(), date_val_, PLearn::DateType, PLearn::FieldValue::DateVal_t::day, double_val_, PLearn::DoubleType, field_type_, PLearn::FloatType, PLearn::IntType, isMissing(), long_val_, MISSING_VALUE, PLearn::FieldValue::DateVal_t::month, PLERROR, PLearn::ShortType, PLearn::SignedCharType, PLearn::StringType, PLearn::Unknown, and PLearn::FieldValue::DateVal_t::year.
{ if (isMissing()) return MISSING_VALUE; switch (field_type_) { case Unknown: return MISSING_VALUE; case StringType: case CharacterType: PLERROR("Cannot convert string or character field to double"); break; case SignedCharType: case ShortType: case IntType: return double(long_val_); case FloatType: case DoubleType: return double_val_; case DateType: return double(date_to_float(PDate(date_val_.year, date_val_.month, date_val_.day))); } return MISSING_VALUE; }
string PLearn::FieldValue::toString | ( | ) | const |
Conversion to strings and doubles.
Definition at line 248 of file SimpleDB.cc.
References PLearn::CharacterType, date_val_, PLearn::DateType, PLearn::FieldValue::DateVal_t::day, double_val_, PLearn::DoubleType, field_type_, PLearn::FloatType, PLearn::PDate::info(), PLearn::IntType, isMissing(), long_val_, PLearn::FieldValue::DateVal_t::month, PLearn::ShortType, PLearn::SignedCharType, PLearn::space_to_underscore(), string_val_, PLearn::StringType, PLearn::tostring(), PLearn::Unknown, and PLearn::FieldValue::DateVal_t::year.
Referenced by PLearn::operator<<(), and PLearn::FieldRowRef::operator=().
{ if (isMissing()) return ""; switch (field_type_) { case Unknown: return ""; case StringType: return space_to_underscore(string_val_); case CharacterType: return string(1,char(long_val_)); case SignedCharType: case ShortType: case IntType: return tostring(long_val_); case FloatType: case DoubleType: return tostring(double_val_); case DateType: return PDate(date_val_.year, date_val_.month, date_val_.day).info(); } return ""; }
friend class FieldRowRef [friend] |
Definition at line 233 of file SimpleDB.h.
union { ... } [private] |
Definition at line 330 of file SimpleDB.h.
Referenced by FieldValue(), isMissing(), operator-(), operator<(), PLearn::FieldRowRef::operator=(), operator==(), setMissing(), swap(), toDate(), toDouble(), and toString().
Definition at line 329 of file SimpleDB.h.
Referenced by FieldValue(), isMissing(), operator*(), operator+(), operator-(), operator/(), operator<(), PLearn::FieldRowRef::operator=(), operator==(), setMissing(), swap(), toDouble(), and toString().
FieldType PLearn::FieldValue::field_type_ [private] |
Definition at line 320 of file SimpleDB.h.
Referenced by FieldValue(), isMissing(), operator*(), operator+(), operator-(), operator/(), operator<(), operator==(), setMissing(), swap(), toDate(), toDouble(), toString(), and ~FieldValue().
Definition at line 328 of file SimpleDB.h.
Referenced by FieldValue(), isMissing(), operator*(), operator+(), operator-(), operator/(), operator<(), PLearn::FieldRowRef::operator=(), operator==(), setMissing(), swap(), toDouble(), and toString().
int PLearn::FieldValue::precision_ [private] |
Definition at line 321 of file SimpleDB.h.
Referenced by FieldValue(), and swap().
Definition at line 327 of file SimpleDB.h.
Referenced by FieldValue(), isMissing(), operator<(), operator==(), setMissing(), swap(), toString(), and ~FieldValue().