Remove two unused temporary variables from SearchPath::add_subdirectory_to_paths
[ardour.git] / libs / pbd / search_path.cc
1 /*
2     Copyright (C) 2007 Tim Mayberry 
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <pbd/tokenizer.h>
21 #include <pbd/search_path.h>
22 #include <pbd/error.h>
23
24 namespace {
25
26 #ifdef WIN32
27 const char * const path_delimiter = ";";
28 #else
29 const char * const path_delimiter = ":";
30 #endif
31
32 }
33
34 namespace PBD {
35
36 SearchPath::SearchPath ()
37 {
38
39 }
40
41 SearchPath::SearchPath (const string& path)
42 {
43         vector<sys::path> tmp;
44
45         if(!tokenize ( path, string(path_delimiter), std::back_inserter (tmp)))
46         {
47                 // log warning(info perhaps?) that the path is empty 
48                 warning << "SearchPath contains no tokens" << endmsg;
49
50         }
51
52         add_directories (tmp);
53 }
54
55 SearchPath::SearchPath (const vector<sys::path>& paths)
56 {
57         add_directories (paths);
58 }
59
60 SearchPath::SearchPath (const SearchPath& other)
61         : m_dirs(other.m_dirs)
62 {
63
64 }
65
66 void
67 SearchPath::add_directory (const sys::path& directory_path)
68 {
69         // test for existance and warn etc?
70         m_dirs.push_back(directory_path);
71 }
72
73 void
74 SearchPath::add_directories (const vector<sys::path>& paths)
75 {
76         for(vector<sys::path>::const_iterator i = paths.begin(); i != paths.end(); ++i) {
77                 add_directory (*i);
78         }
79 }
80
81 const string
82 SearchPath::get_string () const
83 {
84         string path;
85
86         for (vector<sys::path>::const_iterator i = m_dirs.begin(); i != m_dirs.end(); ++i) {
87                 path += (*i).to_string();
88                 path += path_delimiter;
89         }
90
91         path = path.substr (0, path.length() - 1); // drop final separator
92
93         return path;
94 }
95
96 SearchPath&
97 SearchPath::operator= (const SearchPath& path)
98 {
99         m_dirs = path.m_dirs;
100         return *this;
101 }
102
103 SearchPath& 
104 SearchPath::operator+= (const SearchPath& spath)
105 {
106         m_dirs.insert(m_dirs.end(), spath.m_dirs.begin(), spath.m_dirs.end());
107         return *this;
108 }
109
110 SearchPath& 
111 SearchPath::operator+= (const sys::path& directory_path)
112 {
113         add_directory (directory_path);
114         return *this;
115 }
116
117 SearchPath& 
118 SearchPath::operator+ (const sys::path& directory_path)
119 {
120         add_directory (directory_path);
121         return *this;
122 }
123
124 SearchPath& 
125 SearchPath::operator+ (const SearchPath& spath)
126 {
127         // concatenate paths into new SearchPath
128         m_dirs.insert(m_dirs.end(), spath.m_dirs.begin(), spath.m_dirs.end());
129         return *this;
130 }
131
132 SearchPath&
133 SearchPath::add_subdirectory_to_paths (const string& subdir)
134 {
135         for (vector<sys::path>::iterator i = m_dirs.begin(); i != m_dirs.end(); ++i)
136         {
137                 // should these new paths just be added to the end of 
138                 // the search path rather than replace?
139                 *i /= subdir;
140         }
141         
142         return *this;
143 }
144         
145 SearchPath&
146 SearchPath::operator/= (const string& subdir)
147 {
148         return add_subdirectory_to_paths (subdir);
149 }
150
151 } // namespace PBD