From 93924af160ea303c94a2576b0e57a04e94c9228c Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Thu, 9 Oct 2008 09:38:42 +0200 Subject: using namespace instead of a useless class --- src/FbTk/App.cc | 2 -- src/FbTk/Image.cc | 45 +++++++++++++-------------------------------- src/FbTk/Image.hh | 30 ++++++++---------------------- 3 files changed, 21 insertions(+), 56 deletions(-) diff --git a/src/FbTk/App.cc b/src/FbTk/App.cc index 25c338f..39cd36e 100644 --- a/src/FbTk/App.cc +++ b/src/FbTk/App.cc @@ -49,14 +49,12 @@ App::App(const char *displayname):m_done(false), m_display(0) { throw std::string("Couldn't connect to XServer"); FbStringUtil::init(); - Image::init(); } App::~App() { if (m_display != 0) { Font::shutdown(); - Image::shutdown(); XCloseDisplay(m_display); m_display = 0; diff --git a/src/FbTk/Image.cc b/src/FbTk/Image.cc index 020f9c6..0c7b5fc 100644 --- a/src/FbTk/Image.cc +++ b/src/FbTk/Image.cc @@ -42,50 +42,31 @@ using std::string; using std::list; using std::set; -namespace FbTk { -Image::ImageMap Image::s_image_map; -Image::StringList Image::s_search_paths; +namespace { +typedef std::map ImageMap; +typedef std::list StringList; -void Image::init() { +ImageMap s_image_map; +StringList s_search_paths; -// create imagehandlers for their extensions -#ifdef HAVE_XPM - new ImageXPM(); -#endif // HAVE_XPM #ifdef HAVE_IMLIB2 - new ImageImlib2(); -#endif // HAVE_IMLIB2 -} - -void Image::shutdown() { - - set handlers; +FbTk::ImageImlib2 imlib2_loader; +#endif +#ifdef HAVE_XPM +FbTk::ImageXPM xpm_loader; +#endif - // one imagehandler could be registered - // for more than one type - ImageMap::iterator it = s_image_map.begin(); - ImageMap::iterator it_end = s_image_map.end(); - for (; it != it_end; it++) { - if (it->second) - handlers.insert(it->second); - } - // free the unique handlers - set::iterator handler_it = handlers.begin(); - set::iterator handler_it_end = handlers.end(); - for(; handler_it != handler_it_end; handler_it++) { - delete (*handler_it); - } +}; // end of anonymous namespace - s_image_map.clear(); -} +namespace FbTk { PixmapWithMask *Image::load(const string &filename, int screen_num) { - if (filename == "") + if (filename.empty()) return false; // determine file ending diff --git a/src/FbTk/Image.hh b/src/FbTk/Image.hh index acb5879..3c731ad 100644 --- a/src/FbTk/Image.hh +++ b/src/FbTk/Image.hh @@ -32,37 +32,24 @@ class ImageBase; class PixmapWithMask; /// loads images -class Image { -public: - - /// called at FbTk::App creation time, init some internal stuff - static void init(); - - /// called at FbTk:App destruction time, frees stuff allocated by init() - static void shutdown(); +namespace Image { /// @return an instance of PixmapWithMask on success, 0 on failure - static PixmapWithMask *load(const std::string &filename, int screen_num); + PixmapWithMask *load(const std::string &filename, int screen_num); /// for register file type and imagebase /// @return false on failure - static bool registerType(const std::string &type, ImageBase &base); + bool registerType(const std::string &type, ImageBase &base); /// removes a imagebase class from register /// @return false on failure - static void remove(ImageBase &base); + void remove(ImageBase &base); /// adds a path to search images from - static void addSearchPath(const std::string &search_path); + void addSearchPath(const std::string &search_path); /// removes a path to search images from - static void removeSearchPath(const std::string &search_path); + void removeSearchPath(const std::string &search_path); /// adds a path to search images from - static void removeAllSearchPaths(); + void removeAllSearchPaths(); /// locates an image in the search path - static std::string locateFile(const std::string &filename); -private: - typedef std::map ImageMap; - typedef std::list StringList; - - static ImageMap s_image_map; - static StringList s_search_paths; + std::string locateFile(const std::string &filename); }; /// common interface for all image classes @@ -76,4 +63,3 @@ public: #endif // IMAGE_HH - -- cgit v0.11.2