USGS

Isis 3.0 Developer's Reference (API)

Home

ImportPdsTable.h

Go to the documentation of this file.
00001 #ifndef ImportPdsTable_h
00002 #define ImportPdsTable_h
00003 
00025 #include <fstream>
00026 #include <vector>
00027 #include <string>
00028 
00029 #include "iException.h"
00030 #include "iString.h"
00031 #include "Pvl.h"
00032 #include "Table.h"
00033 
00034 namespace Isis {         
00055 class ImportPdsTable {
00056   public:
00057     ImportPdsTable();
00058     ImportPdsTable(const std::string &labfile);
00059     ImportPdsTable(const std::string &labfile, const std::string &tabfile);
00060     ~ImportPdsTable() {}
00061 
00062 
00064     int columns() const { return (m_coldesc.size()); }
00065 
00067     int rows() const { return (m_rows.size()); }
00068 
00069     void load(const std::string &labfile, const std::string &tabfile = "");
00070 
00071     bool hasColumn(const std::string &colName) const;
00072     std::string getColumnName(const int &index = 0, const bool &formatted = true) 
00073                              const;
00074     std::vector<std::string> getColumnNames(const bool &formatted = true) const;
00075 
00076     std::string getType(const std::string &colName) const;
00077     bool setType(const std::string &colName, const std::string &dtype);
00078 
00079     Table exportAsTable(const std::string &tname) const;
00080     Table exportAsTable(const std::string &colNames, 
00081                         const std::string &tname) const;
00082     Table exportAsTable(const std::vector<std::string> &colNames, 
00083                         const std::string &tname) const;
00084 
00085   private:
00086     struct ColumnDescr {
00087       std::string m_name;    // Name of column
00088       int         m_colnum;  // Column number
00089       std::string m_type;    // Type of column
00090       int         m_sbyte;   // Starting byte of data
00091       int         m_nbytes;  // Number bytes in column
00092     };
00093 
00094     typedef std::vector<ColumnDescr> ColumnTypes;
00095     typedef std::vector<iString>     Columns;
00096     typedef std::vector<Columns>     Rows;
00097 
00098   //private instance variables
00099     int         m_trows;      // Number rows in table according to label
00100     ColumnTypes m_coldesc;    // Column descriptions
00101     Rows        m_rows;       //  Table data
00102 
00103     void init();
00104 
00105     void loadLabel(const std::string &labfile, std::string &tblfile) 
00106                    throw (iException &);
00107     void loadTable(const std::string &tabfile) throw (iException &);
00108 
00109     ColumnDescr getColumnDescription(PvlObject &colobj, int nth) const;
00110     ColumnDescr *findColumn(const std::string &colName);
00111     const ColumnDescr *findColumn(const std::string &colName) const;
00112 
00113     std::string getColumnValue(const std::string &tline, 
00114                                const ColumnDescr &cdesc) const;
00115     std::string getFormattedName(const std::string &colname) const;
00116     std::string getGenericType(const std::string &ttype) const;
00117 
00118     TableField makeField(const ColumnDescr &cdesc) const;
00119     TableRecord makeRecord(const ColumnTypes &ctypes) const;
00120 
00121     TableField &extract(const Columns &columns, const ColumnDescr &cdesc,
00122                         TableField &field) const;
00123     TableRecord &extract(const Columns &columns, const ColumnTypes &ctypes,
00124                          TableRecord &record) const;
00125 
00126     void fillTable(Table &table, const ColumnTypes &columns,
00127                    TableRecord &record) const;
00128 };
00129 
00130 }
00131 #endif
00132