-/*] 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 <queue>
+#include <boost/algorithm/string.hpp>
+#include <boost/weak_ptr.hpp>
+
+#include <stlplus/portability/file_system.hpp>
+
#if ENABLE_HOTLOADING
#include <sys/inotify.h>
#include <sys/ioctl.h>
#endif
-#include <boost/algorithm/string.hpp>
-#include <boost/weak_ptr.hpp>
-#include <stlplus/portability/file_system.hpp>
-
#include "hash.hh"
+#include "log.hh"
#include "resource.hh"
-
#ifndef BUF_SIZE
-#define BUF_SIZE 4096
+#define BUF_SIZE 8192
#endif
namespace moof {
-
+
/*] Filesystem searching
*************************************************************************/
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);
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)
{
hash<std::string,resource_weakptr,hash_function>::iterator it;
for (it = table.begin(); it != table.end(); ++it)
- {
log_warning("leaked resource:", (*it).first);
- }
}
#endif
} rsrc_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;
}
} 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();
return resource_ptr();
}
-
/*] Hotloading
*************************************************************************/
}
}
#endif
-
return count;
}
#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<std::string,loader_ptr> table;
switch (action)
{
- case set:
- {
- if (loader) table[ext] = loader;
- else table.erase(ext);
- break;
- }
+ case lookup:
+ {
+ std::map<std::string,loader_ptr>::iterator it;
+ it = table.find(ext);
+ if (it != table.end()) loader = (*it).second;
+ break;
+ }
- case lookup:
- {
- std::map<std::string,loader_ptr>::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;