Commit 0e00f40fc6981bc83e27f8547f0882a4348f29a3
1 parent
a53748b6
Add GFilename::fullname() method that returns the full filename, including any extension.
Showing
5 changed files
with
80 additions
and
52 deletions
ChangeLog
| 1 | -2016-02-22 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 1 | +2016-02-12 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 2 | 2 | |
| 3 | 3 | * Version 1.1.0 released |
| 4 | 4 | ========================= |
| 5 | 5 | |
| 6 | - Add GCTAEventList::remove method | |
| 6 | + Add GFilename::fullname() method | |
| 7 | + Add GCTAEventList::remove() method | |
| 7 | 8 | Handle also additional columns in GCTAEventList::append method |
| 8 | - Correct GFitsTableCol::insert method for empty columns | |
| 9 | - Correct GCTAEdisp2D::compute_ebounds methods (#1662) | |
| 9 | + Correct GFitsTableCol::insert() method for empty columns | |
| 10 | + Correct GCTAEdisp2D::compute_ebounds_xxx() methods (#1662) | |
| 10 | 11 | Use GFilename in GFits to store filename (#1649) |
| 11 | 12 | Load CTA GTI extension from the HDU name provided by the DSS keyword (#1598) |
| 12 | 13 | ... | ... |
NEWS
| ... | ... | @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 1.1.0 |
| 2 | 2 | |
| 3 | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | |
| 5 | -11 February 2016 | |
| 5 | +12 February 2016 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | 1. Introduction |
| ... | ... | @@ -74,7 +74,8 @@ None |
| 74 | 74 | |
| 75 | 75 | 13. Support module |
| 76 | 76 | ------------------ |
| 77 | -None | |
| 77 | +Add GFilename::fullname() method that returns the full filename including | |
| 78 | +any FITS extension. | |
| 78 | 79 | |
| 79 | 80 | |
| 80 | 81 | 14. XML module | ... | ... |
include/GFilename.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFilename.hpp - Filename class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2015-2016 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -59,6 +59,7 @@ public: |
| 59 | 59 | bool empty(void) const; |
| 60 | 60 | int size(void) const; |
| 61 | 61 | int length(void) const; |
| 62 | + const std::string& fullname(void) const; | |
| 62 | 63 | const std::string& filename(void) const; |
| 63 | 64 | std::string extname(const std::string& defaultname = "") const; |
| 64 | 65 | const std::string& expression(void) const; |
| ... | ... | @@ -78,10 +79,11 @@ protected: |
| 78 | 79 | void set_filename(const std::string& filename); |
| 79 | 80 | |
| 80 | 81 | // Protected members |
| 81 | - std::string m_filename; //!< Filename (with stripped extension info) | |
| 82 | - std::string m_extname; //!< Extension name ("": not set) | |
| 83 | - int m_extno; //!< Extension number (-1: not set) | |
| 84 | - int m_extver; //!< Extension version (0: not set) | |
| 82 | + std::string m_fullname; //!< Full file name | |
| 83 | + std::string m_filename; //!< File name (with stripped extension info) | |
| 84 | + std::string m_extname; //!< Extension name ("": not set) | |
| 85 | + int m_extno; //!< Extension number (-1: not set) | |
| 86 | + int m_extver; //!< Extension version (0: not set) | |
| 85 | 87 | std::string m_expression; //!< Selection expression ("": not set) |
| 86 | 88 | }; |
| 87 | 89 | |
| ... | ... | @@ -137,9 +139,25 @@ int GFilename::length(void) const |
| 137 | 139 | |
| 138 | 140 | |
| 139 | 141 | /***********************************************************************//** |
| 140 | - * @brief Return file name | |
| 142 | + * @brief Return full filename | |
| 141 | 143 | * |
| 142 | - * @return String containing file name. | |
| 144 | + * @return String containing filename with extension. | |
| 145 | + * | |
| 146 | + * Returns the full filename, including any extension. | |
| 147 | + ***************************************************************************/ | |
| 148 | +inline | |
| 149 | +const std::string& GFilename::fullname(void) const | |
| 150 | +{ | |
| 151 | + return (m_fullname); | |
| 152 | +} | |
| 153 | + | |
| 154 | + | |
| 155 | +/***********************************************************************//** | |
| 156 | + * @brief Return filename | |
| 157 | + * | |
| 158 | + * @return String containing filename without extension. | |
| 159 | + * | |
| 160 | + * Returns the file name without any extension. | |
| 143 | 161 | ***************************************************************************/ |
| 144 | 162 | inline |
| 145 | 163 | const std::string& GFilename::filename(void) const | ... | ... |
pyext/GFilename.i
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GFilename.i - Filename class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2015-2016 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -51,6 +51,7 @@ public: |
| 51 | 51 | bool empty(void) const; |
| 52 | 52 | int size(void) const; |
| 53 | 53 | int length(void) const; |
| 54 | + const std::string& fullname(void) const; | |
| 54 | 55 | const std::string& filename(void) const; |
| 55 | 56 | std::string extname(const std::string& defaultname = "") const; |
| 56 | 57 | const std::string& expression(void) const; | ... | ... |
src/support/GFilename.cpp
| ... | ... | @@ -350,6 +350,7 @@ std::string GFilename::print(const GChatter& chatter) const |
| 350 | 350 | void GFilename::init_members(void) |
| 351 | 351 | { |
| 352 | 352 | // Initialise members |
| 353 | + m_fullname.clear(); | |
| 353 | 354 | m_filename.clear(); |
| 354 | 355 | m_extname.clear(); |
| 355 | 356 | m_extno = -1; |
| ... | ... | @@ -369,10 +370,11 @@ void GFilename::init_members(void) |
| 369 | 370 | void GFilename::copy_members(const GFilename& filename) |
| 370 | 371 | { |
| 371 | 372 | // Copy members |
| 372 | - m_filename = filename.m_filename; | |
| 373 | - m_extname = filename.m_extname; | |
| 374 | - m_extno = filename.m_extno; | |
| 375 | - m_extver = filename.m_extver; | |
| 373 | + m_fullname = filename.m_fullname; | |
| 374 | + m_filename = filename.m_filename; | |
| 375 | + m_extname = filename.m_extname; | |
| 376 | + m_extno = filename.m_extno; | |
| 377 | + m_extver = filename.m_extver; | |
| 376 | 378 | m_expression = filename.m_expression; |
| 377 | 379 | |
| 378 | 380 | // Return |
| ... | ... | @@ -411,45 +413,48 @@ void GFilename::set_filename(const std::string& filename) |
| 411 | 413 | // Clear file name |
| 412 | 414 | clear(); |
| 413 | 415 | |
| 414 | - // Strip any whitespace | |
| 415 | - std::string fname = gammalib::strip_whitespace(filename); | |
| 416 | + // Strip any whitespace and store the full name | |
| 417 | + m_fullname = gammalib::strip_whitespace(filename); | |
| 416 | 418 | |
| 417 | 419 | // Continue only if filename is not empty |
| 418 | - if (!fname.empty()) { | |
| 420 | + if (!m_fullname.empty()) { | |
| 419 | 421 | |
| 420 | 422 | // Check for [ symbol in filename |
| 421 | - size_t start = fname.find_first_of("["); | |
| 423 | + size_t start = m_fullname.find_first_of("["); | |
| 422 | 424 | |
| 423 | 425 | // If we have an extension then separate filename into filename |
| 424 | 426 | // part and extension part and fill the information of th object |
| 425 | 427 | if (start != std::string::npos) { |
| 426 | 428 | |
| 427 | 429 | // Check for ] symbol in filename |
| 428 | - size_t stop = fname.find_first_of("]", start); | |
| 430 | + size_t stop = m_fullname.find_first_of("]", start); | |
| 429 | 431 | |
| 430 | 432 | // If there is no ] symbol then throw an exception |
| 431 | 433 | if (stop == std::string::npos) { |
| 432 | - std::string msg = "Missing ] symbol in filename \""+ | |
| 433 | - fname+"\" extension. Please correct the " | |
| 434 | - "filename."; | |
| 434 | + std::string msg = "Missing ] symbol in file name \""+ | |
| 435 | + m_fullname+"\" extension. Please correct " | |
| 436 | + "the file name."; | |
| 435 | 437 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 436 | 438 | } |
| 437 | 439 | |
| 438 | 440 | // If ] is not the last character then check if an opening bracket is next |
| 439 | - if (stop < fname.length()-1) { | |
| 441 | + if (stop < m_fullname.length()-1) { | |
| 440 | 442 | |
| 441 | - std::string character = gammalib::strip_whitespace(fname.substr(stop+1,1)); | |
| 443 | + // Get character | |
| 444 | + std::string character = gammalib::strip_whitespace(m_fullname.substr(stop+1,1)); | |
| 442 | 445 | |
| 443 | 446 | // If no bracket is coming, throw an exception |
| 444 | 447 | if (character != "[") { |
| 445 | - std::string msg = "Non-bracket character \""+character+"\" beyond ] symbol in filename \""+ | |
| 446 | - fname+"\" expression. Please correct the filename."; | |
| 448 | + std::string msg = "Non-bracket character \""+character+ | |
| 449 | + "\" beyond ] symbol in file name \""+ | |
| 450 | + m_fullname+"\" expression. Please " | |
| 451 | + "correct the file name."; | |
| 447 | 452 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 448 | 453 | } |
| 449 | 454 | } |
| 450 | 455 | |
| 451 | 456 | // Extract extension name |
| 452 | - std::string extname = gammalib::strip_whitespace(fname.substr(start+1, stop-start-1)); | |
| 457 | + std::string extname = gammalib::strip_whitespace(m_fullname.substr(start+1, stop-start-1)); | |
| 453 | 458 | |
| 454 | 459 | // Check if there is a , symbol that separates extension name |
| 455 | 460 | // and extension version |
| ... | ... | @@ -464,8 +469,8 @@ void GFilename::set_filename(const std::string& filename) |
| 464 | 469 | // If string is empty then throw an exception |
| 465 | 470 | if (extver.empty()) { |
| 466 | 471 | std::string msg = "No extension version found after , " |
| 467 | - "symbol in filename \""+fname+ | |
| 468 | - "\". Please correct the filename."; | |
| 472 | + "symbol in file name \""+m_fullname+ | |
| 473 | + "\". Please correct the file name."; | |
| 469 | 474 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 470 | 475 | } |
| 471 | 476 | |
| ... | ... | @@ -476,8 +481,9 @@ void GFilename::set_filename(const std::string& filename) |
| 476 | 481 | // positive |
| 477 | 482 | if (m_extver <= 0) { |
| 478 | 483 | std::string msg = "Non-positive extension version " |
| 479 | - "encountered in filename \""+fname+ | |
| 480 | - "\". Please correct the filename."; | |
| 484 | + "encountered in file name \""+ | |
| 485 | + m_fullname+ "\". Please correct the " | |
| 486 | + "file name."; | |
| 481 | 487 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 482 | 488 | } |
| 483 | 489 | |
| ... | ... | @@ -489,8 +495,8 @@ void GFilename::set_filename(const std::string& filename) |
| 489 | 495 | // If we have an empty extension name then throw an exception |
| 490 | 496 | if (extname.empty()) { |
| 491 | 497 | std::string msg = "An empty extension has been specified in " |
| 492 | - "filename \""+fname+"\". Please correct the" | |
| 493 | - " filename."; | |
| 498 | + "file name \""+m_fullname+"\". Please " | |
| 499 | + "correct the file name."; | |
| 494 | 500 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 495 | 501 | } |
| 496 | 502 | |
| ... | ... | @@ -505,8 +511,8 @@ void GFilename::set_filename(const std::string& filename) |
| 505 | 511 | // positive |
| 506 | 512 | if (m_extno < 0) { |
| 507 | 513 | std::string msg = "Negative extension number encountered " |
| 508 | - "in filename \""+fname+"\". Please " | |
| 509 | - "correct the filename."; | |
| 514 | + "in file name \""+m_fullname+"\". " | |
| 515 | + "Please correct the file name."; | |
| 510 | 516 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 511 | 517 | } |
| 512 | 518 | |
| ... | ... | @@ -521,48 +527,49 @@ void GFilename::set_filename(const std::string& filename) |
| 521 | 527 | // Throw an exception if extension name is empty |
| 522 | 528 | if (m_extname.empty()) { |
| 523 | 529 | std::string msg = "Empty extension name encountered " |
| 524 | - "in filename \""+fname+"\". Please " | |
| 525 | - "correct the filename."; | |
| 530 | + "in file name \""+m_fullname+"\". " | |
| 531 | + "Please correct the file name."; | |
| 526 | 532 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 527 | 533 | } |
| 528 | 534 | |
| 529 | 535 | } // endelse: extension name provided |
| 530 | 536 | |
| 531 | 537 | // Store the file name |
| 532 | - m_filename = gammalib::strip_whitespace(fname.substr(0,start)); | |
| 538 | + m_filename = gammalib::strip_whitespace(m_fullname.substr(0,start)); | |
| 533 | 539 | |
| 534 | 540 | // Check if there is an expression behind the extension name |
| 535 | - size_t expr_start = fname.find_first_of("[", stop+1); | |
| 541 | + size_t expr_start = m_fullname.find_first_of("[", stop+1); | |
| 536 | 542 | |
| 537 | 543 | if (expr_start != std::string::npos) { |
| 538 | 544 | |
| 539 | 545 | // Check for ] symbol in expression |
| 540 | - size_t expr_stop = fname.find_first_of("]", expr_start); | |
| 546 | + size_t expr_stop = m_fullname.find_first_of("]", expr_start); | |
| 541 | 547 | |
| 542 | 548 | // If there is no ] symbol then throw an exception |
| 543 | 549 | if (expr_stop == std::string::npos) { |
| 544 | - std::string msg = "Missing ] symbol in filename \""+ | |
| 545 | - fname+"\" expression. Please correct the " | |
| 546 | - "filename."; | |
| 550 | + std::string msg = "Missing ] symbol in file name \""+ | |
| 551 | + m_fullname+"\" expression. Please " | |
| 552 | + "correct the file name."; | |
| 547 | 553 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 548 | 554 | } |
| 549 | 555 | |
| 550 | 556 | // If ] is not the last character then throw an exception |
| 551 | - if (expr_stop < fname.length()-1) { | |
| 552 | - std::string msg = "Characters beyond ] symbol in filename \""+ | |
| 553 | - fname+"\" expression. Please correct the filename."; | |
| 557 | + if (expr_stop < m_fullname.length()-1) { | |
| 558 | + std::string msg = "Characters beyond ] symbol in file " | |
| 559 | + "name \""+m_fullname+"\" expression. " | |
| 560 | + "Please correct the file name."; | |
| 554 | 561 | throw GException::invalid_argument(G_SET_FILENAME, msg); |
| 555 | 562 | } |
| 556 | 563 | |
| 557 | 564 | // Store expression |
| 558 | - m_expression = gammalib::strip_whitespace(fname.substr(expr_start+1, expr_stop - expr_start-1)); | |
| 565 | + m_expression = gammalib::strip_whitespace(m_fullname.substr(expr_start+1, expr_stop - expr_start-1)); | |
| 559 | 566 | } |
| 560 | 567 | |
| 561 | 568 | } // endif: had extension |
| 562 | 569 | |
| 563 | 570 | // ... otherwise simply set the filename |
| 564 | 571 | else { |
| 565 | - m_filename = fname; | |
| 572 | + m_filename = m_fullname; | |
| 566 | 573 | } |
| 567 | 574 | |
| 568 | 575 | } // endif: filename was not empty | ... | ... |