-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrules.h
108 lines (86 loc) · 2.55 KB
/
rules.h
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
/////////////////////////////////////////////////////////////////////////////////
// Author: Steven Lamerton
// Copyright: Copyright (C) 2007-2010 Steven Lamerton
// License: GNU GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
/////////////////////////////////////////////////////////////////////////////////
#ifndef H_RULES
#define H_RULES
class frmMain;
#include "path.h"
#include <wx/arrstr.h>
#include <wx/filename.h>
#include <wx/longlong.h>
#include <vector>
#include <boost/bimap.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/assign/list_inserter.hpp>
enum RuleFunction{
FileInclude,
FileExclude,
FolderInclude,
FolderExclude,
AbsoluteFolderExclude
};
enum RuleType{
Simple,
Regex,
Date,
Size
};
enum RuleResult{
NoMatch,
Included,
Excluded,
AbsoluteExcluded
};
namespace{
/*Gets a files size in petabytes, should do for now but it may need changing in a few years ;)
Expects to be passed the result of a wxFilename.GetHumanReadableSize()*/
double GetInPB(const wxString &value);
}
//A pair of bimaps for easily converting between our enums and strings
static const boost::bimap<wxString, RuleType> typemap = boost::assign::list_of<boost::bimap<wxString, RuleType>::relation>
("Simple", Simple)
("Regex", Regex)
("Size", Size)
("Date", Date);
static const boost::bimap<wxString, RuleFunction> functionmap = boost::assign::list_of<boost::bimap<wxString, RuleFunction>::relation>
("File Include", FileInclude)
("File Exclude", FileExclude)
("Folder Include", FolderInclude)
("Folder Exclude", FolderExclude)
("Absolute Folder Exclude", AbsoluteFolderExclude);
class Rule{
public:
Rule(const wxString &rule, RuleFunction function, RuleType type){
this->rule = rule;
this->normalised = Path::Normalise(rule);
this->function = function;
this->type = type;
this->valid = Validate();
}
RuleResult Matches(wxFileName path);
bool IsValid() const { return valid; }
wxString rule;
RuleFunction function;
RuleType type;
private:
wxString normalised;
bool valid;
bool Validate();
};
class RuleSet{
public:
RuleSet(const wxString &name) { this->name = name; }
RuleResult Matches(wxFileName path);
bool IsValid();
bool TransferToFile();
bool TransferFromFile();
void Add(Rule rule) { rules.push_back(rule); }
const wxString& GetName() const {return name;}
const std::vector<Rule>& GetRules() const {return rules;}
private:
std::vector<Rule> rules;
wxString name;
};
#endif