html/table.hh

00001 #ifndef HTML_TABLE_HH
00002 #define HTML_TABLE_HH
00003 
00004 #include "html/compound.hh"
00005 #include "html/Attrib.hh"
00006 #include <vector>
00007 #include <string>
00008 #include <stdexcept>
00009 
00010 namespace html {
00011   class align;
00012 
00019   class cell : public compound {
00020   public:
00024     cell(void);
00025 
00029     virtual ~cell(void);
00030 
00035     cell* clone(void) const;
00036 
00041     const char* getTag(void) const {return "td";}
00042 
00047     void setAlign(const std::string& a);
00048 
00053     void setSave(bool on);
00054   };
00055 
00066   class table : public object {
00067   public:
00071     table(void);
00072 
00077     table(const std::string& title);
00078 
00082     table(const table& x);
00083 
00087     virtual ~table(void);
00088 
00094     table* clone(void) const;
00095 
00100     table& operator=(const table& x);
00101 
00105     void write(writer& out) const;
00106 
00112     int  addColumn(const std::string& title);
00113 
00117     int  addRow(void);
00118 
00125     void eraseRow(int row, int count=1) throw(std::runtime_error);
00126 
00137     void insertData(int row, int col, double x, int wid=-1, int prec=-1) 
00138                     throw(std::runtime_error);
00139 
00151     void insertData(int row, int col, long x, int wid=-1, int radix=10) 
00152                     throw(std::runtime_error);
00153 
00162     void insertData(int row, int col, const std::string& txt) 
00163                     throw(std::runtime_error);
00164 
00174     void insertData(int row, int col, const object& obj) 
00175                     throw(std::runtime_error);
00176 
00186     void insertRow(int row) throw(std::runtime_error);
00187 
00192     int getNRow(void) const;
00193 
00198     int getNColumn(void) const;
00199 
00205     cell& refHeader(int col) throw(std::runtime_error);
00206 
00212     const cell& refHeader(int col) const throw(std::runtime_error);
00213 
00221     cell& refCell(int row, int col) throw(std::runtime_error);
00222 
00230     const cell& refCell(int row, int col) const throw(std::runtime_error);
00231 
00236     void setBorder(bool On=true);
00237 
00238   private:
00242     int inxrc(int row, int col) const throw(std::runtime_error);
00243 
00244   private:
00245     std::string mTitle;
00246     int mRow;
00247     typedef std::vector<cell> ColHdr;
00248     ColHdr    mCTitle;
00249     attList   mAttrib;
00250     typedef std::vector<cell*> TableData;
00251     TableData mData;
00252   };
00253 
00254 }
00255 
00256 //======================================  Inline functions
00257 inline int 
00258 html::table::getNColumn(void) const {
00259     return mCTitle.size();
00260 }
00261 
00262 inline int 
00263 html::table::getNRow(void) const {
00264     return mRow;
00265 }
00266 
00267 inline int
00268 html::table::inxrc(int row, int col) const throw(std::runtime_error) {
00269     if (row >= mRow || row < 0) throw std::runtime_error("Invalid Row.");
00270     int nCol = getNColumn();
00271     if (col >= nCol || col < 0) throw std::runtime_error("Invalid Column.");
00272     return row*nCol + col;
00273 }
00274 
00275 inline const html::cell& 
00276 html::table::refCell(int row, int col) const throw(std::runtime_error) {
00277     return *mData[inxrc(row, col)];
00278 }
00279 
00280 inline html::cell& 
00281 html::table::refCell(int row, int col) throw(std::runtime_error) {
00282     return *mData[inxrc(row, col)];
00283 }
00284 
00285 inline const html::cell& 
00286 html::table::refHeader(int col) const throw(std::runtime_error) {
00287     if (col<0 || col>=getNColumn()) throw std::runtime_error("Invalid Column.");
00288     return mCTitle[col];
00289 }
00290 
00291 inline html::cell& 
00292 html::table::refHeader(int col) throw(std::runtime_error) {
00293     if (col<0 || col>=getNColumn()) throw std::runtime_error("Invalid Column.");
00294     return mCTitle[col];
00295 }
00296 
00297 #endif  // HTML_TABLE_HH

Generated on Sun Mar 8 19:20:48 2009 for dmt by  doxygen 1.5.4