From 088a60c512aff26eeb026c516d0afe724880cb2b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 7 Apr 2015 10:47:28 +0200 Subject: Provide more convenient access to root scope --- build/target.cxx | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'build/target.cxx') diff --git a/build/target.cxx b/build/target.cxx index dc85402..4f49206 100644 --- a/build/target.cxx +++ b/build/target.cxx @@ -37,6 +37,20 @@ namespace build // target // + scope& target:: + base_scope () const + { + return scopes.find (dir); + } + + scope* target:: + root_scope () const + { + // This is tricky to cache so we do the lookup for now. + // + return scopes.find (dir).root_scope (); + } + ostream& operator<< (ostream& os, const target& t) { @@ -97,16 +111,17 @@ namespace build tracer& trace) { iterator i (find (target_key {&tt, &dir, &name, &ext}, trace)); + bool r (i == end ()); - if (i != end ()) - return pair (**i, false); - - unique_ptr t (tt.factory (move (dir), move (name), ext)); - i = map_.emplace ( - make_pair (target_key {&tt, &t->dir, &t->name, &t->ext}, - move (t))).first; + if (r) + { + unique_ptr pt (tt.factory (move (dir), move (name), ext)); + i = map_.emplace ( + make_pair (target_key {&tt, &pt->dir, &pt->name, &pt->ext}, + move (pt))).first; + } - return pair (**i, true); + return pair (**i, r); } ostream& -- cgit v1.1