26 #include "RDBColumn.h" 46 }
catch (
RDBErr& rdberr ) {
47 rdberr.set_message(
"operator>>(istream&,RDBColumn&): " );
51 throw(
RDBErr(
"operator>>(istream&,RDBColumn&): unexpected exception caught" ) );
77 }
catch (
RDBErr& rdberr ) {
78 rdberr.set_message(
"operator>>(istream&,RDBColumn*): " );
82 throw(
RDBErr(
"operator>>(istream&,RDBColumn*): unexpected exception caught" ) );
105 return col.
write( os );
124 return col->
write( os );
140 : _name(name), _def(def), _width(-1), _type(STRING), _just(LEFT),
141 _desc(
""), _changed(false), _throw(true), _errno(0),
142 _precision(DBL_DIG), _group(false), _initgroup(true) {
144 if ( !
_def.empty( ) ) {
148 }
catch (
RDBErr& rdberr ) {
149 rdberr.set_message(
"RDBColumn::RDBColumn(string&,string&): " );
153 throw(
RDBErr(
"RDBColumn::RDBColumn(string&,string&): unexpected exception caught" ) );
168 : _name(col._name), _def(col._def), _width(col._width),
169 _type(col._type), _just(col._just), _desc(col._desc),
170 _changed(col._changed), _throw(col._throw), _errno(col._errno),
171 _precision(col._precision), _group(col._group),
172 _initgroup(col._initgroup) {
195 if (
this != &col ) {
277 size_t defsize = def.size( );
278 char* cdef =
new char[defsize+1];
279 strcpy( cdef, def.c_str() );
283 if ( isdigit( cdef[0] ) ) {
285 _width = strtol( cdef, &ptr, 10 );
292 if ( NUMERIC == cdef[n] || STRING == cdef[n] || MONTH == cdef[n] ) {
295 }
else if (
'-' == cdef[n] ) {
297 while (
'-' == cdef[n] ) {
303 throw(
RDBErr(
string(
"RDBColumn::setDef(string&): Bad type in column defintion '") + def +
"' for '" +
_name +
"'" ) );
307 if (
'\0' != cdef[n] && ( LEFT == cdef[n] || RIGHT == cdef[n] ) ) {
312 if (
'\0' != cdef[n] ) {
313 if (
' ' == cdef[n] ) {
314 while (
' ' == cdef[n] ) {
322 throw(
RDBErr(
string(
"RDBColumn::setDef(string&): Bad just in column defintion '") + def +
"' for '" +
_name +
"'" ) );
453 throw(
RDBErr(
string(
"RDBColumn::mapData(double[],size_t): Wrong data type: double[] in column '") +
_name +
"'" ) );
464 throw(
RDBErr(
string(
"RDBColumn::mapData(long[],size_t): Wrong data type: long[] in column '") +
_name +
"'" ) );
475 throw(
RDBErr(
string(
"RDBColumn::mapData(stringdouble[],size_t): Wrong data type: string[] in column '") +
_name +
"'" ) );
510 if ( RDBColumn::NUMERIC ==
_type )
512 else if ( RDBColumn::STRING ==
_type )
517 if ( RDBColumn::LEFT ==
_just )
522 if ( 0 != _desc.length( ) ) 523 _strstrm << ' ' << _desc; 526 _def = _strstrm.str( ).c_str( ); 592 RDBColumn::getPrecision( 622 return strerror( _errno ); 669 odata = (long) idata; 690 if ( ! _strstrm.good( ) ) 692 _strstrm << setprecision( _precision ) << idata << '\0
'; 693 odata = _strstrm.str( ).c_str( ); 710 odata = (double) idata; 747 if ( ! _strstrm.good( ) ) 749 _strstrm << idata << '\0
'; 750 odata = _strstrm.str( ).c_str( ); 771 odata = strtod( idata.length( ) ? idata.c_str( ) : "NaN", &endptr ); 773 if ( ( endptr && ( *endptr != '\0
' ) ) ) { 775 throw( RDBErr( string("RDBColumn::convert(string&,double&): Non numeric data in column '") + _name + "' at '" + endptr + "'" ) ); 778 _errno = RDBColumn::OUTOFRANGE; 803 odata = strtol( idata.length( ) ? idata.c_str( ) : "NaN", &endptr, 10 ); 805 if ( ( endptr && *endptr != '\0
' ) ) { 806 if ( *endptr != '.
' ) { 808 throw( RDBErr( string("RDBColumn::convert(string&,long&): Non numeric data in column '") + _name + "' at '" + endptr + "'" ) ); 811 _errno = RDBColumn::NONNUMERIC; 815 char* beginptr = endptr+1; 817 strtol( beginptr, &endptr, 10 ); 819 if ( ( endptr && *endptr != '\0
' ) ) { 821 throw( RDBErr( string("RDBColumn::convert(string&,long&): Non numeric data in column '") + _name + "'at '" + endptr + "'" ) ); 824 _errno = RDBColumn::NONNUMERIC; 829 throw( RDBErr( string("RDBColumn::convert(string&,long&): Lost precision in column '") + _name + "'" ) ); 832 _errno = RDBColumn::LOSTPRECISION; 873 if ( ! is.good( ) ) { 874 throw( RDBErr( string("RDBColumn::extract(istream&,double&): Non numeric data in column '") + _name + "'" ) ); 897 if ( ! is.good( ) ) { 898 throw( RDBErr( string("RDBColumn::extract(istream&,long&): Non numeric data in column '") + _name + "'" ) ); 924 if ( ! is.good( ) ) { 925 throw( RDBErr( string("RDBColumn::extract(stream&,string&): Row format error in column '") + _name + "'" ) ); 929 while ( ' ' == is.peek( ) ) { 931 if ( ! is.good( ) ) { 932 throw( RDBErr( string("RDBColumn::extract(stream&,string&): Row format error in column '") + _name + "'" ) ); 958 return os << setprecision( _precision ) << data; 977 return os << setprecision( _precision ) << data; 996 return os << setprecision( _precision ) << data;
string getName(void) const
Returns the name.
bool _throw
State of the exception throwing behavior.
void setPrecision(const int precision)
Sets the precision for numeric output and numeric to string conversion.
RDBColumn & operator=(const RDBColumn &col)
Copies RDBColumn object.
Just
Acceptable column justifications.
void setErrNo(const int no=0)
Sets the error status.
void setName(const string &name)
Sets the name.
stringstream _strstrm
Used for numeric to string conversion.
bool _changed
Indicates state for the definition field.
void setWidth(const long width)
Sets the width.
void setJust(const RDBColumn::Just just)
Sets the justification.
void setType(const RDBColumn::Type type)
Sets the type.
void setDef(const string &def)
Sets the definition.
The parent class for all RDB related exceptions.
virtual void setGroup(bool group)
Turn on/off group tracking for this column object.
bool getGroup(void) const
Returns group status, RBOG if at beginning of a group, REOG if at ned of a group, or REOL if in the m...
RDBColumn::Type _type
Data type.
RDBColumn::Just _just
Justification.
int _precision
Precision used for stream output or numeric to string conversion.
virtual void mapData(double data[], const size_t nelems=1)
Maps data to user-supplied memory, if possible.
Type
Acceptable column types.
virtual istream & read(istream &is)=0
Called by the stream insertion operator.
void setDesc(const string &desc)
Sets the description.
virtual ostream & write(ostream &os) const =0
Called by the stream extraction operator.
bool _group
This is a group column.
void setThrow(const bool t=true)
Sets the excpeption throwing behavior.
string getDef(void)
Returns the definition.
virtual ~RDBColumn(void)
Deletes resources allocated by RDBColumn object.
RDBColumn(const string &name="", const string &def="")
Assigns name and definition to RDBColumn object.
Provides interface for general column related methods.