using namespace instead of a useless class
Mathias Gumz akira at fluxbox dot org
3 files changed,
21 insertions(+),
56 deletions(-)
M
src/FbTk/App.cc
→
src/FbTk/App.cc
@@ -49,14 +49,12 @@ if (!m_display)
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;
M
src/FbTk/Image.cc
→
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<std::string, FbTk::ImageBase *> ImageMap; +typedef std::list<std::string> StringList; -void Image::init() { +ImageMap s_image_map; +StringList s_search_paths; -// create imagehandlers for their extensions +#ifdef HAVE_IMLIB2 +FbTk::ImageImlib2 imlib2_loader; +#endif #ifdef HAVE_XPM - new ImageXPM(); -#endif // HAVE_XPM -#ifdef HAVE_IMLIB2 - new ImageImlib2(); -#endif // HAVE_IMLIB2 -} +FbTk::ImageXPM xpm_loader; +#endif -void Image::shutdown() { - set<ImageBase*> handlers; +}; // end of anonymous namespace - // 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<ImageBase*>::iterator handler_it = handlers.begin(); - set<ImageBase*>::iterator handler_it_end = handlers.end(); - for(; handler_it != handler_it_end; handler_it++) { - delete (*handler_it); - } - - 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
M
src/FbTk/Image.hh
→
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<std::string, ImageBase *> ImageMap; - typedef std::list<std::string> 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 @@ } // end namespace FbTk
#endif // IMAGE_HH -