X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Fresource.cc;h=7a60d0e304e6e4c444dbeb5d920c3a5215c4e478;hp=95b4c698501a05686a02d1789a3f428298939cb1;hb=574af38ed616d1adfa5e6ce35f67cda1f707f89d;hpb=6c9943707d4f33035830eba0587a61a34eaecbc2 diff --git a/src/moof/resource.cc b/src/moof/resource.cc index 95b4c69..7a60d0e 100644 --- a/src/moof/resource.cc +++ b/src/moof/resource.cc @@ -1,15 +1,15 @@ -/*] Copyright (c) 2009-2010, Charles McGarvey [************************** +/*] Copyright (c) 2009-2011, Charles McGarvey [***************************** **] All rights reserved. * -* vi:ts=4 sw=4 tw=75 -* * Distributable under the terms and conditions of the 2-clause BSD license; * see the file COPYING for a complete text of the license. * -**************************************************************************/ +*****************************************************************************/ +#if HAVE_CONFIG_H #include "config.h" +#endif #include @@ -25,14 +25,13 @@ #include "hash.hh" #include "resource.hh" - #ifndef BUF_SIZE -#define BUF_SIZE 4096 +#define BUF_SIZE 8192 #endif namespace moof { - + /*] Filesystem searching *************************************************************************/ @@ -44,7 +43,6 @@ void resource::set_search_paths(const std::string& paths) boost::split(search_paths_, paths, boost::is_any_of(":")); } - std::string resource::find_file(const std::string& name) { std::string ext = stlplus::extension_part(name); @@ -76,8 +74,8 @@ std::string resource::find_file(const std::string& name) return std::string(); } -std::string resource::find_file(const std::string& name, - const std::string& ext) +std::string +resource::find_file(const std::string& name, const std::string& ext) { std::string actual_ext = stlplus::extension_part(name); if (actual_ext != ext) @@ -105,9 +103,7 @@ static struct rsrc_list { hash::iterator it; for (it = table.begin(); it != table.end(); ++it) - { log_warning("leaked resource:", (*it).first); - } } #endif } rsrc_list; @@ -131,7 +127,7 @@ static struct watch_list int add(resource_ptr rsrc) { int wd = inotify_add_watch(fd, rsrc->path().c_str(), - IN_DELETE_SELF | IN_MODIFY); + IN_DELETE_SELF | IN_MODIFY); table[wd] = rsrc; return wd; } @@ -142,22 +138,19 @@ static struct watch_list } watch_list; #endif - resource_ptr resource::load(const std::string& name) { std::string ext = stlplus::extension_part(name); return load_with_path(find_file(name, ext), ext); } -resource_ptr resource::load(const std::string& name, - const std::string& ext) +resource_ptr resource::load(const std::string& name, const std::string& ext) { return load_with_path(find_file(name, ext), ext); } - -resource_ptr resource::load_with_path(const std::string& path, - const std::string& ext) +resource_ptr +resource::load_with_path(const std::string& path, const std::string& ext) { if (path.empty()) return resource_ptr(); @@ -189,7 +182,6 @@ resource_ptr resource::load_with_path(const std::string& path, return resource_ptr(); } - /*] Hotloading *************************************************************************/ @@ -237,7 +229,6 @@ int resource::reload_as_needed() } } #endif - return count; } @@ -260,32 +251,30 @@ resource::~resource() #endif } - /*] Resource registration *************************************************************************/ bool resource::call_registry(const std::string& ext, - loader_ptr& loader, - registry_action action) + loader_ptr& loader, registry_action action) { static std::map table; switch (action) { - case set: - { - if (loader) table[ext] = loader; - else table.erase(ext); - break; - } + case lookup: + { + std::map::iterator it; + it = table.find(ext); + if (it != table.end()) loader = (*it).second; + break; + } - case lookup: - { - std::map::iterator it; - it = table.find(ext); - if (it != table.end()) loader = (*it).second; - break; - } + case set: + if (loader) + table[ext] = loader; + else + table.erase(ext); + break; } return loader;