WvStreams
debian/libwvstreams-dev/usr/include/wvstreams/wvdiriter.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4 *
5 * Directory iterator. Recursively uses opendir and readdir, so you don't
6 * have to. Basically implements 'find'.
7 *
8 */
9
10#ifndef __WVDIRITER_H
11#define __WVDIRITER_H
12
13#include <dirent.h>
14#include <sys/stat.h>
15#include <sys/types.h>
16
17#include "wvstring.h"
18#include "wvlinklist.h"
19#include "strutils.h"
20
21struct WvDirEnt : public stat
22/***************************/
23{
24 // we already have everything from struct stat, but let's also include
25 // some variations on the filename for convenience.
26 WvString fullname; // contains: startdir/path/file
27 WvString name; // contains: file
28 WvString relname; // contains: path/file
29};
30
32/*************/
33{
34private:
35 bool recurse;
36 bool go_up;
37 bool skip_mounts;
38 bool found_top;
39
40 WvDirEnt topdir;
41 WvDirEnt info;
42 WvString relpath;
43
44 struct Dir {
45 Dir( DIR * _d, WvString _dirname )
46 : d( _d ), dirname( _dirname )
47 {}
48 ~Dir()
49 { if( d ) closedir( d ); }
50
51 DIR * d;
52 WvString dirname;
53 };
54
55 DeclareWvList( Dir );
56 DirList dirs;
57 DirList::Iter dir;
58
59public:
60 // the sizeof(stat) helps an assert() in wvdiriter.cc.
61 WvDirIter( WvStringParm dirname,
62 bool _recurse = true, bool _skip_mounts = false,
63 size_t sizeof_stat = sizeof(struct stat) );
64
65 ~WvDirIter();
66
67 bool isok() const;
68 bool isdir() const;
69 void rewind();
70 bool next();
71
72 // calling up() will abandon the current level of recursion, if, for
73 // example, you decide you don't want to continue reading the contents
74 // of the directory you're in. After up(), next() will return the next
75 // entry after the directory you've abandoned, in its parent.
76 void up()
77 { go_up = true; }
78
79 const WvDirEnt *ptr() const { return &info; }
80 WvIterStuff(const WvDirEnt);
81
82 int depth() const
83 { return( dirs.count() ); }
84};
85
86#endif
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
WvString is an implementation of a simple and efficient printable-string class.