From ace1743f7f78bb13f99553d6e97ad1beecf1ba99 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 13 Apr 2015 15:50:17 +0200 Subject: Add separate type to represent directory paths --- build/scope | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'build/scope') diff --git a/build/scope b/build/scope index 2eb8ac7..f9492e6 100644 --- a/build/scope +++ b/build/scope @@ -20,12 +20,10 @@ namespace build class scope { public: - typedef build::path path_type; - - const path_type& + const dir_path& path () const {return i_->first;} // Absolute and normalized. - const path_type& + const dir_path& src_path () const {return *src_path_;} // Corresponding src path. scope* @@ -53,7 +51,7 @@ namespace build value_proxy operator[] (const variable&); - const path_type* src_path_ {nullptr}; // Cached src_{root,base} var value. + const dir_path* src_path_ {nullptr}; // Cached src_{root,base} var value. public: variable_map variables; @@ -69,6 +67,8 @@ namespace build meta_operation_table meta_operations; operation_table operations; + typedef build::path path_type; + // Set of buildfiles already loaded for this scope. The included // buildfiles are checked against the project's root scope while // imported -- against the global scope (global_scope). @@ -90,7 +90,7 @@ namespace build friend class scope_map; friend class temp_scope; - typedef path_map::const_iterator iterator; + typedef dir_path_map::const_iterator iterator; scope (): variables (*this) {} @@ -113,25 +113,36 @@ namespace build temp_scope (scope& p) {i_ = p.i_; parent_ = &p; root_ = p.root_;} }; - class scope_map: public path_map + class scope_map: public dir_path_map { public: // Note that we assume the first insertion into the map is that // of the global scope. // std::pair - insert (const path&, bool root); + insert (const dir_path&, bool root); scope& - operator[] (const path& p) {return insert (p, false).first;} + operator[] (const dir_path& p) {return insert (p, false).first;} // Find the most qualified scope that encompasses this path. // scope& - find (const path&); + find (const dir_path&); + + scope& + find (const path& p) + { + // Natural thing to do here would be to call find (p.directory ()). + // However, there could be a situation where the passed path is a + // directory (i.e., the calling code does not know what it is dealing + // with), so let's use the whole path. + // + return find (dir_path (p.string ())); + } private: - typedef path_map base; + typedef dir_path_map base; }; extern scope_map scopes; -- cgit v1.1