ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
fileexpressions.inl
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of module \alib_files of the \aliblong.
4///
5/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
6/// Published under #"mainpage_license".
7//==================================================================================================
8ALIB_EXPORT namespace alib{ namespace files {
9
10/// This class implements an #"alib_mod_expressions;ALib Expression Compiler Plugin"
11/// and thus enables "run-time expressions" to work with nodes of #"FTree"
12///
13/// Unless multithreaded compilation of expressions is planned, an application should create one
14/// singleton of this class.
15///
16/// Method #"CreateFilter" creates an object of inner type #"FileExpressions::Filter;*", which
17/// implements the \b FFilter interface used with scan parameters of overloaded function
18/// #"ScanFiles(FTree&)". This allows run-time evaluation of filter rules, for example, rules
19/// coming from the command-line, from configuration files or from interactive end-user input
20/// (hence from an UX/UI).
21///
22/// Of course, the expression compiler can also be used directly without using the inner
23/// \b Filter class for evaluation, and expressions then do not need to return a boolean "yes/no"
24/// result.
25///
26/// @see
27/// For a quick tutorial, see the #"alib_mod_files;Programmer's Manual".
28///
29/// # Implemented Expression Features #
30/// %Compiler plug-in that provides expressions on filesystem entries, stored in nodes of
31/// class #"FTree".
32///
33/// All identifier and function names are defined to be matched case-insensitive and can be
34/// abbreviated along their <em>CamelHumps</em>. This means an identifier called
35///
36/// CamelHumpCounter
37///
38/// can be abbreviated to:
39///
40/// CamelHC
41/// CHCounter
42/// CamHuCo
43/// CHC
44/// chc
45/// cHc
46///
47/// and so on.
48///
49/// Furthermore, the matchable tokens are not hard-coded but resourced with \alibcamp singleton
50/// #"alib::FILES". With that, for example, language translations might be performed.
51///
52/// ## Types: ##
53/// <br>
54/// This plug-in introduces the following types to the expression compiler:
55/// - #"FInfo::Types;*"
56/// - #"FInfo::Permissions;*"
57/// - #"FInfo::TOwnerAndGroupID;*"
58///
59/// Each type is auto-cast to built-in expression type \b Integer to allow all common operators,
60/// especially bitwise boolean operators.
61///
62/// ## Constants: ##
63/// <br>
64/// Type | Name |Min. Abbreviation| Description
65/// --------------------------------|------------------|-----------------|-------------
66/// #"FInfo::Permissions" |\b OwnerRead | ore | Used test result of function \p{Permission}.
67/// #"FInfo::Permissions" |\b OwnerWrite | ow | Used test result of function \p{Permission}.
68/// #"FInfo::Permissions" |\b OwnerExecute | oe | Used test result of function \p{Permission}.
69/// #"FInfo::Permissions" |\b GroupRead | gr | Used test result of function \p{Permission}.
70/// #"FInfo::Permissions" |\b GroupWrite | gw | Used test result of function \p{Permission}.
71/// #"FInfo::Permissions" |\b GroupExecute | ge | Used test result of function \p{Permission}.
72/// #"FInfo::Permissions" |\b OthersRead | otr | Used test result of function \p{Permission}.
73/// #"FInfo::Permissions" |\b OthersWrite | otw | Used test result of function \p{Permission}.
74/// #"FInfo::Permissions" |\b OthersExecute | ote | Used test result of function \p{Permission}.
75/// #"FInfo::Types" |\b Directory | dir | Used to compare the result of function \p{Type}.
76/// #"FInfo::Types" |\b SymbolicLinkDir| sld | Used to compare the result of function \p{Type}.
77/// #"FInfo::Types" |\b Regular | reg | Used to compare the result of function \p{Type}.
78/// #"FInfo::Types" |\b SymbolicLink | sl | Used to compare the result of function \p{Type}.
79/// #"FInfo::Types" |\b Block | block | Used to compare the result of function \p{Type}.
80/// #"FInfo::Types" |\b Character | character | Used to compare the result of function \p{Type}.
81/// #"FInfo::Types" |\b Fifo | fifo | Used to compare the result of function \p{Type}.
82/// #"FInfo::Types" |\b Socket | socket | Used to compare the result of function \p{Type}.
83///
84///
85/// <br>
86/// ## Constant Constructor Functions: ##
87/// <br>
88/// Return Type| Name |Min. Abbreviation| Signature | Description |
89/// -----------|-------------|-----------------|-----------|-------------|
90/// Integer |\b KiloBytes | KB | int | Returns the given number multiplied with 2^10.
91/// Integer |\b MegaBytes | MB | int | Returns the given number multiplied with 2^20.
92/// Integer |\b GigaBytes | GB | int | Returns the given number multiplied with 2^30.
93/// Integer |\b TeraBytes | TB | int | Returns the given number multiplied with 2^40.
94/// Integer |\b PetaBytes | PB | int | Returns the given number multiplied with 2^50.
95/// Integer |\b ExaBytes | EB | int | Returns the given number multiplied with 2^60.
96///
97/// <br>
98/// ## Functions: ##
99/// <br>
100///
101/// Return Type | Name | Min. Abbreviation | Signature | Description |
102/// ----------------------------------- | ----------- | ------------------| -----------| ------------- |
103/// String | \b Name | name | ./. | Returns the file name.
104/// #"FInfo::Types" | \b Type | ty | ./. | Returns the result of #"FInfo::Type".
105/// Boolean | \b IsDirectory | isdir | ./. | Returns the result of #"FInfo::IsDirectory".
106/// Boolean | \b IsSymbolicLink| issl | ./. | Returns the result of #"FInfo::IsSymbolicLink".
107/// Integer | \b Size | size | ./. | Returns the result of #"FInfo::Size".
108/// DateTime | \b Date | timestamp | ./. | Returns the result of #"FInfo::MDate".
109/// DateTime | \b MDate | md | ./. | Returns the result of #"FInfo::MDate".
110/// DateTime | \b BDate | bd | ./. | Returns the result of #"FInfo::BDate".
111/// DateTime | \b CDate | cd | ./. | Returns the result of #"FInfo::CDate".
112/// DateTime | \b ATime | ad | ./. | Returns the result of #"FInfo::ADate".
113/// #"FInfo::Permissions" | \b Permissions | perm | ./. | Returns the result of #"FInfo::Permissions".
114/// #"FInfo::TOwnerAndGroupID"| \b Owner | owner | ./. | Returns the result of #"FInfo::Owner".
115/// #"FInfo::TOwnerAndGroupID"| \b Group | group | ./. | Returns the result of #"FInfo::Group".
116/// #"FInfo::TOwnerAndGroupID"| \b UserID | uid | ./. | Returns the current user's ID (calls posix <b>getuid()</b>).
117/// #"FInfo::TOwnerAndGroupID"| \b GroupID | gid | ./. | Returns the current user's group ID (calls posix <b>getgid()</b>).
118///
119/// \par Availability
120/// This class is available only if the module \alib_expressions is included in the \alibbuild.
122{
123 protected:
124 /// The internal compiler plug-in which adds file-related functions to the expression
125 /// compiler as documented with the outer class.
127 {
128 /// Constructor
129 /// @param compiler The compiler that this plugin will be attached to.
131 };
132
133 public:
134 class Filter;
135
136 /// The expression scope used with file expressions. Contains a \b FTree cursor and
137 /// the string of the path that the file or folder is located in.
139 {
140 #if !DOXYGEN
141 //The filter class needs casting this class to its base.
142 friend class Filter;
143 #endif
144
145 File Node; ///<A node of a #"FTree".
146 system::PathString ParentPath; ///<The absolute path to the parent directory.
147
148 /// Constructor. Passes the formatter to the parent constructor.
149 /// @param formatter A reference to a \c std::shared_ptr holding a formatter.
150 /// Usually #"Compiler::CfgFormatter;*".
151 FexScope( SPFormatter& formatter )
152 : expressions::Scope(formatter) {}
153 };
154
155 /// Implementation of abstract class #"FFilter" which uses run-time
156 /// compiled and evaluated expressions to determine the inclusion of files or directories.
157 /// Instances of this type can be created with outer classes' method
158 /// #"FileExpressions::CreateFilter;*" and, for example, be attached to fields
159 /// #"ScanParameters::FileFilter",
160 /// #"ScanParameters::DirectoryFilterPreRecursion" and
161 /// #"ScanParameters::DirectoryFilterPostRecursion" of class
162 /// \b ScanParameters.
163 ///
164 /// \par Availability
165 /// This class is available only if the module \alib_expressions is included in the \alibbuild.
166 class Filter : public FFilter
167 {
168 protected:
169 #if !DOXYGEN
170 // The outer class is our friend.
171 friend class FileExpressions;
172 #endif
173
174 FileExpressions& fex; ///< A reference to the instance that this filter
175 ///< uses.
176 FileExpressions::FexScope scope; ///< The scope used with this filter.
177 Expression expression; ///< The compiled expression.
178
179
180 /// Protected constructor. Compiles the given expression.
181 /// To create an instance of this class, use
182 /// #"FileExpressions::CreateFilter;*".
183 /// @param pFex The expression compiler to use.
184 /// @param expressionString The expression string.
186 Filter( FileExpressions& pFex, const String& expressionString );
187
188
189 public:
190 /// The filter method.
191 /// @param node The node in the file-tree to examine.
192 /// @param parentPath The absolute path to the parent directory that the file resides in.
193 /// @return The result determines, whether the given file or directory has passed the filter
194 /// or not. Consequently, \c true means "passed" and \c false means
195 /// "filtered out".
196 virtual bool Includes( const File& node, const system::PathString& parentPath) override {
197 scope.Node = node;
198 scope.ParentPath = parentPath;
199 return expression->Evaluate( scope ).Unbox<bool>();
200 }
201 }; // class Filter
202
203
204 Compiler compiler; ///< The expression compiler.
205 Plugin plugin; ///< The file expression Plugin
206
207
208 /// Default constructor.
211
212 /// Creates a file filter using the expression compiler of this instance.
213 /// @param expressionString The expression string to filter files and directories.
214 /// @return A shared pointer to the dynamically allocated filter object.
216 SPFileFilter CreateFilter( const String& expressionString );
217
218}; // class FileExpressions
219
220} // namespace alib[::files]
221
222
223/// Type alias in namespace \b alib.
225
226} // namespace [alib]
#define ALIB_DLL
Definition alib.inl:573
#define ALIB_EXPORT
Definition alib.inl:562
Expression expression
The compiled expression.
virtual bool Includes(const File &node, const system::PathString &parentPath) override
Filter(FileExpressions &pFex, const String &expressionString)
FileExpressions::FexScope scope
The scope used with this filter.
SPFileFilter CreateFilter(const String &expressionString)
FileExpressions()
Default constructor.
Plugin plugin
The file expression Plugin.
Compiler compiler
The expression compiler.
std::shared_ptr< FFilter > SPFileFilter
A shared pointer to a filter.
Definition ffilter.inl:44
strings::TString< PathCharType > PathString
The string-type used with this ALib Module.
Definition path.inl:33
containers::SharedPtr< format::Formatter > SPFormatter
Definition formatter.inl:42
expressions::Compiler Compiler
Type alias in namespace alib.
Definition compiler.inl:540
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2172
expressions::Expression Expression
Type alias in namespace alib.
files::FileExpressions FileExpressions
Type alias in namespace alib.
Scope(SPFormatter &formatter)
Definition compiler.cpp:39
system::PathString ParentPath
The absolute path to the parent directory.
Plugin(Compiler &compiler)
DOXYGEN.