File size: 14,620 Bytes
9375c9a |
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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library. See http://dlib.net for updates. --><head><title>dlib C++ Library - dir_nav_extensions.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2009 Davis E. King ([email protected])
</font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_DIR_NAV_EXTENSIONs_H_
<font color='#0000FF'>#define</font> DLIB_DIR_NAV_EXTENSIONs_H_
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>string<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>vector<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>algorithm<font color='#5555FF'>></font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='dir_nav_extensions_abstract.h.html'>dir_nav_extensions_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../dir_nav.h.html'>../dir_nav.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../string.h.html'>../string.h</a>"
<font color='#0000FF'>namespace</font> dlib
<b>{</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'><u>bool</u></font> <b><a name='file_exists'></a>file_exists</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&</font> filename
<font face='Lucida Console'>)</font>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>namespace</font> implementation_details
<b>{</b>
<font color='#0000FF'><u>void</u></font> <b><a name='get_all_sub_dirs'></a>get_all_sub_dirs</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> directory<font color='#5555FF'>&</font> top_of_tree,
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> max_depth,
std::vector<font color='#5555FF'><</font>directory<font color='#5555FF'>></font><font color='#5555FF'>&</font> result,
std::vector<font color='#5555FF'><</font>directory<font color='#5555FF'>></font><font color='#5555FF'>&</font> temp
<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>></font>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font>file<font color='#5555FF'>></font> <b><a name='get_files_in_directory_tree'></a>get_files_in_directory_tree</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> directory<font color='#5555FF'>&</font> top_of_tree,
<font color='#0000FF'>const</font> T<font color='#5555FF'>&</font> add_file,
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> max_depth <font color='#5555FF'>=</font> <font color='#979000'>30</font>
<font face='Lucida Console'>)</font>
<b>{</b>
std::vector<font color='#5555FF'><</font>file<font color='#5555FF'>></font> result, temp;
std::vector<font color='#5555FF'><</font>directory<font color='#5555FF'>></font> dirs, dirs_temp;
dirs.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>top_of_tree<font face='Lucida Console'>)</font>;
<font color='#009900'>// get all the directories in the tree first
</font> implementation_details::<font color='#BB00BB'>get_all_sub_dirs</font><font face='Lucida Console'>(</font>top_of_tree, max_depth, dirs, dirs_temp<font face='Lucida Console'>)</font>;
<font color='#009900'>// now just loop over all the directories and pick out the files we want to keep
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> d <font color='#5555FF'>=</font> <font color='#979000'>0</font>; d <font color='#5555FF'><</font> dirs.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>d<font face='Lucida Console'>)</font>
<b>{</b>
dirs[d].<font color='#BB00BB'>get_files</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
<font color='#009900'>// pick out the members of temp that we should keep
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>add_file</font><font face='Lucida Console'>(</font>temp[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
result.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>temp[i]<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'>return</font> result;
<b>}</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>class</font> <b><a name='match_ending'></a>match_ending</b>
<b>{</b>
<font color='#0000FF'>public</font>:
<b><a name='match_ending'></a>match_ending</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&</font> ending_
<font face='Lucida Console'>)</font> : ending<font face='Lucida Console'>(</font>ending_<font face='Lucida Console'>)</font> <b>{</b><b>}</b>
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> file<font color='#5555FF'>&</font> f
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
<b>{</b>
<font color='#009900'>// if the ending is bigger than f's name then it obviously doesn't match
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ending.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font> f.<font color='#BB00BB'>name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>false</font>;
<font color='#009900'>// now check if the actual characters that make up the end of the file name
</font> <font color='#009900'>// matches what is in ending.
</font> <font color='#0000FF'>return</font> std::<font color='#BB00BB'>equal</font><font face='Lucida Console'>(</font>ending.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, ending.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, f.<font color='#BB00BB'>name</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>ending.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>private</font>:
std::string ending;
<b>}</b>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>class</font> <b><a name='match_endings'></a>match_endings</b>
<b>{</b>
<font color='#0000FF'>public</font>:
<b><a name='match_endings'></a>match_endings</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&</font> endings_
<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font>std::string<font color='#5555FF'>></font><font color='#5555FF'>&</font> s <font color='#5555FF'>=</font> <font color='#BB00BB'>split</font><font face='Lucida Console'>(</font>endings_<font face='Lucida Console'>)</font>;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> s.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
<b>{</b>
endings.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>match_ending</font><font face='Lucida Console'>(</font>s[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> file<font color='#5555FF'>&</font> f
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
<b>{</b>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> endings.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>endings[i]<font face='Lucida Console'>(</font>f<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>true</font>;
<b>}</b>
<font color='#0000FF'>return</font> <font color='#979000'>false</font>;
<b>}</b>
<font color='#0000FF'>private</font>:
std::vector<font color='#5555FF'><</font>match_ending<font color='#5555FF'>></font> endings;
<b>}</b>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>class</font> <b><a name='match_all'></a>match_all</b>
<b>{</b>
<font color='#0000FF'>public</font>:
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> file<font color='#5555FF'>&</font>
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> <font color='#979000'>true</font>; <b>}</b>
<b>}</b>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
directory <b><a name='get_parent_directory'></a>get_parent_directory</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> directory<font color='#5555FF'>&</font> dir
<font face='Lucida Console'>)</font>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
directory <b><a name='get_parent_directory'></a>get_parent_directory</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> file<font color='#5555FF'>&</font> f
<font face='Lucida Console'>)</font>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
std::string <b><a name='select_oldest_file'></a>select_oldest_file</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&</font> filename1,
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&</font> filename2
<font face='Lucida Console'>)</font>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
std::string <b><a name='select_newest_file'></a>select_newest_file</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&</font> filename1,
<font color='#0000FF'>const</font> std::string<font color='#5555FF'>&</font> filename2
<font face='Lucida Console'>)</font>;
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>
<font color='#0000FF'>#ifdef</font> NO_MAKEFILE
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='dir_nav_extensions.cpp.html'>dir_nav_extensions.cpp</a>"
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_DIR_NAV_EXTENSIONs_H_
</font>
</pre></body></html> |