diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2019-07-05 17:52:06 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2019-07-05 19:17:11 +0300 |
commit | f5f8d5f05c7e73627be492a1f702fcb04af3160f (patch) | |
tree | b630e1fc8077dbb444ca93b67697597acabd8dc9 | |
parent | 646ff7d9933b550b65b8377b3fa1b9bd85056cb3 (diff) |
Fix move-constructing/assigning for process_env and process_path classes
-rw-r--r-- | libbutl/command.mxx | 1 | ||||
-rw-r--r-- | libbutl/process.ixx | 48 | ||||
-rw-r--r-- | libbutl/process.mxx | 8 |
3 files changed, 45 insertions, 12 deletions
diff --git a/libbutl/command.mxx b/libbutl/command.mxx index 354788d..e2a9737 100644 --- a/libbutl/command.mxx +++ b/libbutl/command.mxx @@ -80,5 +80,4 @@ LIBBUTL_MODEXPORT namespace butl const optional<command_substitution_map>& = nullopt, char subst = '@', const std::function<command_callback>& = {}); - } diff --git a/libbutl/process.ixx b/libbutl/process.ixx index 0aa23fa..accc57b 100644 --- a/libbutl/process.ixx +++ b/libbutl/process.ixx @@ -22,13 +22,13 @@ namespace butl inline process_path:: process_path (process_path&& p) - : recall (std::move (p.recall)), - effect (std::move (p.effect)), + : effect (std::move (p.effect)), args0_ (p.args0_) { - initial = p.initial != p.recall.string ().c_str () - ? p.initial - : recall.string ().c_str (); + bool init (p.initial != p.recall.string ().c_str ()); + + recall = std::move (p.recall); + initial = init ? p.initial : recall.string ().c_str (); p.args0_ = nullptr; } @@ -41,14 +41,13 @@ namespace butl if (args0_ != nullptr) *args0_ = initial; // Restore. - recall = std::move (p.recall); - effect = std::move (p.effect); - args0_ = p.args0_; + bool init (p.initial != p.recall.string ().c_str ()); - initial = p.initial != p.recall.string ().c_str () - ? p.initial - : recall.string ().c_str (); + recall = std::move (p.recall); + effect = std::move (p.effect); + initial = init ? p.initial : recall.string ().c_str (); + args0_ = p.args0_; p.args0_ = nullptr; } @@ -237,4 +236,31 @@ namespace butl using namespace std::chrono; return timed_wait (duration_cast<milliseconds> (d)); } + + // process_env + // + inline process_env:: + process_env (process_env&& e) + { + *this = std::move (e); + } + + inline process_env& process_env:: + operator= (process_env&& e) + { + if (this != &e) + { + cwd = e.cwd; + + bool sp (e.path == &e.path_); + path_ = std::move (e.path_); + path = sp ? &path_ : e.path; + + bool sv (e.vars == e.vars_.data ()); + vars_ = std::move (e.vars_); + vars = sv ? vars_.data () : e.vars; + } + + return *this; + } } diff --git a/libbutl/process.mxx b/libbutl/process.mxx index 655650e..13438be 100644 --- a/libbutl/process.mxx +++ b/libbutl/process.mxx @@ -588,6 +588,14 @@ LIBBUTL_MODEXPORT namespace butl process_env (const butl::path& p, const V& v) : process_env (p.string (), v) {} + // Moveable-only type. + // + process_env (process_env&&); + process_env& operator= (process_env&&); + + process_env (const process_env&) = delete; + process_env& operator= (const process_env&) = delete; + private: template <typename V> void |