Commit 4f007f771d804c2fc4006cb291e3e22d1b26cc29
1 parent
dc913a73
added better comments for stim::filename
Showing
1 changed file
with
40 additions
and
36 deletions
Show diff stats
stim/parser/filename.h
... | ... | @@ -110,7 +110,7 @@ public: |
110 | 110 | } |
111 | 111 | |
112 | 112 | |
113 | - | |
113 | + /// Outputs the file name (including prefix and extension) | |
114 | 114 | std::string get_name(){ |
115 | 115 | if(prefix == "" && ext == "") |
116 | 116 | return ""; |
... | ... | @@ -118,14 +118,18 @@ public: |
118 | 118 | return prefix + "." + ext; |
119 | 119 | } |
120 | 120 | |
121 | + /// Output the file extension only (usually three characters after a '.') | |
121 | 122 | std::string get_extension(){ |
122 | 123 | return ext; |
123 | 124 | } |
124 | 125 | |
126 | + /// Output the file prefix only (name before the extension) | |
125 | 127 | std::string get_prefix(){ |
126 | 128 | return prefix; |
127 | 129 | } |
128 | 130 | |
131 | + /// Output the entire path (not including the filename) | |
132 | + /// ex. "c:\this\is\the\directory\" | |
129 | 133 | std::string dir(){ |
130 | 134 | std::stringstream ss; |
131 | 135 | |
... | ... | @@ -146,17 +150,17 @@ public: |
146 | 150 | |
147 | 151 | } |
148 | 152 | |
153 | + /// Output the entire string, including the path and filename | |
154 | + /// ex. "c:\this\is\a\directory\file.txt" | |
149 | 155 | std::string str(){ |
150 | - | |
151 | - std::stringstream ss; | |
152 | - | |
153 | - ss<<dir()<<get_name(); | |
154 | - | |
155 | - return ss.str(); | |
156 | + std::stringstream ss; //create a string stream | |
157 | + ss<<dir()<<get_name(); //push the directory and filename to that stream | |
158 | + return ss.str(); //convert the stream to a string and return it | |
156 | 159 | } |
157 | 160 | |
158 | 161 | //***************************************************************************************************************** |
159 | 162 | // output is the directory and the prefix and the extension of the files, which are looking for in that directory. |
163 | + /// David: I have no idea what this is doing. It looks identical to dir() | |
160 | 164 | std::string dir_fname(){ |
161 | 165 | std::stringstream ss; |
162 | 166 | |
... | ... | @@ -182,20 +186,17 @@ public: |
182 | 186 | std::string f_name(std::string file_name){ |
183 | 187 | std::stringstream ss; |
184 | 188 | |
185 | - //if the path is absolute | |
186 | - if(absolute){ | |
187 | - //output the drive letter if in Windows | |
189 | + if(absolute){ //if the path is absolute | |
188 | 190 | #ifdef _WIN32 |
189 | - ss<<drive<<":"; | |
191 | + ss<<drive<<":"; //output the drive letter if in Windows | |
190 | 192 | #endif |
191 | - ss<<STIM_FILENAME_DIV; | |
193 | + ss<<STIM_FILENAME_DIV; //output a path divider | |
192 | 194 | } |
193 | 195 | |
194 | - //output the directory | |
195 | - for(unsigned int d = 0; d < path.size(); d++) | |
196 | - ss<<path[d]<<STIM_FILENAME_DIV; | |
196 | + for(unsigned int d = 0; d < path.size(); d++) //for each directory in the current path | |
197 | + ss<<path[d]<<STIM_FILENAME_DIV; //add that directory, interspersing path dividers | |
197 | 198 | |
198 | - stim::filename fn = file_name; | |
199 | + stim::filename fn = file_name; | |
199 | 200 | std::string fn_prefix = fn.prefix; |
200 | 201 | std::string fn_ext = fn.ext; |
201 | 202 | ss<<fn_prefix + '.' + fn_ext; |
... | ... | @@ -204,38 +205,41 @@ public: |
204 | 205 | |
205 | 206 | } |
206 | 207 | |
208 | + /// Returns a list of files using the current filename as a template. | |
209 | + /// For example: | |
210 | + /// C:\this\is\a\path\file*.txt | |
211 | + /// can be used as a template to find a series of files file001.txt, file002.txt, file003.txt, etc. | |
207 | 212 | std::vector<stim::filename> get_list(){ |
208 | -#ifdef _WIN32 | |
209 | - //get a list of files matching the current template | |
210 | - | |
213 | + //this is OS dependent, so we're starting with Windows | |
214 | + //the Unix version requires Boost | |
211 | 215 | |
212 | - //stim::filename file_path; | |
213 | - stim::filename filepath(dir_fname()); | |
216 | +#elif _WIN32 | |
217 | + stim::filename filepath(dir_fname()); //initialize filepath with the mask | |
214 | 218 | |
215 | - HANDLE hFind = INVALID_HANDLE_VALUE; | |
219 | + HANDLE hFind = INVALID_HANDLE_VALUE; //allocate data structures for looping through files | |
216 | 220 | WIN32_FIND_DATAA FindFileData; |
217 | - std::vector<stim::filename> file_list; | |
221 | + std::vector<stim::filename> file_list; //initialize a list to hold all matching filenames | |
218 | 222 | |
219 | - hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); | |
223 | + hFind = FindFirstFileA((filepath.str().c_str()), &FindFileData); //find the first file that matches the specified file path | |
220 | 224 | |
221 | - if (hFind == INVALID_HANDLE_VALUE) { | |
222 | - printf ("Invalid file handle. Error is %u.\n", GetLastError()); | |
225 | + if (hFind == INVALID_HANDLE_VALUE) { //if there are no matching files | |
226 | + printf ("Invalid file handle. Error is %u.\n", GetLastError()); //print an error | |
223 | 227 | } |
224 | 228 | else { |
225 | - std::string file_name = FindFileData.cFileName; //get the file name | |
226 | - std::string file_path = dir(); | |
227 | - stim::filename current_file(file_path + file_name); | |
228 | - file_list.push_back(current_file); | |
229 | + std::string file_name = FindFileData.cFileName; //save the file name | |
230 | + std::string file_path = dir(); //the file is in the specified directory, so save it | |
231 | + stim::filename current_file(file_path + file_name); //create a stim::filename structure representing this file | |
232 | + file_list.push_back(current_file); //push the new stim::filename to the file list | |
229 | 233 | |
230 | 234 | // List all the other files in the directory. |
231 | - while (FindNextFileA(hFind, &FindFileData) != 0){ | |
232 | - file_name = FindFileData.cFileName; | |
233 | - current_file = (f_name(file_name)); | |
234 | - file_list.push_back(current_file); | |
235 | + while (FindNextFileA(hFind, &FindFileData) != 0){ //iterate until there are no more matching files | |
236 | + file_name = FindFileData.cFileName; //save the next file | |
237 | + current_file = (f_name(file_name)); //append the directory | |
238 | + file_list.push_back(current_file); //push it to the list | |
235 | 239 | } |
236 | - FindClose(hFind); | |
240 | + FindClose(hFind); //close the file data structure | |
237 | 241 | } |
238 | - return file_list; | |
242 | + return file_list; //return the list of files | |
239 | 243 | |
240 | 244 | #elif BOOST_PRECOMPILED |
241 | 245 | ... | ... |