Skip to content

Commit

Permalink
Forking Boost.Tokenizer
Browse files Browse the repository at this point in the history
- flyby: remove more Boost headers that are not needed anymore
  • Loading branch information
hkaiser committed Dec 7, 2022
1 parent 896c388 commit 76b71b3
Show file tree
Hide file tree
Showing 48 changed files with 1,765 additions and 458 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -2345,7 +2345,6 @@ if(HPX_WITH_PRECOMPILED_HEADERS)
<boost/lockfree/queue.hpp>
<boost/optional.hpp>
<boost/spirit/home/x3.hpp>
<boost/tokenizer.hpp>
)

if(HPX_WITH_CXX17_FILESYSTEM)
Expand Down
Expand Up @@ -17,78 +17,72 @@
#include <hpx/modules/filesystem.hpp>
#include <hpx/serialization/string.hpp>

#include <boost/shared_array.hpp>

#include <string>

namespace hpx { namespace components { namespace process { namespace posix {

namespace initializers {
namespace hpx::components::process::posix::initializers {

class run_exe_ : public initializer_base
{
public:
run_exe_()
class run_exe_ : public initializer_base
{
cmd_line_[0] = cmd_line_[1] = nullptr;
}

explicit run_exe_(const std::string &s)
: s_(s)
public:
run_exe_()
{
cmd_line_[0] = cmd_line_[1] = nullptr;
}

explicit run_exe_(const std::string& s)
: s_(s)
{
cmd_line_[0] = const_cast<char*>(s_.c_str());
cmd_line_[1] = nullptr;
}

template <class PosixExecutor>
void on_exec_setup(PosixExecutor& e) const
{
e.exe = s_.c_str();
if (!e.cmd_line)
e.cmd_line = const_cast<char**>(cmd_line_);
}

private:
friend class hpx::serialization::access;

template <typename Archive>
void save(Archive& ar, unsigned const) const
{
ar& s_;
}

template <typename Archive>
void load(Archive& ar, const unsigned int)
{
ar& s_;

cmd_line_[0] = const_cast<char*>(s_.c_str());
cmd_line_[1] = nullptr;
}

HPX_SERIALIZATION_SPLIT_MEMBER()

std::string s_;
char* cmd_line_[2];
};

inline run_exe_ run_exe(const char* s)
{
cmd_line_[0] = const_cast<char*>(s_.c_str());
cmd_line_[1] = nullptr;
return run_exe_(s);
}

template <class PosixExecutor>
void on_exec_setup(PosixExecutor &e) const
inline run_exe_ run_exe(const std::string& s)
{
e.exe = s_.c_str();
if (!e.cmd_line)
e.cmd_line = const_cast<char**>(cmd_line_);
return run_exe_(s);
}

private:
friend class hpx::serialization::access;

template <typename Archive>
void save(Archive& ar, unsigned const) const
inline run_exe_ run_exe(const filesystem::path& p)
{
ar & s_;
return run_exe_(p.string());
}

template <typename Archive>
void load(Archive& ar, const unsigned int)
{
ar & s_;

cmd_line_[0] = const_cast<char*>(s_.c_str());
cmd_line_[1] = nullptr;
}

HPX_SERIALIZATION_SPLIT_MEMBER()

std::string s_;
char* cmd_line_[2];
};

inline run_exe_ run_exe(const char *s)
{
return run_exe_(s);
}

inline run_exe_ run_exe(const std::string &s)
{
return run_exe_(s);
}

inline run_exe_ run_exe(const filesystem::path &p)
{
return run_exe_(p.string());
}

}

}}}}
} // namespace hpx::components::process::posix::initializers

#endif
Expand Up @@ -16,83 +16,80 @@
#include <hpx/components/process/util/posix/initializers/initializer_base.hpp>
#include <hpx/serialization/string.hpp>
#include <hpx/serialization/vector.hpp>
#include <hpx/modules/string_util.hpp>

#if !defined(HPX_HAVE_CXX17_SHARED_PTR_ARRAY)
#include <boost/shared_array.hpp>
#else
#include <memory>
#endif

#include <boost/tokenizer.hpp>

#include <cstddef>
#include <string>
#include <vector>

