Skip to content

Commit

Permalink
Removed dependency on Boost.LexicalCast.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastique committed Aug 25, 2023
1 parent e175d01 commit 7ddeff5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,6 @@ target_link_libraries(boost_log
Boost::bind
Boost::exception
Boost::interprocess
Boost::lexical_cast
Boost::optional
Boost::random
Boost::spirit
Expand Down Expand Up @@ -544,7 +543,6 @@ set(boost_log_setup_public_deps
Boost::config
Boost::core
Boost::iterator
Boost::lexical_cast
Boost::move
Boost::optional
Boost::parameter
Expand Down
17 changes: 14 additions & 3 deletions example/doc/extension_filter_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

#include <string>
#include <sstream>
#include <iostream>
#include <stdexcept>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/phoenix.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
Expand Down Expand Up @@ -110,12 +110,23 @@ class point_filter_factory :

logging::filter on_equality_relation(logging::attribute_name const& name, string_type const& arg)
{
return expr::attr< point >(name) == boost::lexical_cast< point >(arg);
return expr::attr< point >(name) == parse_argument(arg);
}

logging::filter on_inequality_relation(logging::attribute_name const& name, string_type const& arg)
{
return expr::attr< point >(name) != boost::lexical_cast< point >(arg);
return expr::attr< point >(name) != parse_argument(arg);
}

private:
static point parse_argument(string_type const& arg)
{
std::istringstream strm(arg);
point val;
strm >> val;
if (strm.fail() || strm.bad())
throw std::runtime_error("Failed to parse point from \"" + arg + "\"");
return val;
}
};

Expand Down
20 changes: 16 additions & 4 deletions example/doc/extension_filter_parser_custom_rel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

#include <string>
#include <sstream>
#include <iostream>
#include <stdexcept>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/phoenix.hpp>
#include <boost/log/core.hpp>
#include <boost/log/expressions.hpp>
Expand Down Expand Up @@ -142,22 +142,34 @@ class point_filter_factory :

logging::filter on_equality_relation(logging::attribute_name const& name, string_type const& arg)
{
return expr::attr< point >(name) == boost::lexical_cast< point >(arg);
return expr::attr< point >(name) == parse_argument< point >(arg);
}

logging::filter on_inequality_relation(logging::attribute_name const& name, string_type const& arg)
{
return expr::attr< point >(name) != boost::lexical_cast< point >(arg);
return expr::attr< point >(name) != parse_argument< point >(arg);
}

logging::filter on_custom_relation(logging::attribute_name const& name, string_type const& rel, string_type const& arg)
{
if (rel == "is_in_rectangle")
{
return boost::phoenix::bind(&is_in_rectangle, expr::attr< point >(name), boost::lexical_cast< rectangle >(arg));
return boost::phoenix::bind(&is_in_rectangle, expr::attr< point >(name), parse_argument< rectangle >(arg));
}
throw std::runtime_error("Unsupported filter relation: " + rel);
}

private:
template< typename ArgumentT >
static ArgumentT parse_argument(string_type const& arg)
{
std::istringstream strm(arg);
ArgumentT val;
strm >> val;
if (strm.fail() || strm.bad())
throw std::runtime_error("Failed to parse argument from \"" + arg + "\"");
return val;
}
};

void init_factories()
Expand Down
3 changes: 1 addition & 2 deletions example/doc/extension_stat_collector_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <stdexcept>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/optional/optional.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <boost/phoenix.hpp>
Expand Down Expand Up @@ -169,7 +168,7 @@ class stat_collector_factory :
boost::posix_time::time_duration write_interval = boost::posix_time::minutes(1);
if (boost::optional< std::string > param = settings["WriteInterval"])
{
unsigned int sec = boost::lexical_cast< unsigned int >(param.get());
unsigned long sec = std::stoul(param.get());
write_interval = boost::posix_time::seconds(sec);
}

Expand Down
9 changes: 7 additions & 2 deletions include/boost/log/utility/setup/filter_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define BOOST_LOG_UTILITY_SETUP_FILTER_PARSER_HPP_INCLUDED_

#include <string>
#include <boost/lexical_cast.hpp>
#include <sstream>
#include <boost/smart_ptr/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared_object.hpp>
#include <boost/phoenix/operator/comparison.hpp>
Expand Down Expand Up @@ -217,7 +217,12 @@ class basic_filter_factory :
*/
virtual value_type parse_argument(string_type const& arg)
{
return boost::lexical_cast< value_type >(arg);
std::basic_istringstream< typename base_type::char_type > strm(arg);
value_type val{};
strm >> val;
if (BOOST_UNLIKELY((strm.rdstate() & (std::ios_base::badbit | std::ios_base::failbit)) != 0))
BOOST_LOG_THROW_DESCR(parse_error, "Failed to parse argument value from \"" + boost::log::aux::to_narrow(arg) + "\"");
return val;
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/process_name.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ BOOST_LOG_CLOSE_NAMESPACE // namespace log
#include <unistd.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <boost/lexical_cast.hpp>
#include <string>
#include <boost/filesystem/operations.hpp>
#include <boost/log/detail/header.hpp>

Expand All @@ -137,7 +137,7 @@ BOOST_LOG_API std::string get_process_name()
if (filesystem::exists("/proc/curproc/file"))
return filesystem::read_symlink("/proc/curproc/file").filename().string();

return boost::lexical_cast< std::string >(getpid());
return std::to_string(getpid());
}

} // namespace aux
Expand All @@ -151,7 +151,7 @@ BOOST_LOG_CLOSE_NAMESPACE // namespace log
#else

#include <unistd.h>
#include <boost/lexical_cast.hpp>
#include <string>
#include <boost/filesystem/operations.hpp>
#include <boost/log/detail/header.hpp>

Expand All @@ -173,7 +173,7 @@ BOOST_LOG_API std::string get_process_name()
if (filesystem::exists("/proc/curproc/exe"))
return filesystem::read_symlink("/proc/curproc/exe").filename().string();

return boost::lexical_cast< std::string >(getpid());
return std::to_string(getpid());
}

} // namespace aux
Expand Down

0 comments on commit 7ddeff5

Please sign in to comment.