Isis 3 Programmer Reference
ImportPdsTable.h
1 #ifndef ImportPdsTable_h
2 #define ImportPdsTable_h
3 
8 /* SPDX-License-Identifier: CC0-1.0 */
9 
10 #include <QString>
11 #include <QList>
12 #include <QStringList>
13 
14 #include <fstream>
15 #include <vector>
16 #include <string>
17 
18 class QString;
19 
20 namespace Isis {
21  class Table;
22  class TableField;
23  class TableRecord;
24  class PvlObject;
102  public:
103  ImportPdsTable();
104  ImportPdsTable(const QString &pdsLabFile,
105  const QString &pdsTabFile="",
106  const QString &pdsTableName ="TABLE");
107  virtual ~ImportPdsTable();
108 
109  QString name() const;
110  void setName(const QString &name = "TABLE");
111 
112  int columns() const;
113  int rows() const;
114 
115  void load(const QString &pdsLabFile, const QString &pdsTabFile = "",
116  const QString &pdsTableName = "TABLE");
117 
118  bool hasColumn(const QString &colName) const;
119  QString getColumnName(const unsigned int &index = 0,
120  const bool &formatted = true) const;
121  QStringList getColumnNames(const bool &formatted = true) const;
122  QString getFormattedName(const QString &colname) const;
123 
124  QString getType(const QString &colName) const;
125  bool setType(const QString &colName, const QString &dataType);
126 
127  Table importTable(const QString &isisTableName);
128  Table importTable(const QString &colNames,
129  const QString &isisTableName);
130  Table importTable(const QStringList &colNames,
131  const QString &isisTableName);
132 
133 
134  protected:
135  struct ColumnDescr {
136  QString m_name;
137  int m_colnum;
138  QString m_dataType;
142  int m_items;
143  };
144 
145  // Internal types
147  typedef QStringList Columns;
148  typedef QList<Columns> Rows;
149 
150  const ColumnDescr &getColumnDescriptor(const int &nth) const;
151  ColumnDescr *findColumn(const QString &colName);
152  const ColumnDescr *findColumn(const QString &colName) const;
153 
154 
155  QString getColumnValue(const QString &tline,
156  const ColumnDescr &cdesc,
157  const QString &delimiter = "") const;
158  QStringList getColumnFields(const QString &tline,
159  const ColumnDescr &cdesc,
160  const QString &delimiter = "") const;
161 
162 
163  QString getGenericType(const QString &ttype) const;
164 
165  virtual bool processRow(const int &row, const QString &rowdata);
166 
167 
168  private:
169  void init();
170 
171  void loadLabel(const QString &labfile, QString &tblfile,
172  const QString &tblname = "");
173  void loadTable(const QString &tabfile);
174 
175  ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const;
176 
177  TableRecord makeRecord(const ColumnTypes &ctypes);
178  TableField makeField(const ColumnDescr &cdesc);
180  void setPdsByteOrder(QString byteOrder);
181 
182  TableField &extract(const Columns &columns, const ColumnDescr &cdesc,
183  TableField &field) const;
184  TableRecord &extract(const Columns &columns, const ColumnTypes &ctypes,
185  TableRecord &record) const;
186  TableRecord extractBinary(char *rowBuffer, TableRecord &record) const;
187 
188  void fillTable(Table &table, const ColumnTypes &columns,
189  TableRecord &record) const;
190 
191  //private instance variables
192  int m_trows;
195  QString m_pdsTableType;
198  QString m_tableName;
199  QString m_pdsTableFile;
201  QString m_byteOrder;
203  };
204 
205 }
206 #endif
Isis::ImportPdsTable::makeField
TableField makeField(const ColumnDescr &cdesc)
Creates a TableField for the column type.
Definition: ImportPdsTable.cpp:820
Isis::ImportPdsTable::getColumnName
QString getColumnName(const unsigned int &index=0, const bool &formatted=true) const
Returns the name of the specifed column.
Definition: ImportPdsTable.cpp:211
Isis::ImportPdsTable::m_pdsTableFile
QString m_pdsTableFile
The name of the file containing the table data.
Definition: ImportPdsTable.h:199
Isis::ImportPdsTable::m_pdsTableStart
int m_pdsTableStart
The start byte of the PDS table data.
Definition: ImportPdsTable.h:200
Isis::ImportPdsTable::makeRecord
TableRecord makeRecord(const ColumnTypes &ctypes)
Creates a TableRecord for columns.
Definition: ImportPdsTable.cpp:856
Isis::ImportPdsTable::fillTable
void fillTable(Table &table, const ColumnTypes &columns, TableRecord &record) const
Fill the ISIS Table object with PDS table data.
Definition: ImportPdsTable.cpp:950
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::ImportPdsTable
Import a PDS table file with a label description.
Definition: ImportPdsTable.h:101
Isis::ImportPdsTable::load
void load(const QString &pdsLabFile, const QString &pdsTabFile="", const QString &pdsTableName="TABLE")
Loads a PDS table label and (optional) data file.
Definition: ImportPdsTable.cpp:132
QList< ColumnDescr >
Isis::ImportPdsTable::ColumnDescr::m_items
int m_items
Number of items in column.
Definition: ImportPdsTable.h:142
Isis::ImportPdsTable::ColumnDescr
Definition: ImportPdsTable.h:135
Isis::ImportPdsTable::loadTable
void loadTable(const QString &tabfile)
Loads the contents of a PDS table data file.
Definition: ImportPdsTable.cpp:534
Isis::ImportPdsTable::getColumnDescriptor
const ColumnDescr & getColumnDescriptor(const int &nth) const
Retrieve a column description by index.
Definition: ImportPdsTable.cpp:614
Isis::ImportPdsTable::ColumnDescr::m_colnum
int m_colnum
Column number.
Definition: ImportPdsTable.h:137
Isis::ImportPdsTable::processRow
virtual bool processRow(const int &row, const QString &rowdata)
Process a freshly read PDS table line of data.
Definition: ImportPdsTable.cpp:1212
Isis::ImportPdsTable::ColumnDescr::m_startByte
int m_startByte
Starting byte of data.
Definition: ImportPdsTable.h:139
Isis::ImportPdsTable::ColumnDescr::m_numBytes
int m_numBytes
Number bytes in column.
Definition: ImportPdsTable.h:140
Isis::ImportPdsTable::rows
int rows() const
Returns the number of rows in the table.
Definition: ImportPdsTable.cpp:1011
Isis::ImportPdsTable::getFormattedName
QString getFormattedName(const QString &colname) const
Converts a column name to a camel-case after it has been cleansed.
Definition: ImportPdsTable.cpp:759
Isis::ImportPdsTable::getGenericType
QString getGenericType(const QString &ttype) const
Determine generic data type of a column.
Definition: ImportPdsTable.cpp:798
Isis::TableRecord
Definition: TableRecord.h:38
QStringList
Isis::ImportPdsTable::getColumnValue
QString getColumnValue(const QString &tline, const ColumnDescr &cdesc, const QString &delimiter="") const
Extracts a column from a QString based upon a description.
Definition: ImportPdsTable.cpp:690
Isis::ImportPdsTable::ImportPdsTable
ImportPdsTable()
Default constructor.
Definition: ImportPdsTable.cpp:43
Isis::ImportPdsTable::m_coldesc
ColumnTypes m_coldesc
Column descriptions.
Definition: ImportPdsTable.h:193
Isis::ImportPdsTable::~ImportPdsTable
virtual ~ImportPdsTable()
Destructs the ImportPdsTable object.
Definition: ImportPdsTable.cpp:84
Isis::ImportPdsTable::setPdsByteOrder
void setPdsByteOrder(QString byteOrder)
Sets the byte order for BINARY PDS table files.
Definition: ImportPdsTable.cpp:1191
Isis::ImportPdsTable::setType
bool setType(const QString &colName, const QString &dataType)
Change the datatype for a column.
Definition: ImportPdsTable.cpp:295
Isis::ImportPdsTable::m_recordBytes
int m_recordBytes
The number of bytes for one Isis table record.
Definition: ImportPdsTable.h:197
Isis::ImportPdsTable::m_byteOrder
QString m_byteOrder
The byte order of the PDS table file, if binary.
Definition: ImportPdsTable.h:201
Isis::ImportPdsTable::m_trows
int m_trows
Number rows in table according to label.
Definition: ImportPdsTable.h:192
Isis::ImportPdsTable::makeFieldFromBinaryTable
TableField makeFieldFromBinaryTable(const ColumnDescr &cdesc)
Creates an empty TableField with the appropriate type from a binary PDS table column description.
Definition: ImportPdsTable.cpp:1102
Isis::Table
Class for storing Table blobs information.
Definition: Table.h:61
Isis::ImportPdsTable::init
void init()
Initialize object variables.
Definition: ImportPdsTable.cpp:401
Isis::ImportPdsTable::getColumnDescription
ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const
Extract a column description from a COLUMN object.
Definition: ImportPdsTable.cpp:572
Isis::ImportPdsTable::m_rows
Rows m_rows
Table data.
Definition: ImportPdsTable.h:194
Isis::ImportPdsTable::getColumnNames
QStringList getColumnNames(const bool &formatted=true) const
Return the names of all the columns.
Definition: ImportPdsTable.cpp:242
Isis::ImportPdsTable::ColumnDescr::m_name
QString m_name
Name of column.
Definition: ImportPdsTable.h:136
Isis::ImportPdsTable::m_rowBytes
int m_rowBytes
The number of bytes for one PDS table row.
Definition: ImportPdsTable.h:196
Isis::ImportPdsTable::ColumnDescr::m_dataType
QString m_dataType
PDS table DATA_TYPE of column.
Definition: ImportPdsTable.h:138
Isis::ImportPdsTable::getColumnFields
QStringList getColumnFields(const QString &tline, const ColumnDescr &cdesc, const QString &delimiter="") const
Extracts column fields from a QString based upon a description.
Definition: ImportPdsTable.cpp:712
Isis::ImportPdsTable::importTable
Table importTable(const QString &isisTableName)
Populate a Table object with the PDS table and return it.
Definition: ImportPdsTable.cpp:318
Isis::ImportPdsTable::name
QString name() const
Return the name of the PDS table.
Definition: ImportPdsTable.cpp:89
Isis::ImportPdsTable::hasColumn
bool hasColumn(const QString &colName) const
This method determines whether the PDS table has a column with the given name.
Definition: ImportPdsTable.cpp:186
Isis::ImportPdsTable::loadLabel
void loadLabel(const QString &labfile, QString &tblfile, const QString &tblname="")
Loads the contents of a PDS table label description.
Definition: ImportPdsTable.cpp:438
Isis::ImportPdsTable::findColumn
ColumnDescr * findColumn(const QString &colName)
Searches internal column descriptors for a named column.
Definition: ImportPdsTable.cpp:642
Isis::ImportPdsTable::ColumnDescr::m_itemBytes
int m_itemBytes
Number bytes per item.
Definition: ImportPdsTable.h:141
Isis::ImportPdsTable::m_tableName
QString m_tableName
The name of the PDS table object.
Definition: ImportPdsTable.h:198
Isis::ImportPdsTable::extract
TableField & extract(const Columns &columns, const ColumnDescr &cdesc, TableField &field) const
Extract a TableField from a PDS column in the text row.
Definition: ImportPdsTable.cpp:882
Isis::ImportPdsTable::setName
void setName(const QString &name="TABLE")
Set the name of the PDS table object.
Definition: ImportPdsTable.cpp:98
Isis::ImportPdsTable::m_pdsTableType
QString m_pdsTableType
The INTERCHANGE_FORMAT value for the table.
Definition: ImportPdsTable.h:195
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16
Isis::ImportPdsTable::getType
QString getType(const QString &colName) const
Get the type associated with the specified column.
Definition: ImportPdsTable.cpp:268
Isis::ImportPdsTable::columns
int columns() const
Returns the number of columns in the table.
Definition: ImportPdsTable.cpp:999
Isis::ImportPdsTable::extractBinary
TableRecord extractBinary(char *rowBuffer, TableRecord &record) const
This method is used to set the field values for the given record.
Definition: ImportPdsTable.cpp:1031
Isis::TableField
Class for storing an Isis::Table's field information.
Definition: TableField.h:47