libxml++移出对glibmm等库的依赖

前端之家收集整理的这篇文章主要介绍了libxml++移出对glibmm等库的依赖前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


原始依赖关系

libxml++

|--libxml2

|--glibmm

|--libsigc++

|--glib2.0

|--libffi


libxml++主要是使用了glibmm的Glib::ustring和Glib::Threads::Mutex两个类

1.Glib::ustring这个类主要是对std::string进行扩展,添加了iconv转换UTF-8编码的相关操作,可以外部先提前转换为UTF-8,内部直接使用std::string就行了

2.Glib::ustring::format()主要使用在int转换为string,所以可以用boost::lexical_cast<std::string>或者封装成对 itoa的调用都可以

3.Glib::Threads::Mutex 互斥锁,和boost::mutex功能一样;Glib::Threads::Mutex::Lock范围锁, 和boost::mutex::scoped_lock功能一样

使用boost好处在于boost::lexical_cast和boost::mutex都只要头文件就可以


新的依赖关系

libxml++

|--libxml2

|--boost::lexical_cast(头文件

|--boost::mutex(头文件


下面是修改好的库文件

libxml++-2.38.0-no-glibmm.txz

==========
主要改动
1.Glib::ustring::format => boost::lexical_cast<std::string>
2.Glib::ustring => std::string
3.Glib::Threads::Mutex => boost::mutex

4.G_STRFUNC => __FUNCTION__

==========
使用方法
tar -xJvf libxml++-2.38.0-no-glibmm.txz
cd libxml++-2.38.0-no-glibmm
make
make install



===========================
修改步骤

下载原始的源文件及其相关依赖的库
libxml++-2.38.0.tar.gz

--- 1..编译源文件及其相关依赖的库文件生成出Makefile

编辑Makefile去掉glibmm相关的 -I -L -l

--- 2. 行末的“\”是连接符,将他们改为一行后请手动去掉 cd <path_to_libxml++-2.38.0> sed -i "s/glibmm\/ustring.h/string>\n#include <boost\/lexical_cast.hpp/g" libxml++/exceptions/exception.h find libxml++ -name "*.h" \ -exec sed -i "s/glibmm\/ustring.h/string/g" {} \; \ -exec sed -i "s/Glib::ustring::format/boost::lexical_cast<std::string>/g" {} \; \ -exec sed -i "s/Glib::ustring/std::string/g" {} \; \ -exec sed -i "s/.bytes(/.length(/g" {} \; \ -exec sed -i "s/glibmm\/threads.h/boost\/thread.hpp/g" {} \; \ -exec sed -i "s/Glib::Threads::Mutex::Lock/boost::mutex::scoped_lock/g" {} \; \ -exec sed -i "s/Glib::Threads::Mutex/boost::mutex/g" {} \; \ -exec sed -i "s/G_STRFUNC/__FUNCTION__/g" {} \; find libxml++ -name "*.cc" \ -exec sed -i "s/glibmm\/ustring.h/string/g" {} \; \ -exec sed -i "s/Glib::ustring::format/boost::lexical_cast<std::string>/g" {} \; \ -exec sed -i "s/Glib::ustring/std::string/g" {} \; \ -exec sed -i "s/.bytes(/.length(/g" {} \; \ -exec sed -i "s/glibmm\/threads.h/boost\/thread.hpp/g" {} \; \ -exec sed -i "s/Glib::Threads::Mutex::Lock/boost::mutex::scoped_lock/g" {} \; \ -exec sed -i "s/Glib::Threads::Mutex/boost::mutex/g" {} \; \ -exec sed -i "s/G_STRFUNC/__FUNCTION__/g" {} \; --- 3.修改文件libxml++/schemabase.h ("-" delete,"+"insert) @@ -21,10 +21,7 @@ #include <libxml++/noncopyable.h> -namespace Glib -{ -class ustring; -} +#include <string> --- 4. 修改libxml++/parsers/parser.cc 文件里面的"Parser::initialize_context()" 函数("-" delete,"+"insert) void Parser::initialize_context() { - Glib::Threads::Mutex::Lock lock(extra_parser_data_mutex); +ExtraParserData extra_parser_data_; +{ + boost::mutex::scoped_lock lock(extra_parser_data_mutex); //Clear these temporary buffers: extra_parser_data[this].parser_error_.erase(); @@ -142,8 +144,9 @@ // Take a copy of the extra data,so we don't have to access // the extra_parser_data map more than necessary. - const ExtraParserData extra_parser_data_this = extra_parser_data[this]; - lock.release(); + extra_parser_data_ = extra_parser_data[this]; +} +const ExtraParserData& extra_parser_data_this = extra_parser_data_; //Disactivate any non-standards-compliant libxml1 features. //These are disactivated by default,but if we don't deactivate them for each context @@ -210,13 +213,13 @@ } }

原文链接:https://www.f2er.com/javaschema/284686.html

猜你在找的设计模式相关文章