Made this example simpler

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402505
This commit is contained in:
Davis King 2008-09-07 02:54:28 +00:00
parent 6fa91605f8
commit bfad8f3ef6
1 changed files with 16 additions and 27 deletions

View File

@ -10,17 +10,12 @@
#include <iostream>
#include <iomanip>
#include "dlib/dir_nav.h"
#include "dlib/queue.h"
#include "dlib/static_set.h"
#include <vector>
#include <algorithm>
using namespace std;
using namespace dlib;
typedef queue<directory>::kernel_2a queue_of_dirs;
typedef queue<file>::kernel_2a queue_of_files;
typedef static_set<file>::kernel_1a set_of_files;
typedef static_set<directory>::kernel_1a set_of_dirs;
int main(int argc, char** argv)
{
@ -34,10 +29,8 @@ int main(int argc, char** argv)
directory test(loc);
queue_of_dirs dirs;
queue_of_files files;
set_of_dirs sorted_dirs;
set_of_files sorted_files;
std::vector<directory> dirs;
std::vector<file> files;
cout << "directory: " << test.name() << endl;
cout << "full path: " << test.full_name() << endl;
@ -47,38 +40,34 @@ int main(int argc, char** argv)
test.get_dirs(dirs);
test.get_files(files);
// load the dirs and files into static_sets. This
// seems weird but a static_set can be enumerated in sorted order
// so this way we can print everything in sorted order. This
// static_set also uses a median of three quick sort so the sorting
// should be very fast.
sorted_files.load(files);
sorted_dirs.load(dirs);
// sort the files and directorys
sort(files.begin(), files.end());
sort(dirs.begin(), dirs.end());
cout << "\n\n\n";
// print all the subdirectories
while (sorted_dirs.move_next())
cout << " <DIR> " << sorted_dirs.element().name() << "\n";
for (unsigned long i = 0; i < dirs.size(); ++i)
cout << " <DIR> " << dirs[i].name() << "\n";
// print all the subfiles
while (sorted_files.move_next())
cout << setw(13) << sorted_files.element().size() << " " << sorted_files.element().name() << "\n";
for (unsigned long i = 0; i < files.size(); ++i)
cout << setw(13) << files[i].size() << " " << files[i].name() << "\n";
cout << "\n\nnumber of dirs: " << sorted_dirs.size() << endl;
cout << "number of files: " << sorted_files.size() << endl;
cout << "\n\nnumber of dirs: " << dirs.size() << endl;
cout << "number of files: " << files.size() << endl;
}
catch (file::file_not_found e)
catch (file::file_not_found& e)
{
cout << "file not found or accessable: " << e.info << endl;
}
catch (directory::dir_not_found e)
catch (directory::dir_not_found& e)
{
cout << "dir not found or accessable: " << e.info << endl;
}
catch (directory::listing_error e)
catch (directory::listing_error& e)
{
cout << "listing error: " << e.info << endl;
}