Commit eb3a4caff766f3e9eaa8f934e811ef596b0e820f
1 parent
6c96b7ca
replace FITS table column() method by access operator[]
Showing
2 changed files
with
179 additions
and
17 deletions
include/GFitsTable.hpp
| ... | ... | @@ -59,22 +59,24 @@ public: |
| 59 | 59 | virtual ~GFitsTable(void); |
| 60 | 60 | |
| 61 | 61 | // Operators |
| 62 | - GFitsTable& operator= (const GFitsTable& table); | |
| 62 | + GFitsTable& operator=(const GFitsTable& table); | |
| 63 | + GFitsTableCol& operator[](const int& colnum); | |
| 64 | + const GFitsTableCol& operator[](const int& colnum) const; | |
| 65 | + GFitsTableCol& operator[](const std::string& colname); | |
| 66 | + const GFitsTableCol& operator[](const std::string& colname) const; | |
| 63 | 67 | |
| 64 | 68 | // Pure virtual methods |
| 65 | 69 | virtual GFitsTable* clone(void) const = 0; |
| 66 | 70 | |
| 67 | 71 | // Implemented Methods |
| 68 | - void append_column(GFitsTableCol& column); | |
| 69 | - void insert_column(int colnum, GFitsTableCol& column); | |
| 70 | - void append_rows(const int& nrows); | |
| 71 | - void insert_rows(const int& rownum, const int& nrows); | |
| 72 | - void remove_rows(const int& rownum, const int& nrows); | |
| 73 | - GFitsTableCol* column(const std::string& colname); | |
| 74 | - GFitsTableCol* column(const int& colnum); | |
| 75 | - int nrows(void) const; | |
| 76 | - int ncols(void) const; | |
| 77 | - std::string print(void) const; | |
| 72 | + void append_column(GFitsTableCol& column); | |
| 73 | + void insert_column(int colnum, GFitsTableCol& column); | |
| 74 | + void append_rows(const int& nrows); | |
| 75 | + void insert_rows(const int& rownum, const int& nrows); | |
| 76 | + void remove_rows(const int& rownum, const int& nrows); | |
| 77 | + int nrows(void) const; | |
| 78 | + int ncols(void) const; | |
| 79 | + std::string print(void) const; | |
| 78 | 80 | |
| 79 | 81 | protected: |
| 80 | 82 | // Protected methods | ... | ... |
src/fits/GFitsTable.cpp
| ... | ... | @@ -50,12 +50,14 @@ |
| 50 | 50 | #include "GFitsTableCDoubleCol.hpp" |
| 51 | 51 | |
| 52 | 52 | /* __ Method name definitions ____________________________________________ */ |
| 53 | +#define G_ACCESS1 "GFitsTable::operator[](int&)" | |
| 54 | +#define G_ACCESS2 "GFitsTable::operator[](std::string&)" | |
| 53 | 55 | #define G_APPEND_COLUMN "GFitsTable::append_column(GFitsTableCol*)" |
| 54 | 56 | #define G_INSERT_COLUMN "GFitsTable::insert_column(int, GFitsTableCol*)" |
| 55 | 57 | #define G_INSERT_ROWS "GFitsTable::insert_rows(int&, int&)" |
| 56 | 58 | #define G_REMOVE_ROWS "GFitsTable::remove_rows(int&, int&)" |
| 57 | -#define G_COLUMN1 "GFitsTable::column(std::string&)" | |
| 58 | -#define G_COLUMN2 "GFitsTable::column(int&)" | |
| 59 | +//#define G_COLUMN1 "GFitsTable::column(std::string&)" | |
| 60 | +//#define G_COLUMN2 "GFitsTable::column(int&)" | |
| 59 | 61 | #define G_OPEN_DATA "GFitsTable::open_data(void*)" |
| 60 | 62 | #define G_SAVE_DATA "GFitsTable::save_data()" |
| 61 | 63 | #define G_GET_TFORM "GFitsTable::get_tform(int&)" |
| ... | ... | @@ -149,9 +151,9 @@ GFitsTable::~GFitsTable(void) |
| 149 | 151 | /***********************************************************************//** |
| 150 | 152 | * @brief Assignment operator |
| 151 | 153 | * |
| 152 | - * @param[in] table Table which will be assigned | |
| 154 | + * @param[in] table Table. | |
| 153 | 155 | ***************************************************************************/ |
| 154 | -GFitsTable& GFitsTable::operator= (const GFitsTable& table) | |
| 156 | +GFitsTable& GFitsTable::operator=(const GFitsTable& table) | |
| 155 | 157 | { |
| 156 | 158 | // Execute only if object is not identical |
| 157 | 159 | if (this != &table) { |
| ... | ... | @@ -175,6 +177,162 @@ GFitsTable& GFitsTable::operator= (const GFitsTable& table) |
| 175 | 177 | } |
| 176 | 178 | |
| 177 | 179 | |
| 180 | +/***********************************************************************//** | |
| 181 | + * @brief Returns reference to table column | |
| 182 | + * | |
| 183 | + * @param[in] colnum Column number [0,...,ncols()-1]. | |
| 184 | + * | |
| 185 | + * @exception GException::fits_no_data | |
| 186 | + * No data found in table. | |
| 187 | + * @exception GException::out_of_range | |
| 188 | + * Column number is out of range. | |
| 189 | + ***************************************************************************/ | |
| 190 | +GFitsTableCol& GFitsTable::operator[](const int& colnum) | |
| 191 | +{ | |
| 192 | + // If there is no data then throw an exception | |
| 193 | + if (m_columns == NULL) { | |
| 194 | + throw GException::fits_no_data(G_ACCESS1, "No columns in table."); | |
| 195 | + } | |
| 196 | + | |
| 197 | + // Compile option: raise exception if column number is out of range | |
| 198 | + #if defined(G_RANGE_CHECK) | |
| 199 | + if (colnum < 0 || colnum >= m_cols) | |
| 200 | + throw GException::out_of_range(G_ACCESS1, colnum, 0, m_cols-1); | |
| 201 | + #endif | |
| 202 | + | |
| 203 | + // Get column pointer | |
| 204 | + GFitsTableCol* ptr = m_columns[colnum]; | |
| 205 | + if (ptr == NULL) { | |
| 206 | + throw GException::fits_no_data(G_ACCESS1, "No data for this column."); | |
| 207 | + } | |
| 208 | + | |
| 209 | + // Return reference | |
| 210 | + return *ptr; | |
| 211 | +} | |
| 212 | + | |
| 213 | + | |
| 214 | +/***********************************************************************//** | |
| 215 | + * @brief Returns reference to table column (const version) | |
| 216 | + * | |
| 217 | + * @param[in] colnum Column number [0,...,ncols()-1]. | |
| 218 | + * | |
| 219 | + * @exception GException::fits_no_data | |
| 220 | + * No data found in table. | |
| 221 | + * @exception GException::out_of_range | |
| 222 | + * Column number is out of range. | |
| 223 | + ***************************************************************************/ | |
| 224 | +const GFitsTableCol& GFitsTable::operator[](const int& colnum) const | |
| 225 | +{ | |
| 226 | + // If there is no data then throw an exception | |
| 227 | + if (m_columns == NULL) { | |
| 228 | + throw GException::fits_no_data(G_ACCESS1, "No columns in table."); | |
| 229 | + } | |
| 230 | + | |
| 231 | + // Compile option: raise exception if column number is out of range | |
| 232 | + #if defined(G_RANGE_CHECK) | |
| 233 | + if (colnum < 0 || colnum >= m_cols) | |
| 234 | + throw GException::out_of_range(G_ACCESS1, colnum, 0, m_cols-1); | |
| 235 | + #endif | |
| 236 | + | |
| 237 | + // Get column pointer | |
| 238 | + const GFitsTableCol* ptr = m_columns[colnum]; | |
| 239 | + if (ptr == NULL) { | |
| 240 | + throw GException::fits_no_data(G_ACCESS1, "No data for this column."); | |
| 241 | + } | |
| 242 | + | |
| 243 | + // Return reference | |
| 244 | + return *ptr; | |
| 245 | +} | |
| 246 | + | |
| 247 | + | |
| 248 | +/***********************************************************************//** | |
| 249 | + * @brief Returns reference to table column | |
| 250 | + * | |
| 251 | + * @param[in] colname Column name. | |
| 252 | + * | |
| 253 | + * @exception GException::fits_no_data | |
| 254 | + * No data found in table. | |
| 255 | + * @exception GException::fits_column_not_found | |
| 256 | + * Column name not found. | |
| 257 | + ***************************************************************************/ | |
| 258 | +GFitsTableCol& GFitsTable::operator[](const std::string& colname) | |
| 259 | +{ | |
| 260 | + // If there is no data then throw an exception | |
| 261 | + if (m_columns == NULL) { | |
| 262 | + throw GException::fits_no_data(G_ACCESS2, "No columns in table."); | |
| 263 | + } | |
| 264 | + | |
| 265 | + // Initialise pointer | |
| 266 | + GFitsTableCol* ptr = NULL; | |
| 267 | + | |
| 268 | + // If there are columns then search for the specified name | |
| 269 | + if (m_columns != NULL) { | |
| 270 | + for (int i = 0; i < m_cols; ++i) { | |
| 271 | + if (m_columns[i]->name() == colname) { | |
| 272 | + ptr = m_columns[i]; | |
| 273 | + if (ptr == NULL) { | |
| 274 | + throw GException::fits_no_data(G_ACCESS2, | |
| 275 | + "No data for this column"); | |
| 276 | + } | |
| 277 | + break; | |
| 278 | + } | |
| 279 | + } | |
| 280 | + } | |
| 281 | + | |
| 282 | + // If column has not been found throw an exception | |
| 283 | + if (ptr == NULL) { | |
| 284 | + throw GException::fits_column_not_found(G_ACCESS2, colname); | |
| 285 | + } | |
| 286 | + | |
| 287 | + // Return reference | |
| 288 | + return *ptr; | |
| 289 | +} | |
| 290 | + | |
| 291 | + | |
| 292 | +/***********************************************************************//** | |
| 293 | + * @brief Returns reference to table column (const version) | |
| 294 | + * | |
| 295 | + * @param[in] colname Column name. | |
| 296 | + * | |
| 297 | + * @exception GException::fits_no_data | |
| 298 | + * No data found in table. | |
| 299 | + * @exception GException::fits_column_not_found | |
| 300 | + * Column name not found. | |
| 301 | + ***************************************************************************/ | |
| 302 | +const GFitsTableCol& GFitsTable::operator[](const std::string& colname) const | |
| 303 | +{ | |
| 304 | + // If there is no data then throw an exception | |
| 305 | + if (m_columns == NULL) { | |
| 306 | + throw GException::fits_no_data(G_ACCESS2, "No columns in table."); | |
| 307 | + } | |
| 308 | + | |
| 309 | + // Initialise pointer | |
| 310 | + const GFitsTableCol* ptr = NULL; | |
| 311 | + | |
| 312 | + // If there are columns then search for the specified name | |
| 313 | + if (m_columns != NULL) { | |
| 314 | + for (int i = 0; i < m_cols; ++i) { | |
| 315 | + if (m_columns[i]->name() == colname) { | |
| 316 | + ptr = m_columns[i]; | |
| 317 | + if (ptr == NULL) { | |
| 318 | + throw GException::fits_no_data(G_ACCESS2, | |
| 319 | + "No data for this column"); | |
| 320 | + } | |
| 321 | + break; | |
| 322 | + } | |
| 323 | + } | |
| 324 | + } | |
| 325 | + | |
| 326 | + // If column has not been found throw an exception | |
| 327 | + if (ptr == NULL) { | |
| 328 | + throw GException::fits_column_not_found(G_ACCESS2, colname); | |
| 329 | + } | |
| 330 | + | |
| 331 | + // Return reference | |
| 332 | + return *ptr; | |
| 333 | +} | |
| 334 | + | |
| 335 | + | |
| 178 | 336 | /*========================================================================== |
| 179 | 337 | = = |
| 180 | 338 | = Public methods = |
| ... | ... | @@ -399,6 +557,7 @@ void GFitsTable::remove_rows(const int& rownum, const int& nrows) |
| 399 | 557 | * @exception GException::fits_column_not_found |
| 400 | 558 | * Requested column has not been found in table. |
| 401 | 559 | ***************************************************************************/ |
| 560 | +/* | |
| 402 | 561 | GFitsTableCol* GFitsTable::column(const std::string& colname) |
| 403 | 562 | { |
| 404 | 563 | // If there is no data then throw an exception |
| ... | ... | @@ -428,7 +587,7 @@ GFitsTableCol* GFitsTable::column(const std::string& colname) |
| 428 | 587 | // Return column pointer |
| 429 | 588 | return ptr; |
| 430 | 589 | } |
| 431 | - | |
| 590 | +*/ | |
| 432 | 591 | |
| 433 | 592 | /***********************************************************************//** |
| 434 | 593 | * @brief Return pointer to column with number |
| ... | ... | @@ -441,6 +600,7 @@ GFitsTableCol* GFitsTable::column(const std::string& colname) |
| 441 | 600 | * @exception GException::out_of_range |
| 442 | 601 | * Requested column has not been found in table. |
| 443 | 602 | ***************************************************************************/ |
| 603 | +/* | |
| 444 | 604 | GFitsTableCol* GFitsTable::column(const int& colnum) |
| 445 | 605 | { |
| 446 | 606 | // If there is no data then throw an exception |
| ... | ... | @@ -459,7 +619,7 @@ GFitsTableCol* GFitsTable::column(const int& colnum) |
| 459 | 619 | // Return column pointer |
| 460 | 620 | return ptr; |
| 461 | 621 | } |
| 462 | - | |
| 622 | +*/ | |
| 463 | 623 | |
| 464 | 624 | /***********************************************************************//** |
| 465 | 625 | * @brief Return number of rows in table | ... | ... |