summaryrefslogtreecommitdiff
path: root/libs/pbd/pbd/search_path.h
blob: 909bffb0a4af9ccc5443e741f9a8a37d739412ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
    Copyright (C) 2007 Tim Mayberry 

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __libpbd_search_path_h__
#define __libpbd_search_path_h__

#include <string>
#include <vector>

#include "pbd/libpbd_visibility.h"

namespace PBD {

/**
 * @class Searchpath
 *
 * The Searchpath class is a helper class for getting a
 * vector of paths contained in a search path string where a 
 * "search path string" contains absolute directory paths 
 * separated by a colon(:) or a semi-colon(;) on windows.
 *
 * The Searchpath class does not test whether the paths exist
 * or are directories. It is basically just a container.
 */
class /*LIBPBD_API*/ Searchpath : public std::vector<std::string>
{
public:
	/**
	 * Create an empty Searchpath.
	 */
	LIBPBD_API Searchpath ();

	/**
	 * Initialize Searchpath from a string where the string contains
	 * one or more absolute paths to directories which are delimited 
	 * by a path separation character. The path delimeter is a 
	 * colon(:) on unix and a semi-colon(;) on windows.
	 *
	 * Each path contained in the search path may or may not resolve to
	 * an existing directory in the filesystem.
	 * 
	 * @param search_path A path string.
	 */
	LIBPBD_API Searchpath (const std::string& search_path);

	/**
	 * Initialize Searchpath from a vector of paths that may or may
	 * not exist.
	 *
	 * @param paths A vector of paths.
	 */
	LIBPBD_API Searchpath (const std::vector<std::string>& paths);

	LIBPBD_API ~Searchpath () {};

	/**
	 * @return a search path string.
	 *
	 * The string that is returned contains the platform specific
	 * path separator.
	 */
	LIBPBD_API const std::string to_string () const;

	/**
	 * Add all the directories in path to this.
	 */
	LIBPBD_API Searchpath& operator+= (const Searchpath& spath);

	/**
	 * Add another directory path to the search path.
	 */
	LIBPBD_API Searchpath& operator+= (const std::string& directory_path);
	
	/**
	 * Concatenate another Searchpath onto this.
	 */
	LIBPBD_API Searchpath& operator+ (const Searchpath& other);
	
	/**
	 * Add another path to the search path.
	 */
	LIBPBD_API Searchpath& operator+ (const std::string& directory_path);

	/**
	 * Add a sub-directory to each path in the search path.
	 * @param subdir The directory name, it should not contain 
	 * any path separating tokens.
	 */
	LIBPBD_API Searchpath& add_subdirectory_to_paths (const std::string& subdir);

protected:

	LIBPBD_API void add_directory (const std::string& directory_path);
	LIBPBD_API void add_directories (const std::vector<std::string>& paths);
};

} // namespace PBD

#endif /* __libpbd_search_path_h__ */