From b7aa70706ddc9fe4fbc447734996f977b6889fc8 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 11 Dec 2015 14:08:28 +0100 Subject: [PATCH] Remove GFilename::default_extname() and enhance GFilename::extname() method. --- include/GFilename.hpp | 15 +-------------- pyext/GFilename.i | 3 +-- src/support/GFilename.cpp | 22 ++++++++++++++-------- test/test_GSupport.cpp | 6 ++---- 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/include/GFilename.hpp b/include/GFilename.hpp index d54badd..f8a96e0 100644 --- a/include/GFilename.hpp +++ b/include/GFilename.hpp @@ -60,13 +60,12 @@ public: int size(void) const; int length(void) const; const std::string& filename(void) const; - const std::string& extname(void) const; + std::string extname(const std::string& defaultname = "") const; const int& extno(void) const; const int& extver(void) const; bool has_extname(void) const; bool has_extno(void) const; bool has_extver(void) const; - void default_extname(const std::string& extname); std::string print(const GChatter& chatter = NORMAL) const; protected: @@ -147,18 +146,6 @@ const std::string& GFilename::filename(void) const /***********************************************************************//** - * @brief Return extension name - * - * @return String containing extension name. - ***************************************************************************/ -inline -const std::string& GFilename::extname(void) const -{ - return (m_extname); -} - - -/***********************************************************************//** * @brief Return extension number * * @return Extension number (-1 if not set). diff --git a/pyext/GFilename.i b/pyext/GFilename.i index 6d2a478..154ad51 100644 --- a/pyext/GFilename.i +++ b/pyext/GFilename.i @@ -52,13 +52,12 @@ public: int size(void) const; int length(void) const; const std::string& filename(void) const; - const std::string& extname(void) const; + std::string extname(const std::string& defaultname = "") const; const int& extno(void) const; const int& extver(void) const; bool has_extname(void) const; bool has_extno(void) const; bool has_extver(void) const; - void default_extname(const std::string& extname); }; diff --git a/src/support/GFilename.cpp b/src/support/GFilename.cpp index 69fc3bd..8456f75 100644 --- a/src/support/GFilename.cpp +++ b/src/support/GFilename.cpp @@ -200,21 +200,27 @@ GFilename* GFilename::clone(void) const /***********************************************************************//** - * @brief Set default extension name + * @brief Return extension name * - * @param[in] extname Extension name. + * @param[in] defaultname Default extension name (default: ""). + * @return String containing extension name. * - * If the object has no extension name then set the extension name. + * Returns the extension name. If no extension name is given the name + * provided by the @p defaultname argument will be used. By default, the + * @p defaultname parameter is an empty string. ***************************************************************************/ -void GFilename::default_extname(const std::string& extname) +std::string GFilename::extname(const std::string& defaultname) const { - // Set extension name if it has not yet been set + // Set the extension name + std::string extname = m_extname; + + // If no extension name is set, the use the default extension name if (!has_extname()) { - m_extname = extname; + extname = defaultname; } - // Return - return; + // Return extension name + return (extname); } diff --git a/test/test_GSupport.cpp b/test/test_GSupport.cpp index 8030e51..a8de738 100644 --- a/test/test_GSupport.cpp +++ b/test/test_GSupport.cpp @@ -760,13 +760,11 @@ void TestGSupport::test_filename(void) // Test default extension name filename = "myfile.fits"; - filename.default_extname("EVENTS"); - test_assert(filename.extname() == "EVENTS", + test_assert(filename.extname("EVENTS") == "EVENTS", "Expected \"EVENTS\" extension name, " "found \""+filename.extname()+"\""); filename = "myfile.fits[LUCKY]"; - filename.default_extname("EVENTS"); - test_assert(filename.extname() == "LUCKY", + test_assert(filename.extname("EVENTS") == "LUCKY", "Expected \"LUCKY\" extension name, " "found \""+filename.extname()+"\""); -- libgit2 0.21.4