|
From: <br...@us...> - 2009-08-07 07:58:11
|
Revision: 3987
http://openvrml.svn.sourceforge.net/openvrml/?rev=3987&view=rev
Author: braden
Date: 2009-08-07 07:58:00 +0000 (Fri, 07 Aug 2009)
Log Message:
-----------
Modified openvrml::local::dl interface to use boost::filesystem::path and std::string.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/Makefile.am
trunk/src/libopenvrml/openvrml/local/conf.cpp
trunk/src/libopenvrml/openvrml/local/conf.h
trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.cpp
trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.h
trunk/src/libopenvrml/openvrml/script.cpp
trunk/src/local/libopenvrml-dl/openvrml/local/dl.cpp
trunk/src/local/libopenvrml-dl/openvrml/local/dl.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/ChangeLog 2009-08-07 07:58:00 UTC (rev 3987)
@@ -1,3 +1,57 @@
+2009-08-07 Braden McDaniel <br...@en...>
+
+ Modified openvrml::local::dl interface to use
+ boost::filesystem::path and std::string.
+
+ * src/Makefile.am
+ (local_libopenvrml_dl_la_LIBADD): Added libboost_filesystem
+ dependency.
+ * src/libopenvrml/openvrml/local/conf.cpp
+ (openvrml::local::conf::datadir()): Return a
+ boost::filesystem::path.
+ (openvrml::local::conf::node_path()): Return a std::vector of
+ boost::filesystem::path to represent the node module search path.
+ (openvrml::local::conf::script_path()): Return a std::vector of
+ boost::filesystem::path to represent the script module search
+ path.
+ * src/libopenvrml/openvrml/local/conf.h
+ (openvrml::local::conf::datadir()): Return a
+ boost::filesystem::path.
+ (openvrml::local::conf::node_path()): Return a std::vector of
+ boost::filesystem::path to represent the node module search path.
+ (openvrml::local::conf::script_path()): Return a std::vector of
+ boost::filesystem::path to represent the script module search
+ path.
+ * src/libopenvrml/openvrml/local/node_metatype_registry_impl.cpp
+ (openvrml_open_node_module(const std::string &, void *)): Changed
+ signature to use std::string.
+ (openvrml::local::node_metatype_registry_impl::node_metatype_registry_impl(openvrml::browser&)):
+ Use a std::vector of boost::filesystem::path to represent the node
+ module search path.
+ * src/libopenvrml/openvrml/local/node_metatype_registry_impl.h
+ (node_metatype_registry_impl): Use std::string in the signature of
+ openvrml_open_node_module; changed type of sym to std::string.
+ * src/local/libopenvrml-dl/openvrml/local/dl.cpp
+ (openvrml::local::dl::foreachfile(const
+ std::vector<boost::filesystem::path> &, int (*)(const
+ std::string&, void *), void *)): Use boost::filesystem::path and
+ std::string.
+ (openvrml::local::dl::prepend_to_searchpath(const
+ boost::filesystem::path &)): Use boost::filesystem::path.
+ (openvrml::local::dl::open(const std::string &)): Use std::string.
+ (openvrml::local::dl::sym(handle, const std::string &)): Use
+ std::string.
+ * src/local/libopenvrml-dl/openvrml/local/dl.h
+ (openvrml::local::dl::foreachfile(const
+ std::vector<boost::filesystem::path> &, int (*)(const
+ std::string&, void *), void *)): Use boost::filesystem::path and
+ std::string.
+ (openvrml::local::dl::prepend_to_searchpath(const
+ boost::filesystem::path &)): Use boost::filesystem::path.
+ (openvrml::local::dl::open(const std::string &)): Use std::string.
+ (openvrml::local::dl::sym(handle, const std::string &)): Use
+ std::string.
+
2009-08-03 Braden McDaniel <br...@en...>
Converted Java scripting backend to use libopenvrml-dl to load
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/Makefile.am 2009-08-07 07:58:00 UTC (rev 3987)
@@ -130,7 +130,9 @@
local_libopenvrml_dl_la_CPPFLAGS = \
-I$(top_builddir)/src/libopenvrml \
-I$(top_srcdir)/src/libopenvrml
-local_libopenvrml_dl_la_LIBADD = -lltdl
+local_libopenvrml_dl_la_LIBADD = \
+ -lboost_filesystem$(BOOST_LIB_SUFFIX) \
+ -lltdl
openvrmlscriptdir = $(pkglibdir)/script
Modified: trunk/src/libopenvrml/openvrml/local/conf.cpp
===================================================================
--- trunk/src/libopenvrml/openvrml/local/conf.cpp 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/libopenvrml/openvrml/local/conf.cpp 2009-08-07 07:58:00 UTC (rev 3987)
@@ -21,6 +21,7 @@
# include "conf.h"
# include <boost/multi_index/detail/scope_guard.hpp>
# include <boost/ref.hpp>
+# include <boost/tokenizer.hpp>
# ifdef _WIN32
# include <windows.h>
# include <vector>
@@ -132,10 +133,10 @@
# endif
}
-const std::string openvrml::local::conf::datadir()
+const boost::filesystem::path openvrml::local::conf::datadir()
OPENVRML_THROW2(std::runtime_error, std::bad_alloc)
{
- std::string result;
+ boost::filesystem::path result;
try {
result = get_env("OPENVRML_DATADIR");
} catch (const no_environment_var &) {
@@ -156,25 +157,56 @@
':';
# endif
- OPENVRML_LOCAL void append_to_path(std::string & path,
- const std::string & appended_part)
- OPENVRML_THROW1(std::bad_alloc)
- {
- if (!path.empty() && !appended_part.empty()) {
- path += path_separator;
+ struct OPENVRML_LOCAL search_path_tokenizer {
+ template <typename Iterator, typename Token>
+ bool operator()(Iterator & next, Iterator end, Token & tok)
+ {
+ while (next != end) {
+ if (*next == path_separator) {
+ ++next;
+ break;
+ }
+ this->tok_.push_back(*next);
+ ++next;
+ }
+ if (!this->tok_.empty()) {
+ tok = this->tok_;
+ this->tok_.clear();
+ return true;
+ }
+ return false;
}
- path += appended_part;
- }
+
+ void reset()
+ {
+ this->tok_.clear();
+ }
+
+ private:
+ std::string tok_;
+ };
}
-const std::string openvrml::local::conf::node_path()
+const std::vector<boost::filesystem::path> openvrml::local::conf::node_path()
OPENVRML_THROW2(std::runtime_error, std::bad_alloc)
{
+ using std::back_inserter;
+ using std::copy;
+ using boost::filesystem::path;
+ typedef boost::tokenizer<search_path_tokenizer> tokenizer_t;
+
+ std::vector<path> result;
+ search_path_tokenizer tokenizer_func;
+
std::string env_path;
try {
env_path = get_env("OPENVRML_NODE_PATH");
} catch (const no_environment_var &) {}
+ tokenizer_t env_path_tokenizer(env_path, tokenizer_func);
+ copy(env_path_tokenizer.begin(), env_path_tokenizer.end(),
+ back_inserter(result));
+
std::string system_path;
# ifdef _WIN32
try {
@@ -184,19 +216,33 @@
system_path = OPENVRML_PKGLIBDIR_ "/node";
# endif
- std::string result = env_path;
- append_to_path(result, system_path);
+ tokenizer_t system_path_tokenizer(system_path, tokenizer_func);
+ copy(system_path_tokenizer.begin(), system_path_tokenizer.end(),
+ back_inserter(result));
+
return result;
}
-const std::string openvrml::local::conf::script_path()
+const std::vector<boost::filesystem::path> openvrml::local::conf::script_path()
OPENVRML_THROW2(std::runtime_error, std::bad_alloc)
{
+ using std::back_inserter;
+ using std::copy;
+ using boost::filesystem::path;
+ typedef boost::tokenizer<search_path_tokenizer> tokenizer_t;
+
+ std::vector<path> result;
+ search_path_tokenizer tokenizer_func;
+
std::string env_path;
try {
env_path = get_env("OPENVRML_SCRIPT_PATH");
} catch (const no_environment_var &) {}
+ tokenizer_t env_path_tokenizer(env_path, tokenizer_func);
+ copy(env_path_tokenizer.begin(), env_path_tokenizer.end(),
+ back_inserter(result));
+
std::string system_path;
# ifdef _WIN32
try {
@@ -206,7 +252,9 @@
system_path = OPENVRML_PKGLIBDIR_ "/script";
# endif
- std::string result = env_path;
- append_to_path(result, system_path);
+ tokenizer_t system_path_tokenizer(system_path, tokenizer_func);
+ copy(system_path_tokenizer.begin(), system_path_tokenizer.end(),
+ back_inserter(result));
+
return result;
}
Modified: trunk/src/libopenvrml/openvrml/local/conf.h
===================================================================
--- trunk/src/libopenvrml/openvrml/local/conf.h 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/libopenvrml/openvrml/local/conf.h 2009-08-07 07:58:00 UTC (rev 3987)
@@ -22,8 +22,9 @@
# define OPENVRML_LOCAL_CONF_H
# include <openvrml-common.h>
+# include <boost/filesystem/path.hpp>
# include <stdexcept>
-# include <string>
+# include <vector>
namespace openvrml {
@@ -31,11 +32,15 @@
namespace conf {
- OPENVRML_LOCAL const std::string datadir()
+ OPENVRML_LOCAL const boost::filesystem::path datadir()
OPENVRML_THROW2(std::runtime_error, std::bad_alloc);
- OPENVRML_LOCAL const std::string node_path()
+
+ OPENVRML_LOCAL
+ const std::vector<boost::filesystem::path> node_path()
OPENVRML_THROW2(std::runtime_error, std::bad_alloc);
- OPENVRML_LOCAL const std::string script_path()
+
+ OPENVRML_LOCAL
+ const std::vector<boost::filesystem::path> script_path()
OPENVRML_THROW2(std::runtime_error, std::bad_alloc);
}
}
Modified: trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.cpp
===================================================================
--- trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.cpp 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.cpp 2009-08-07 07:58:00 UTC (rev 3987)
@@ -27,10 +27,10 @@
using namespace boost::multi_index::detail; // for scope_guard
-const char openvrml::local::node_metatype_registry_impl::sym[33] =
+const std::string openvrml::local::node_metatype_registry_impl::sym =
"openvrml_register_node_metatypes";
-int openvrml_open_node_module(const char * const filename, void * const data)
+int openvrml_open_node_module(const std::string & filename, void * const data)
{
using openvrml::node_metatype_registry;
using namespace openvrml::local;
@@ -75,9 +75,9 @@
throw std::runtime_error("dlinit_failure");
}
- const std::string node_path = conf::node_path();
+ const std::vector<boost::filesystem::path> & node_path = conf::node_path();
- result = dl::foreachfile(node_path.c_str(),
+ result = dl::foreachfile(node_path,
openvrml_open_node_module,
this);
assert(result == 0); // We always return 0 from the callback.
Modified: trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.h
===================================================================
--- trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.h 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/libopenvrml/openvrml/local/node_metatype_registry_impl.h 2009-08-07 07:58:00 UTC (rev 3987)
@@ -24,8 +24,9 @@
# include <openvrml/local/dl.h>
# include <openvrml/node.h>
-extern "C" OPENVRML_LOCAL int openvrml_open_node_module(const char * filename,
- void * data);
+extern "C"
+OPENVRML_LOCAL
+int openvrml_open_node_module(const std::string & filename, void * data);
namespace openvrml {
@@ -36,8 +37,10 @@
namespace local {
class OPENVRML_LOCAL node_metatype_registry_impl : boost::noncopyable {
- friend int (::openvrml_open_node_module)(const char * filename,
- void * data);
+ friend
+ int (::openvrml_open_node_module)(const std::string & filename,
+ void * data);
+
mutable boost::shared_mutex mutex_;
openvrml::browser & browser_;
@@ -50,7 +53,7 @@
mutable node_metatype_map_t node_metatype_map_;
public:
- static const char sym[33];
+ static const std::string sym;
explicit node_metatype_registry_impl(openvrml::browser & b);
~node_metatype_registry_impl() OPENVRML_NOTHROW;
Modified: trunk/src/libopenvrml/openvrml/script.cpp
===================================================================
--- trunk/src/libopenvrml/openvrml/script.cpp 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/libopenvrml/openvrml/script.cpp 2009-08-07 07:58:00 UTC (rev 3987)
@@ -361,7 +361,7 @@
* instantiate @c script_factory_registry.
*/
-extern "C" int openvrml_get_script_factory(const char * filename, void * data);
+extern "C" int openvrml_get_script_factory(const std::string & filename, void * data);
/**
* @internal
@@ -373,7 +373,7 @@
class openvrml::script_factory_registry::impl :
boost::noncopyable {
- friend int (::openvrml_get_script_factory)(const char * filename,
+ friend int (::openvrml_get_script_factory)(const std::string & filename,
void * data);
typedef std::set<local::dl::handle> module_handle_set;
@@ -403,7 +403,7 @@
find_using_uri_scheme(const std::string & uri_scheme) const;
};
-int openvrml_get_script_factory(const char * const filename, void * data)
+int openvrml_get_script_factory(const std::string & filename, void * data)
{
assert(data);
@@ -442,9 +442,10 @@
throw std::runtime_error("dlinit failure");
}
- const std::string script_path = local::conf::script_path();
+ const std::vector<boost::filesystem::path> & script_path =
+ local::conf::script_path();
- result = dl::foreachfile(script_path.c_str(),
+ result = dl::foreachfile(script_path,
openvrml_get_script_factory,
this);
assert(result == 0); // We always return 0 from the callback.
Modified: trunk/src/local/libopenvrml-dl/openvrml/local/dl.cpp
===================================================================
--- trunk/src/local/libopenvrml-dl/openvrml/local/dl.cpp 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/local/libopenvrml-dl/openvrml/local/dl.cpp 2009-08-07 07:58:00 UTC (rev 3987)
@@ -23,6 +23,7 @@
# include <boost/ref.hpp>
# include <boost/tokenizer.hpp>
# include <boost/multi_index/detail/scope_guard.hpp>
+# include <sstream>
using namespace boost::multi_index::detail; // for scope_guard
@@ -45,75 +46,55 @@
}
namespace {
-
- struct OPENVRML_LOCAL win32_search_path_tokenizer {
- win32_search_path_tokenizer()
- {}
-
- template <typename Iterator, typename Token>
- bool operator()(Iterator & next, Iterator end, Token & tok)
- {
- while (next != end) {
- if (*next == ';') {
- ++next;
- break;
- }
- this->tok_.push_back(*next);
- ++next;
- }
- if (!this->tok_.empty()) {
- tok = this->tok_;
- this->tok_.clear();
- return true;
- }
- return false;
- }
-
- void reset()
- {
- this->tok_.clear();
- }
-
- private:
- std::string tok_;
+ struct ltforeachfile_data {
+ int (*func)(const std::string & filename, void * data);
+ void * data;
};
}
+extern "C"
+OPENVRML_LOCAL
+int openvrml_dl_ltforeachfile(const char * filename, void * data)
+{
+ ltforeachfile_data * const d = static_cast<ltforeachfile_data *>(data);
+ return (d->func)(filename, d->data);
+}
+
int
-openvrml::local::dl::foreachfile(const char * search_path,
- int (*func)(const char * filename, void * data),
- void * data)
+openvrml::local::dl::
+foreachfile(const std::vector<boost::filesystem::path> & search_path,
+ int (*func)(const std::string & filename, void * data),
+ void * data)
{
# ifdef _WIN32
using boost::filesystem::path;
using boost::filesystem::directory_iterator;
typedef boost::tokenizer<win32_search_path_tokenizer> tokenizer_t;
- std::vector<path> search_dirs;
- win32_search_path_tokenizer tokenizer_func;
- std::string search_path_str(search_path);
- tokenizer_t tokenizer(search_path_str, tokenizer_func);
- for (tokenizer_t::const_iterator token = tokenizer.begin();
- token != tokenizer.end();
- ++token) {
- search_dirs.push_back(path(*token));
- }
-
int result = 0;
- for (std::vector<path>::const_iterator dir = search_dirs.begin();
- dir != search_dirs.end();
+ for (std::vector<path>::const_iterator dir = search_path.begin();
+ dir != search_path.end();
++dir) try {
- for (directory_iterator entry(*dir);
- entry != directory_iterator();
- ++entry) {
- result = (func)(entry->path().external_file_string().c_str(),
- data);
- if (result != 0) { return result; }
- }
- } catch (boost::filesystem::filesystem_error &) {}
+ for (directory_iterator entry(*dir);
+ entry != directory_iterator();
+ ++entry) {
+ result = (func)(entry->path().external_file_string(), data);
+ if (result != 0) { return result; }
+ }
+ } catch (boost::filesystem::filesystem_error &) {}
return result;
# else
- return lt_dlforeachfile(search_path, func, data);
+ std::ostringstream path;
+ std::vector<boost::filesystem::path>::const_iterator dir =
+ search_path.begin();
+ while (dir != search_path.end()) {
+ path << *dir;
+ if (++dir != search_path.end()) { path << LT_PATHSEP_CHAR; }
+ }
+ ltforeachfile_data ltdata = { func, data };
+ return lt_dlforeachfile(path.str().c_str(),
+ openvrml_dl_ltforeachfile,
+ <data);
# endif
}
@@ -122,24 +103,26 @@
*
* @brief Prepend @p dir to the dynamic library search path.
*/
-int openvrml::local::dl::prepend_to_searchpath(const char * const dir)
+int
+openvrml::local::dl::prepend_to_searchpath(const boost::filesystem::path & dir)
{
# ifdef _WIN32
- return SetDllDirectory(dir);
+ return SetDllDirectory(dir.directory_string().c_str());
# else
const char * const before = lt_dlgetsearchpath();
- return lt_dlinsertsearchdir(before, dir);
+ return lt_dlinsertsearchdir(before, dir.directory_string().c_str());
# endif
}
-openvrml::local::dl::handle openvrml::local::dl::open(const char * filename)
+openvrml::local::dl::handle
+openvrml::local::dl::open(const std::string & filename)
{
# ifdef _WIN32
- const char * last_dot = strrchr(filename, '.');
- if (strcmp(last_dot, ".dll") != 0) { return 0; }
- return LoadLibrary(filename);
+ std::string::size_type last_dot_index = filename.find_last_of('.');
+ if (filename.substr(last_dot_index) != ".dll") { return 0; }
+ return LoadLibrary(filename.c_str());
# else
- return lt_dlopenext(filename);
+ return lt_dlopenext(filename.c_str());
# endif
}
@@ -177,11 +160,11 @@
# endif
}
-void * openvrml::local::dl::sym(handle h, const char * name)
+void * openvrml::local::dl::sym(handle h, const std::string & name)
{
# ifdef _WIN32
- return GetProcAddress(h, name);
+ return GetProcAddress(h, name.c_str());
# else
- return lt_dlsym(h, name);
+ return lt_dlsym(h, name.c_str());
# endif
}
Modified: trunk/src/local/libopenvrml-dl/openvrml/local/dl.h
===================================================================
--- trunk/src/local/libopenvrml-dl/openvrml/local/dl.h 2009-08-03 06:41:42 UTC (rev 3986)
+++ trunk/src/local/libopenvrml-dl/openvrml/local/dl.h 2009-08-07 07:58:00 UTC (rev 3987)
@@ -27,7 +27,9 @@
# else
# include <ltdl.h>
# endif
+# include <boost/filesystem/path.hpp>
# include <string>
+# include <vector>
namespace openvrml {
@@ -40,11 +42,14 @@
OPENVRML_LOCAL int exit();
OPENVRML_LOCAL
- int foreachfile(const char * search_path,
- int (*func)(const char * filename, void * data),
- void * data);
+ int
+ foreachfile(
+ const std::vector<boost::filesystem::path> & search_path,
+ int (*func)(const std::string & filename, void * data),
+ void * data);
- OPENVRML_LOCAL int prepend_to_searchpath(const char * dir);
+ OPENVRML_LOCAL
+ int prepend_to_searchpath(const boost::filesystem::path & dir);
# ifdef _WIN32
typedef HMODULE handle;
@@ -52,13 +57,13 @@
typedef lt_dlhandle handle;
# endif
- OPENVRML_LOCAL handle open(const char * filename);
+ OPENVRML_LOCAL handle open(const std::string & filename);
OPENVRML_LOCAL const std::string error();
OPENVRML_LOCAL int close(handle);
- OPENVRML_LOCAL void * sym(handle, const char * name);
+ OPENVRML_LOCAL void * sym(handle, const std::string & name);
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|