1 /* 2 * File: SearchPath.h 3 * 4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved. 5 * See included license file for license details. 6 */ 7 #if !defined(_searchpath_h_) 8 #define _searchpath_h_ 9 10 #include <string> 11 #include <list> 12 13 /*! 14 * \brief Handles searching a list of paths for a file. 15 */ 16 class PathSearcher 17 { 18 public: 19 //! 20 enum _target_type 21 { 22 kFindFile, 23 kFindDirectory 24 }; 25 26 //! 27 typedef enum _target_type target_type_t; 28 29 protected: 30 //! Global search object singleton. 31 static PathSearcher * s_searcher; 32 33 public: 34 //! \brief Access global path searching object. 35 static PathSearcher & getGlobalSearcher(); 36 37 public: 38 //! \brief Constructor. PathSearcher()39 PathSearcher() {} 40 41 //! \brief Add a new search path to the end of the list. 42 void addSearchPath(std::string & path); 43 44 //! \brief Attempts to locate a file by using the search paths. 45 bool search(const std::string & base, target_type_t targetType, bool searchCwd, std::string & result); 46 47 protected: 48 typedef std::list<std::string> string_list_t; //!< Linked list of strings. 49 string_list_t m_paths; //!< Ordered list of paths to search. 50 51 //! \brief Returns whether \a path is absolute. 52 bool isAbsolute(const std::string & path); 53 54 //! \brief Combines two paths into a single one. 55 std::string joinPaths(const std::string & first, const std::string & second); 56 }; 57 58 #endif // _searchpath_h_ 59