ALib C++ Library
Library Version: 2510 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 \ref mainpage_license "Boost Software License".
7//==================================================================================================
8ALIB_EXPORT namespace alib{ namespace files {
9
10/// This class implements an \ref alib_mod_expressions "ALib Expression Compiler Plugin"
11/// and thus enables "run-time expressions" to work with nodes of \alib{files;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 \alib{files;FileExpressions::Filter}, which
17/// implements the \b FFilter interface used with scan parameters of function
18/// \alib{files;ScanFiles}. 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 \ref 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 \alib{files;FTree}.
32///
33/// All identifier and function names are defined to be matched case-insensitive.
34/// Furthermore, the matchable tokens are not hard-coded but resourced with \alibcamp singleton
35/// \ref alib::FILES. With that, for example, language translations might be performed.
36///
37/// ## Types: ##
38/// <br>
39/// This plug-in introduces the following types to the expression compiler:
40/// - \alib{files;FInfo::Types}
41/// - \alib{files;FInfo::Permissions}
42/// - \alib{files;FInfo::TOwnerAndGroupID}
43///
44/// Each type is auto-cast to built-in expression type \b Integer to allow all common operators,
45/// especially bitwise boolean operators.
46///
47/// ## Constants: ##
48/// <br>
49/// Type | Name |Min. Abbreviation| Description
50/// --------------------------------|------------------|-----------------|-------------
51/// \alib{files::FInfo;Permissions} |\b OwnerRead | ore | Used test result of function \p{Permission}.
52/// \alib{files::FInfo;Permissions} |\b OwnerWrite | ow | Used test result of function \p{Permission}.
53/// \alib{files::FInfo;Permissions} |\b OwnerExecute | oe | Used test result of function \p{Permission}.
54/// \alib{files::FInfo;Permissions} |\b GroupRead | gr | Used test result of function \p{Permission}.
55/// \alib{files::FInfo;Permissions} |\b GroupWrite | gw | Used test result of function \p{Permission}.
56/// \alib{files::FInfo;Permissions} |\b GroupExecute | ge | Used test result of function \p{Permission}.
57/// \alib{files::FInfo;Permissions} |\b OthersRead | otr | Used test result of function \p{Permission}.
58/// \alib{files::FInfo;Permissions} |\b OthersWrite | otw | Used test result of function \p{Permission}.
59/// \alib{files::FInfo;Permissions} |\b OthersExecute | ote | Used test result of function \p{Permission}.
60/// \alib{files::FInfo;Types} |\b Directory | dir | Used to compare the result of function \p{Type}.
61/// \alib{files::FInfo;Types} |\b SymbolicLinkDir| sld | Used to compare the result of function \p{Type}.
62/// \alib{files::FInfo;Types} |\b Regular | reg | Used to compare the result of function \p{Type}.
63/// \alib{files::FInfo;Types} |\b SymbolicLink | sl | Used to compare the result of function \p{Type}.
64/// \alib{files::FInfo;Types} |\b Block | block | Used to compare the result of function \p{Type}.
65/// \alib{files::FInfo;Types} |\b Character | character | Used to compare the result of function \p{Type}.
66/// \alib{files::FInfo;Types} |\b Fifo | fifo | Used to compare the result of function \p{Type}.
67/// \alib{files::FInfo;Types} |\b Socket | socket | Used to compare the result of function \p{Type}.
68///
69///
70/// <br>
71/// ## Constant Constructor Functions: ##
72/// <br>
73/// Return Type| Name |Min. Abbreviation| Signature | Description |
74/// -----------|-------------|-----------------|-----------|-------------|
75/// Integer |\b KiloBytes | KB | int | Returns the given number multiplied with 2^10.
76/// Integer |\b MegaBytes | MB | int | Returns the given number multiplied with 2^20.
77/// Integer |\b GigaBytes | GB | int | Returns the given number multiplied with 2^30.
78/// Integer |\b TeraBytes | TB | int | Returns the given number multiplied with 2^40.
79/// Integer |\b PetaBytes | PB | int | Returns the given number multiplied with 2^50.
80/// Integer |\b ExaBytes | EB | int | Returns the given number multiplied with 2^60.
81///
82/// <br>
83/// ## Functions: ##
84/// <br>
85///
86/// Return Type | Name | Min. Abbreviation | Signature | Description |
87/// ----------------------------------- | ----------- | ------------------| -----------| ------------- |
88/// String | \b Name | name | ./. | Returns the file name.
89/// \alib{files::FInfo;Types} | \b Type | ty | ./. | Returns the result of \alib{files::FInfo;Type}.
90/// Boolean | \b IsDirectory | isdir | ./. | Returns the result of \alib{files::FInfo;IsDirectory}.
91/// Boolean | \b IsSymbolicLink| issl | ./. | Returns the result of \alib{files::FInfo;IsSymbolicLink}.
92/// Integer | \b Size | size | ./. | Returns the result of \alib{files::FInfo;Size}.
93/// DateTime | \b Date | timestamp | ./. | Returns the result of \alib{files::FInfo;MDate}.
94/// DateTime | \b MDate | md | ./. | Returns the result of \alib{files::FInfo;MDate}.
95/// DateTime | \b BDate | bd | ./. | Returns the result of \alib{files::FInfo;BDate}.
96/// DateTime | \b CDate | cd | ./. | Returns the result of \alib{files::FInfo;CDate}.
97/// DateTime | \b ATime | ad | ./. | Returns the result of \alib{files::FInfo;ADate}.
98/// \alib{files::FInfo;Permissions} | \b Permissions | perm | ./. | Returns the result of \alib{files::FInfo;Permissions}.
99/// \alib{files::FInfo;TOwnerAndGroupID}| \b Owner | owner | ./. | Returns the result of \alib{files::FInfo;Owner}.
100/// \alib{files::FInfo;TOwnerAndGroupID}| \b Group | group | ./. | Returns the result of \alib{files::FInfo;Group}.
101/// \alib{files::FInfo;TOwnerAndGroupID}| \b UserID | uid | ./. | Returns the current user's ID (calls posix <b>getuid()</b>).
102/// \alib{files::FInfo;TOwnerAndGroupID}| \b GroupID | gid | ./. | Returns the current user's group ID (calls posix <b>getgid()</b>).
103///
104/// \par Availability
105/// This class is available only if the module \alib_expressions is included in the \alibbuild.
107{
108 protected:
109 /// The internal compiler plug-in which adds file-related functions to the expression
110 /// compiler as documented with the outer class.
112 {
113 /// Constructor
114 /// @param compiler The compiler that this plugin will be attached to.
116 };
117
118 public:
119 class Filter;
120
121 /// The expression scope used with file expressions. Contains a \b FTree cursor and
122 /// the string of the path that the file or folder is located in.
124 {
125 friend class Filter; ///<The filter class needs casting this class to its base.
126 File Node; ///<A node of a \alib{files;FTree}.
127 system::PathString ParentPath; ///<The absolute path to the parent directory.
128
129 /// Constructor. Passes the formatter to the parent constructor.
130 /// @param formatter A reference to a \c std::shared_ptr holding a formatter.
131 /// Usually \alib{expressions;Compiler::CfgFormatter}.
132 FexScope( SPFormatter& formatter )
133 : expressions::Scope(formatter) {}
134 };
135
136 /// Implementation of abstract class \alib{files;FFilter} which uses run-time
137 /// compiled and evaluated expressions to determine the inclusion of files or directories.
138 /// Instances of this type can be created with outer classes' method
139 /// \alib{files;FileExpressions::CreateFilter} and, for example, be attached to fields
140 /// \alib{files::ScanParameters;FileFilter},
141 /// \alib{files::ScanParameters;DirectoryFilterPreRecursion} and
142 /// \alib{files::ScanParameters;DirectoryFilterPostRecursion} of class
143 /// \b ScanParameters.
144 ///
145 /// \par Availability
146 /// This class is available only if the module \alib_expressions is included in the \alibbuild.
147 class Filter : public FFilter
148 {
149 protected:
150 friend class FileExpressions; ///< The outer class is our friend.
151 FileExpressions& fex; ///< The scope used with this filter.
152 FileExpressions::FexScope scope; ///< The scope used with this filter.
153 Expression expression; ///< The compiled expression.
154
155
156 /// Protected constructor. Compiles the given expression.
157 /// To create an instance of this class, use
158 /// \alib{files;FileExpressions::CreateFilter}.
159 /// @param pFex The expression compiler to use.
160 /// @param expressionString The expression string.
162 Filter( FileExpressions& pFex, const String& expressionString );
163
164
165 public:
166 /// The filter method.
167 /// @param node The node in the file-tree to examine.
168 /// @param parentPath The absolute path to the parent directory that the file resides in.
169 /// @return The result determines, whether the given file or directory has passed the filter
170 /// or not. Consequently, \c true means "passed" and \c false means
171 /// "filtered out".
172 virtual bool Includes( const File& node, const system::PathString& parentPath) override
173 {
174 scope.Node = node;
175 scope.ParentPath = parentPath;
176 return expression->Evaluate( scope ).Unbox<bool>();
177 }
178 }; // class Filter
179
180
181 Compiler compiler; ///< The expression compiler.
182 Plugin plugin; ///< The file expression Plugin
183
184
185 /// Default constructor.
188
189 /// Creates a file filter using the expression compiler of this instance.
190 /// @param expressionString The expression string to filter files and directories.
191 /// @return A shared pointer to the dynamically allocated filter object.
193 SPFileFilter CreateFilter( const String& expressionString );
194
195}; // class FileExpressions
196
197} // namespace alib[::files]
198
199
200/// Type alias in namespace \b alib.
202
203} // namespace [alib]
FileExpressions & fex
The scope used with this filter.
friend class FileExpressions
The outer class is our friend.
Expression expression
The compiled expression.
virtual bool Includes(const File &node, const system::PathString &parentPath) override
ALIB_DLL Filter(FileExpressions &pFex, const String &expressionString)
FileExpressions::FexScope scope
The scope used with this filter.
ALIB_DLL SPFileFilter CreateFilter(const String &expressionString)
ALIB_DLL FileExpressions()
Default constructor.
Plugin plugin
The file expression Plugin.
Compiler compiler
The expression compiler.
#define ALIB_DLL
Definition alib.inl:496
#define ALIB_EXPORT
Definition alib.inl:488
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
files::FileExpressions FileExpressions
Type alias in namespace alib.
expressions::Expression Expression
Type alias in namespace alib.
containers::SharedPtr< format::Formatter > SPFormatter
Definition formatter.inl:42
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
expressions::Compiler Compiler
Type alias in namespace alib.
Definition compiler.inl:574
ALIB_DLL Scope(SPFormatter &formatter)
Definition compiler.cpp:39
system::PathString ParentPath
The absolute path to the parent directory.
friend class Filter
The filter class needs casting this class to its base.
Plugin(Compiler &compiler)
DOXYGEN.