34 #include <suplibxx/str.h> 36 #include <rdbxx/RDBErr.h> 38 #include <rdbxx/RDBComment.h> 39 #include <rdbxx/RDBColumnTmplt.h> 45 friend std::istream&
operator>>( std::istream& is,
RDB& rdb );
48 friend std::ostream&
operator<<( std::ostream& os,
RDB& rdb );
54 enum Status { REOF=0x00, REOL=0x01, REOG=0x02, RBOG=0x04 };
60 RDB(
const std::string& name=
"", std::ios::openmode mode=std::ios::in );
63 RDB( std::istream* isptr );
65 RDB( std::ostream* osptr );
74 void open(
const std::string& name, std::ios::openmode mode=std::ios::in );
77 void open( std::istream* isptr );
79 void open( std::ostream* osptr );
105 void setGroup(
const std::string& name,
bool group=
true );
108 void setGroup(
const int idx,
bool group=
true );
110 bool getGroup(
const std::string& name );
119 void setComment(
const std::string& comm,
const int idx=-1 );
136 void setColumn(
const std::string& name,
const std::string& def,
const int idx=-1 );
153 void setName(
const size_t idx,
const std::string& name );
156 void setDef(
const size_t idx,
const std::string& def );
158 void setWidth(
const size_t idx,
const long width );
164 void setDesc(
const size_t idx,
const std::string& desc );
166 void mapData(
const size_t idx,
double data[],
const size_t nelems=1 );
168 void mapData(
const size_t idx,
long data[],
const size_t nelems=1 );
170 void mapData(
const size_t idx, std::string data[],
const size_t nelems=1 );
172 void setData(
const size_t idx,
const double data );
174 void setData(
const size_t idx,
const long data );
176 void setData(
const size_t idx,
const std::string& data );
179 void getName(
const size_t idx, std::string& name )
const;
181 void getDef(
const size_t idx, std::string& def );
183 void getWidth(
const size_t idx,
long& width )
const;
189 void getDesc(
const size_t idx, std::string& desc )
const;
191 void getData(
const size_t idx,
double& data );
193 void getData(
const size_t idx,
long& data );
195 void getData(
const size_t idx, std::string& data );
198 std::string
getName(
const size_t idx )
const;
200 std::string
getDef(
const size_t idx );
202 long getWidth(
const size_t idx )
const;
208 std::string
getDesc(
const size_t idx )
const;
219 void setName(
const std::string& name,
const std::string& newname );
222 void setDef(
const std::string& name,
const std::string& def );
224 void setWidth(
const std::string& name,
const long width );
230 void setDesc(
const std::string& name,
const std::string& desc );
232 void mapData(
const std::string& name,
double data[],
const size_t nelems=1 );
234 void mapData(
const std::string& name,
long data[],
const size_t nelems=1 );
236 void mapData(
const std::string& name, std::string data[],
const size_t nelems=1 );
238 void setData(
const std::string& name,
const double data );
240 void setData(
const std::string& name,
const long data );
242 void setData(
const std::string& name,
const std::string& data );
245 void getName(
const std::string& name, std::string& namefound )
const;
247 void getDef(
const std::string& name, std::string& def );
249 void getWidth(
const std::string& name,
long& width )
const;
255 void getDesc(
const std::string& name, std::string& desc )
const;
257 void getData(
const std::string& name,
double& data );
259 void getData(
const std::string& name,
long& data );
261 void getData(
const std::string& name, std::string& data );
264 std::string
getName(
const std::string& name )
const;
266 std::string
getDef(
const std::string& name );
268 long getWidth(
const std::string& name )
const;
274 std::string
getDesc(
const std::string& name )
const;
290 size_t nRows(
void );
297 std::vector<std::string>
parseLine(
const std::string& line )
const;
size_t _ncols
Number of columns.
void getData(const size_t idx, double &data)
Return the data of the RDBColumn at idx, converting if necessary.
size_t nColumns(void) const
Return number of columns in RDB object.
std::ios::openmode _mode
Open mode of the associated stream.
void setComment(const std::string &comm, const int idx=-1)
Add RDBComment in header of RDB object.
Just
Acceptable column justifications.
std::string _line
Line from RDB table.
size_t _nrows
Number of rows.
bool _knowrows
Indicates if associated file must be scanned to determine number of rows.
bool rewind(void)
Rewind the stream to the beginning of the first row of data.
bool _myosptr
Indicates if RDB object is responsible for deallocating the ostream.
RDBComment & getComment(const size_t idx)
Return RDBComment at given index.
bool _myisptr
Indicates if RDB object is responsible for deallocating the istream.
Status
Acceptable column justifications.
bool _firstread
Indicates if this is the first call to RDB::read.
friend std::ostream & operator<<(std::ostream &os, RDB &rdb)
Write table to output stream.
void getDesc(const size_t idx, std::string &desc) const
Return the description of the RDBColumn at idx.
bool _writehdr
Indicates if the header has been output.
void close(void)
Closes the stream attached to RDB object.
std::istream * _isptr
Istream attached to data file.
RDBLongColumn _nrcol
Hidden column, containing row number.
void getName(const size_t idx, std::string &name) const
Return the name of the RDBColumn at idx.
int read(void)
Read a line of data from the istream.
void parseHeader(void)
Parse header, i.e. comments and column names and definitions.
~RDB(void)
Deletes resources allocated by the RDB object.
RDBColumn ** _cols
Array of RDBColumns.
bool write(void)
Write a line of data to the ostream.
void setWidth(const size_t idx, const long width)
Modify the width of the RDBColumn at idx.
std::ostream * _osptr
Ostream attached to data file.
void setType(const size_t idx, const RDBColumn::Type type)
Modify the type of the RDBColumn at idx.
void setDesc(const size_t idx, const std::string &desc)
Modify the description of the RDBColumn at idx.
void setData(const size_t idx, const double data)
Sets the data value of RDBColumn, converting as necessary.
void setGroup(const std::string &name, bool group=true)
Turn on/off group status for the named column.
RDBColumn * getColumn(const size_t idx)
Return pointer to RDBColumn at given index.
size_t nRows(void)
Return number of rows in RDB object.
bool autoIdx(void) const
Indicates if auto-indexing is activated.
RDBComment * _comms
Array of RDBComments.
RDB(const std::string &name="", std::ios::openmode mode=std::ios::in)
Attaches RDB object to a file.
bool newGroup(void)
Checks if any column indicates a new group.
size_t _rewindto
Position of beginning of first row of data.
Provides interface for manipulating RDB tables.
size_t _ncomms
Number of comments.
void getType(const size_t idx, RDBColumn::Type &type) const
Return the type of the RDBColumn at idx.
Type
Acceptable column types.
void getWidth(const size_t idx, long &width) const
Return the width of the RDBColumn at idx.
void mapData(const size_t idx, double data[], const size_t nelems=1)
Map RDBColumn data to user-supplied memory.
long getDataLong(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
void getDef(const size_t idx, std::string &def)
Return the definition of the RDBColumn at idx.
size_t nComments(void) const
Return number of comments in RDB object.
void advanceIdx(void)
Increments the indices in the RDBColumn data elements.
void open(const std::string &name, std::ios::openmode mode=std::ios::in)
Attaches RDB object to a file.
void setColumn(const std::string &name, const std::string &def, const int idx=-1)
Add an RDBColumn in RDB object.
std::vector< std::string > parseLine(const std::string &line) const
Parse fields in a row.
void setName(const size_t idx, const std::string &name)
Modify the name of the RDBColumn at idx.
void setDef(const size_t idx, const std::string &def)
Modify the definition of the RDBColumn at idx.
std::string getDataString(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
bool _autoidx
Indicates if RDBColumn data elements should be advanced.
friend std::istream & operator>>(std::istream &is, RDB &rdb)
Read table from input stream.
std::string _filename
Name of RDB file.
bool _lastread
Indicates if this is the last call to RDB::read.
double getDataDouble(const size_t idx)
Return the data of the RDBColumn at idx, converting if necessary.
bool getGroup(const std::string &name)
Returns group status, true if its a new group, for the named column.
long _rownum
Current table row number.
long _frownum
Current file row number.
Provides interface for general column related methods.
bool * _mycols
Indicates if RDB object is responsible for deallocating given RDBColumn.
void getJust(const size_t idx, RDBColumn::Just &just) const
Return the just of the RDBColumn at idx.
void setJust(const size_t idx, const RDBColumn::Just just)
Modify the justification of the RDBColumn at idx.