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

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

class CommonObjects;

/// Project2 component to create a row set based on files and directories on the local filesystem
class DLL_PUBLIC FsRows : public RowSet {
	public:
		class SearchState;
		class SpecBase : public virtual Something {
			public:
				virtual bool recurse(const SearchState * fs, ExecContext *) const;
				virtual bool matches(const SearchState * fs, ExecContext *) 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 std::shared_ptr<SpecBase> SpecBasePtr;
		typedef AdHoc::Factory<SpecBase, std::shared_ptr<const ScriptNode>> SpecBaseFactory;
		typedef AdHoc::Factory<SpecBase, const Glib::ustring &> SpecBaseStringFactory;
		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 RowProcessorCallback &, ExecContext *) 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 RowProcessorCallback &, ExecContext *) const;
		friend class SpecBase;
		SpecBases specs;
};

#endif