namespace hpx { namespace components { namespace process { namespace posix {

namespace initializers {

class set_cmd_line : public initializer_base
{
public:
explicit set_cmd_line(const std::string &s)
{
split_command_line(s);
init_command_line_arguments();
}

template <class PosixExecutor>
void on_exec_setup(PosixExecutor &e) const
{
e.cmd_line = cmd_line_.get();
}

private:
void split_command_line(std::string const& s)
{
typedef boost::tokenizer<boost::escaped_list_separator<char> > tokenizer;
boost::escaped_list_separator<char> sep('\\', ' ', '\"');
tokenizer tok(s, sep);
args_.assign(tok.begin(), tok.end());
}

void init_command_line_arguments()
{
cmd_line_.reset(new char*[args_.size() + 1]);
std::size_t i = 0;
for (std::string const& s : args_)
cmd_line_[i++] = const_cast<char*>(s.c_str());
cmd_line_[i] = nullptr;
}

friend class hpx::serialization::access;

template <typename Archive>
void save(Archive& ar, unsigned const) const
{
ar & args_;
}
namespace hpx::components::process::posix::initializers {

template <typename Archive>
void load(Archive& ar, const unsigned int)
class set_cmd_line : public initializer_base
{
ar & args_;
init_command_line_arguments();
}

HPX_SERIALIZATION_SPLIT_MEMBER()

std::vector<std::string> args_;
public:
explicit set_cmd_line(const std::string& s)
{
split_command_line(s);
init_command_line_arguments();
}

template <class PosixExecutor>
void on_exec_setup(PosixExecutor& e) const
{
e.cmd_line = cmd_line_.get();
}

private:
void split_command_line(std::string const& s)
{
typedef hpx::string_util::tokenizer<
hpx::string_util::escaped_list_separator<char>>
tokenizer;
hpx::string_util::escaped_list_separator<char> sep('\\', ' ', '\"');
tokenizer tok(s, sep);
args_.assign(tok.begin(), tok.end());
}

void init_command_line_arguments()
{
cmd_line_.reset(new char*[args_.size() + 1]);
std::size_t i = 0;
for (std::string const& s : args_)
cmd_line_[i++] = const_cast<char*>(s.c_str());
cmd_line_[i] = nullptr;
}

friend class hpx::serialization::access;

template <typename Archive>
void save(Archive& ar, unsigned const) const
{
ar& args_;
}

template <typename Archive>
void load(Archive& ar, const unsigned int)
{
ar& args_;
init_command_line_arguments();
}

HPX_SERIALIZATION_SPLIT_MEMBER()

std::vector<std::string> args_;
#if defined(HPX_HAVE_CXX17_SHARED_PTR_ARRAY)
std::shared_ptr<char*[]> cmd_line_;
std::shared_ptr<char*[]> cmd_line_;
#else
boost::shared_array<char*> cmd_line_;
boost::shared_array<char*> cmd_line_;
#endif
};

}
};

}}}}
} // namespace hpx::components::process::posix::initializers

#endif
21 changes: 10 additions & 11 deletions components/process/src/util/posix/search_path_u.cpp
Expand Up @@ -3,7 +3,7 @@
// Copyright (c) 2009 Boris Schaeling
// Copyright (c) 2010 Felipe Tanus, Boris Schaeling
// Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
// Copyright (c) 2016 Hartmut Kaiser
// Copyright (c) 2016-2022 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand All @@ -15,33 +15,32 @@
#include <hpx/components/process/util/search_path.hpp>
#include <hpx/modules/errors.hpp>
#include <hpx/modules/filesystem.hpp>

#include <boost/tokenizer.hpp>
#include <hpx/modules/string_util.hpp>

#include <unistd.h>

#include <cstdlib>
#include <stdexcept>
#include <string>

namespace hpx { namespace components { namespace process { namespace posix
{
std::string search_path(const std::string &filename, std::string path)
namespace hpx { namespace components { namespace process { namespace posix {
std::string search_path(const std::string& filename, std::string path)
{
if (path.empty())
{
path = ::getenv("PATH");
if (path.empty())
{
HPX_THROW_EXCEPTION(invalid_status,
"process::search_path",
HPX_THROW_EXCEPTION(invalid_status, "process::search_path",
"Environment variable PATH not found");
}
}

std::string result;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
boost::char_separator<char> sep(":");
typedef hpx::string_util::tokenizer<
hpx::string_util::char_separator<char>>
tokenizer;
hpx::string_util::char_separator<char> sep(":");
tokenizer tok(path, sep);
for (tokenizer::iterator it = tok.begin(); it != tok.end(); ++it)
{
Expand All @@ -55,6 +54,6 @@ namespace hpx { namespace components { namespace process { namespace posix
}
return result;
}
}}}}
}}}} // namespace hpx::components::process::posix

#endif

0 comments on commit 76b71b3

Please sign in to comment.