summaryrefslogtreecommitdiff
path: root/project2/files/fsRows.h
blob: acbce0d0d354b8d3c9f9d03877b4ea3b98252db5 (plain)
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
#ifndef FSROWS_H
#define FSROWS_H

#include <boost/intrusive_ptr.hpp>
#include <boost/filesystem/path.hpp>
#include <sys/stat.h>
#include "variables.h"
#include "rowSet.h"
#include "scriptStorage.h"

class CommonObjects;

/// Project2 component to create a row set based on files and directories on the local filesystem
class FsRows : public RowSet {
	public:
		class SearchState;
		class SpecBase : public virtual IntrusivePtrBase {
			public:
				virtual bool recurse(const SearchState * fs) const;
				virtual bool matches(const SearchState * fs) const;
			protected:
				const boost::filesystem::path & curPath(const SearchState * fs) const;
				unsigned int depth(const SearchState * fs) const;
				const struct stat & curStat(const SearchState * fs) const;
		};
		typedef boost::intrusive_ptr<SpecBase> SpecBasePtr;
		class SpecBaseLoader : public ComponentLoader {
			public:
				virtual SpecBasePtr createFrom(ScriptNodePtr) const = 0;
				virtual SpecBasePtr create(const Glib::ustring &) const = 0;
		};
		template <class T>
		class SpecBaseLoaderImpl : public SpecBaseLoader {
			public:
				SpecBasePtr createFrom(ScriptNodePtr s) const {
					return new T(s);
				}
				SpecBasePtr create(const Glib::ustring & v) const {
					return new T(v);
				}
		};
		typedef ANONSTORAGEOF(SpecBase) SpecBases;
		typedef std::list<Glib::ustring> SpecSpec;
		typedef boost::filesystem::path Path;

		FsRows(ScriptNodePtr p);
		~FsRows();

		const Variable root;
		const Variable spec;
		const Variable ignoreErrors;

		void execute(const Glib::ustring &, const RowProcessor *) const;
		class SearchState : public RowState {
			public:
				SearchState(const boost::filesystem::path & r);

				virtual RowAttribute resolveAttr(const Glib::ustring & attrName) const;
				virtual void foreachAttr(const AttrAction & action) const;
				virtual const Columns & getColumns() const;

				VariableType fileRelPath() const;
				VariableType fileSize() const;
				VariableType fileModDate() const;
				VariableType fileUser() const;
				VariableType fileGroup() const;
				VariableType fileMode() const;
				VariableType filePerms() const;
				VariableType fileType() const;

				static const Columns col;
				SpecBases specs;
				const boost::filesystem::path fsRoot;
				boost::filesystem::path curPath;
				Glib::ustring curPathStr;
				unsigned int depth;
				struct stat curStat;
		};
	protected:
		void execute(SearchState &, const Path & dir, const RowProcessor *) const;
		friend class SpecBase;
		SpecBases specs;
};

#endif