Isis 3 Programmer Reference
ImportPdsTable.h
Go to the documentation of this file.
1 #ifndef ImportPdsTable_h
2 #define ImportPdsTable_h
3 
25 #include <QString>
26 #include <QList>
27 #include <QStringList>
28 
29 #include <fstream>
30 #include <vector>
31 #include <string>
32 
33 class QString;
34 
35 namespace Isis {
36  class Table;
37  class TableField;
38  class TableRecord;
39  class PvlObject;
117  public:
118  ImportPdsTable();
119  ImportPdsTable(const QString &pdsLabFile,
120  const QString &pdsTabFile="",
121  const QString &pdsTableName ="TABLE");
122  virtual ~ImportPdsTable();
123 
124  QString name() const;
125  void setName(const QString &name = "TABLE");
126 
127  int columns() const;
128  int rows() const;
129 
130  void load(const QString &pdsLabFile, const QString &pdsTabFile = "",
131  const QString &pdsTableName = "TABLE");
132 
133  bool hasColumn(const QString &colName) const;
134  QString getColumnName(const unsigned int &index = 0,
135  const bool &formatted = true) const;
136  QStringList getColumnNames(const bool &formatted = true) const;
137  QString getFormattedName(const QString &colname) const;
138 
139  QString getType(const QString &colName) const;
140  bool setType(const QString &colName, const QString &dataType);
141 
142  Table importTable(const QString &isisTableName);
143  Table importTable(const QString &colNames,
144  const QString &isisTableName);
145  Table importTable(const QStringList &colNames,
146  const QString &isisTableName);
147 
148 
149  protected:
150  struct ColumnDescr {
151  QString m_name;
152  int m_colnum;
153  QString m_dataType;
157  int m_items;
158  };
159 
160  // Internal types
162  typedef QStringList Columns;
163  typedef QList<Columns> Rows;
164 
165  const ColumnDescr &getColumnDescriptor(const int &nth) const;
166  ColumnDescr *findColumn(const QString &colName);
167  const ColumnDescr *findColumn(const QString &colName) const;
168 
169 
170  QString getColumnValue(const QString &tline,
171  const ColumnDescr &cdesc,
172  const QString &delimiter = "") const;
173  QStringList getColumnFields(const QString &tline,
174  const ColumnDescr &cdesc,
175  const QString &delimiter = "") const;
176 
177 
178  QString getGenericType(const QString &ttype) const;
179 
180  virtual bool processRow(const int &row, const QString &rowdata);
181 
182 
183  private:
184  void init();
185 
186  void loadLabel(const QString &labfile, QString &tblfile,
187  const QString &tblname = "");
188  void loadTable(const QString &tabfile);
189 
190  ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const;
191 
192  TableRecord makeRecord(const ColumnTypes &ctypes);
193  TableField makeField(const ColumnDescr &cdesc);
195  void setPdsByteOrder(QString byteOrder);
196 
197  TableField &extract(const Columns &columns, const ColumnDescr &cdesc,
198  TableField &field) const;
199  TableRecord &extract(const Columns &columns, const ColumnTypes &ctypes,
200  TableRecord &record) const;
201  TableRecord extractBinary(char *rowBuffer, TableRecord &record) const;
202 
203  void fillTable(Table &table, const ColumnTypes &columns,
204  TableRecord &record) const;
205 
206  //private instance variables
207  int m_trows;
210  QString m_pdsTableType;
213  QString m_tableName;
214  QString m_pdsTableFile;
216  QString m_byteOrder;
218  };
219 
220 }
221 #endif
222 
virtual bool processRow(const int &row, const QString &rowdata)
Process a freshly read PDS table line of data.
int rows() const
Returns the number of rows in the table.
QString getGenericType(const QString &ttype) const
Determine generic data type of a column.
Table importTable(const QString &isisTableName)
Populate a Table object with the PDS table and return it.
TableRecord extractBinary(char *rowBuffer, TableRecord &record) const
This method is used to set the field values for the given record.
int m_rowBytes
The number of bytes for one PDS table row.
int m_itemBytes
Number bytes per item.
QString name() const
Return the name of the PDS table.
void fillTable(Table &table, const ColumnTypes &columns, TableRecord &record) const
Fill the ISIS Table object with PDS table data.
void loadTable(const QString &tabfile)
Loads the contents of a PDS table data file.
QString m_name
Name of column.
QString getType(const QString &colName) const
Get the type associated with the specified column.
QStringList getColumnNames(const bool &formatted=true) const
Return the names of all the columns.
QStringList getColumnFields(const QString &tline, const ColumnDescr &cdesc, const QString &delimiter="") const
Extracts column fields from a QString based upon a description.
int m_pdsTableStart
The start byte of the PDS table data.
void load(const QString &pdsLabFile, const QString &pdsTabFile="", const QString &pdsTableName="TABLE")
Loads a PDS table label and (optional) data file.
void setPdsByteOrder(QString byteOrder)
Sets the byte order for BINARY PDS table files.
virtual ~ImportPdsTable()
Destructs the ImportPdsTable object.
void init()
Initialize object variables.
QString getColumnName(const unsigned int &index=0, const bool &formatted=true) const
Returns the name of the specifed column.
int columns() const
Returns the number of columns in the table.
Rows m_rows
Table data.
void setName(const QString &name="TABLE")
Set the name of the PDS table object.
TableRecord makeRecord(const ColumnTypes &ctypes)
Creates a TableRecord for columns.
QString m_pdsTableType
The INTERCHANGE_FORMAT value for the table.
ColumnTypes m_coldesc
Column descriptions.
bool hasColumn(const QString &colName) const
This method determines whether the PDS table has a column with the given name.
QString m_pdsTableFile
The name of the file containing the table data.
int m_items
Number of items in column.
QString getColumnValue(const QString &tline, const ColumnDescr &cdesc, const QString &delimiter="") const
Extracts a column from a QString based upon a description.
bool setType(const QString &colName, const QString &dataType)
Change the datatype for a column.
TableField makeFieldFromBinaryTable(const ColumnDescr &cdesc)
Creates an empty TableField with the appropriate type from a binary PDS table column description...
int m_trows
Number rows in table according to label.
Class for storing Table blobs information.
Definition: Table.h:77
QString m_tableName
The name of the PDS table object.
QString getFormattedName(const QString &colname) const
Converts a column name to a camel-case after it has been cleansed.
void loadLabel(const QString &labfile, QString &tblfile, const QString &tblname="")
Loads the contents of a PDS table label description.
int m_startByte
Starting byte of data.
ImportPdsTable()
Default constructor.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const
Extract a column description from a COLUMN object.
TableField makeField(const ColumnDescr &cdesc)
Creates a TableField for the column type.
QString m_byteOrder
The byte order of the PDS table file, if binary.
Class for storing an Isis::Table&#39;s field information.
Definition: TableField.h:63
TableField & extract(const Columns &columns, const ColumnDescr &cdesc, TableField &field) const
Extract a TableField from a PDS column in the text row.
int m_numBytes
Number bytes in column.
QString m_dataType
PDS table DATA_TYPE of column.
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
const ColumnDescr & getColumnDescriptor(const int &nth) const
Retrieve a column description by index.
Import a PDS table file with a label description.
int m_recordBytes
The number of bytes for one Isis table record.
ColumnDescr * findColumn(const QString &colName)
Searches internal column descriptors for a named column.