Commit b7aa70706ddc9fe4fbc447734996f977b6889fc8
1 parent
537d0e9d
Remove GFilename::default_extname() and enhance GFilename::extname() method.
The GFilename::default_extname() has been removed and remplaced by an enhanced GFilename::extname() method that either returns the extension name set in the filename, or if not set, the string that has been provided as argument.
Showing
4 changed files
with
18 additions
and
28 deletions
include/GFilename.hpp
| ... | ... | @@ -60,13 +60,12 @@ public: |
| 60 | 60 | int size(void) const; |
| 61 | 61 | int length(void) const; |
| 62 | 62 | const std::string& filename(void) const; |
| 63 | - const std::string& extname(void) const; | |
| 63 | + std::string extname(const std::string& defaultname = "") const; | |
| 64 | 64 | const int& extno(void) const; |
| 65 | 65 | const int& extver(void) const; |
| 66 | 66 | bool has_extname(void) const; |
| 67 | 67 | bool has_extno(void) const; |
| 68 | 68 | bool has_extver(void) const; |
| 69 | - void default_extname(const std::string& extname); | |
| 70 | 69 | std::string print(const GChatter& chatter = NORMAL) const; |
| 71 | 70 | |
| 72 | 71 | protected: |
| ... | ... | @@ -147,18 +146,6 @@ const std::string& GFilename::filename(void) const |
| 147 | 146 | |
| 148 | 147 | |
| 149 | 148 | /***********************************************************************//** |
| 150 | - * @brief Return extension name | |
| 151 | - * | |
| 152 | - * @return String containing extension name. | |
| 153 | - ***************************************************************************/ | |
| 154 | -inline | |
| 155 | -const std::string& GFilename::extname(void) const | |
| 156 | -{ | |
| 157 | - return (m_extname); | |
| 158 | -} | |
| 159 | - | |
| 160 | - | |
| 161 | -/***********************************************************************//** | |
| 162 | 149 | * @brief Return extension number |
| 163 | 150 | * |
| 164 | 151 | * @return Extension number (-1 if not set). | ... | ... |
pyext/GFilename.i
| ... | ... | @@ -52,13 +52,12 @@ public: |
| 52 | 52 | int size(void) const; |
| 53 | 53 | int length(void) const; |
| 54 | 54 | const std::string& filename(void) const; |
| 55 | - const std::string& extname(void) const; | |
| 55 | + std::string extname(const std::string& defaultname = "") const; | |
| 56 | 56 | const int& extno(void) const; |
| 57 | 57 | const int& extver(void) const; |
| 58 | 58 | bool has_extname(void) const; |
| 59 | 59 | bool has_extno(void) const; |
| 60 | 60 | bool has_extver(void) const; |
| 61 | - void default_extname(const std::string& extname); | |
| 62 | 61 | }; |
| 63 | 62 | |
| 64 | 63 | ... | ... |
src/support/GFilename.cpp
| ... | ... | @@ -200,21 +200,27 @@ GFilename* GFilename::clone(void) const |
| 200 | 200 | |
| 201 | 201 | |
| 202 | 202 | /***********************************************************************//** |
| 203 | - * @brief Set default extension name | |
| 203 | + * @brief Return extension name | |
| 204 | 204 | * |
| 205 | - * @param[in] extname Extension name. | |
| 205 | + * @param[in] defaultname Default extension name (default: ""). | |
| 206 | + * @return String containing extension name. | |
| 206 | 207 | * |
| 207 | - * If the object has no extension name then set the extension name. | |
| 208 | + * Returns the extension name. If no extension name is given the name | |
| 209 | + * provided by the @p defaultname argument will be used. By default, the | |
| 210 | + * @p defaultname parameter is an empty string. | |
| 208 | 211 | ***************************************************************************/ |
| 209 | -void GFilename::default_extname(const std::string& extname) | |
| 212 | +std::string GFilename::extname(const std::string& defaultname) const | |
| 210 | 213 | { |
| 211 | - // Set extension name if it has not yet been set | |
| 214 | + // Set the extension name | |
| 215 | + std::string extname = m_extname; | |
| 216 | + | |
| 217 | + // If no extension name is set, the use the default extension name | |
| 212 | 218 | if (!has_extname()) { |
| 213 | - m_extname = extname; | |
| 219 | + extname = defaultname; | |
| 214 | 220 | } |
| 215 | 221 | |
| 216 | - // Return | |
| 217 | - return; | |
| 222 | + // Return extension name | |
| 223 | + return (extname); | |
| 218 | 224 | } |
| 219 | 225 | |
| 220 | 226 | ... | ... |
test/test_GSupport.cpp
| ... | ... | @@ -760,13 +760,11 @@ void TestGSupport::test_filename(void) |
| 760 | 760 | |
| 761 | 761 | // Test default extension name |
| 762 | 762 | filename = "myfile.fits"; |
| 763 | - filename.default_extname("EVENTS"); | |
| 764 | - test_assert(filename.extname() == "EVENTS", | |
| 763 | + test_assert(filename.extname("EVENTS") == "EVENTS", | |
| 765 | 764 | "Expected \"EVENTS\" extension name, " |
| 766 | 765 | "found \""+filename.extname()+"\""); |
| 767 | 766 | filename = "myfile.fits[LUCKY]"; |
| 768 | - filename.default_extname("EVENTS"); | |
| 769 | - test_assert(filename.extname() == "LUCKY", | |
| 767 | + test_assert(filename.extname("EVENTS") == "LUCKY", | |
| 770 | 768 | "Expected \"LUCKY\" extension name, " |
| 771 | 769 | "found \""+filename.extname()+"\""); |
| 772 | 770 | ... | ... |