Warning, file /include/boost/process/v1/detail/posix/cmd.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_
0008 #define BOOST_PROCESS_DETAIL_POSIX_CMD_HPP_
0009
0010 #include <boost/process/v1/detail/config.hpp>
0011 #include <boost/process/v1/detail/posix/handler.hpp>
0012 #include <string>
0013 #include <vector>
0014
0015 namespace boost
0016 {
0017 namespace process
0018 {
0019 BOOST_PROCESS_V1_INLINE namespace v1
0020 {
0021 namespace detail
0022 {
0023 namespace posix
0024 {
0025
0026
0027 template<typename Char>
0028 inline std::vector<std::basic_string<Char>> build_cmd(const std::basic_string<Char> & value)
0029 {
0030 std::vector<std::basic_string<Char>> ret;
0031
0032 bool in_quotes = false;
0033 auto beg = value.begin();
0034 for (auto itr = value.begin(); itr != value.end(); itr++)
0035 {
0036 if (*itr == quote_sign<Char>())
0037 in_quotes = !in_quotes;
0038
0039 if (!in_quotes && (*itr == space_sign<Char>()))
0040 {
0041 if (itr != beg)
0042 {
0043 ret.emplace_back(beg, itr);
0044 beg = itr + 1;
0045 }
0046 }
0047 }
0048 if (beg != value.end())
0049 ret.emplace_back(beg, value.end());
0050
0051 return ret;
0052 }
0053
0054 template<typename Char>
0055 struct cmd_setter_ : handler_base_ext
0056 {
0057 typedef Char value_type;
0058 typedef std::basic_string<value_type> string_type;
0059
0060 cmd_setter_(string_type && cmd_line) : _cmd_line(api::build_cmd(std::move(cmd_line))) {}
0061 cmd_setter_(const string_type & cmd_line) : _cmd_line(api::build_cmd(cmd_line)) {}
0062 template <class Executor>
0063 void on_setup(Executor& exec)
0064 {
0065 exec.exe = _cmd_impl.front();
0066 exec.cmd_line = &_cmd_impl.front();
0067 exec.cmd_style = true;
0068 }
0069 string_type str() const
0070 {
0071 string_type ret;
0072 std::size_t size = 0;
0073 for (auto & cmd : _cmd_line)
0074 size += cmd.size() + 1;
0075 ret.reserve(size -1);
0076
0077 for (auto & cmd : _cmd_line)
0078 {
0079 if (!ret.empty())
0080 ret += equal_sign<Char>();
0081 ret += cmd;
0082 }
0083 return ret;
0084 }
0085 private:
0086 static inline std::vector<Char*> make_cmd(std::vector<string_type> & args);
0087 std::vector<string_type> _cmd_line;
0088 std::vector<Char*> _cmd_impl = make_cmd(_cmd_line);
0089 };
0090
0091 template<typename Char>
0092 std::vector<Char*> cmd_setter_<Char>::make_cmd(std::vector<std::basic_string<Char>> & args)
0093 {
0094 std::vector<Char*> vec;
0095
0096 for (auto & v : args)
0097 vec.push_back(&v.front());
0098
0099 vec.push_back(nullptr);
0100
0101 return vec;
0102 }
0103
0104 }}}}}
0105
0106 #endif