ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
ftree.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
10class FTree;
11template<typename TLock> struct TSharedFTree;
12class File;
13
14/// This namespace implements internals of namespace #alib::files.
15namespace detail {
16
17struct FTreeNodeHandler;
18
19/// A shortcut to the base class of the base class of class \alib{files;FTree}.
21 FInfo,
23 Recycling::Private>;
24
25/// Specialized \ref alib_ns_containers_stringtree_referencedoc "TNodeHandler" for class
26/// \alib{files;FTree} which recycles extended information objects of type
27/// \alib{files;FInfo::EIDirectory}, \alib{files;FInfo::EISymLinkFile}, and
28/// \alib{files;FInfo::EISymLinkDir} with node deletion.
29///
30/// In respect to the node name allocation, this type behaves like
31/// default handler \alib{containers;StringTreeNamesDynamic}.
32/// In debug compilations, statistics
33/// variables \alib{containers;DBG_STATS_STRINGTREE_NAMES} and
34/// \alib{containers;DBG_STATS_STRINGTREE_NAME_OVERFLOWS} are increased, just like the original
35/// does.
37{
38 /// The character type that the \b StringTree uses for child name and path strings.
39 /// This is taken from the C++ standard library.
41
42 /// The string-type of a node's name. This is a simple static string, allocated with the
43 /// pool allocator.
45
46 /// Copies the node's name to the local string.
47 ///
48 /// @param node The node that was just created. Allows access to the key and
49 /// custom value data. While the parent and sibling nodes are likewise accessible,
50 /// it is strictly forbidden to modify those.
51 /// @param tree The instance of struct \alib{containers;detail::StringTreeBase} that invokes
52 /// this method. Any member may be accessed, including
53 /// \alib{containers::detail::StringTreeBase;nodeTable} which contains the
54 /// \alib{MonoAllocator} that the tree uses for the allocation of nodes.
55 static
56 inline
57 void InitializeNode( TTree::Node& node, TTree& tree );
58
59 /// This implementation frees any dynamically allocated memory of the node's name and in
60 /// addition recycles any extended information object attached to the \alib{files;FInfo}
61 /// object.
62 /// @param node The node that is to be removed. Allows access to the key and
63 /// custom value data. While the parent and sibling nodes are likewise accessible,
64 /// it is strictly forbidden to modify those.
65 /// @param tree The instance of struct \alib{containers;detail::StringTreeBase} that invokes
66 /// this method. Any member may be accessed, including
67 /// \alib{containers::detail::StringTreeBase;nodeTable} which contains the
68 /// \alib{MonoAllocator} that the tree uses for the allocation of nodes.
69 static
70 inline
71 void FreeNode( TTree::Node& node, TTree& tree );
72
73 /// Implements \alib{files;FTree::AllocateExtendedInfo}.
74 /// @param node The node add extended information to.
75 /// @param symLinkDest In case of symbolic link types, the symbolic link target.
76 /// @param symLinkRealPath In case of symbolic link types, the symbolic link target as real path.
78 static
80 const system::PathString& symLinkDest,
81 const system::PathString& symLinkRealPath );
82}; // struct FTreeNodeHandler
83
84} // namespace alib::files[::detail]
85
86
87//==================================================================================================
88/// Abstract virtual interface type to implement types observing changes in instances of class
89/// \alib{files;FTree}.
90/// @see Chapter \ref alib_files_monitoring of the Programmer's Manual of camp \alib_files_nl.
91//==================================================================================================
93{
94 /// The type of change that imposes the notification of a listener.
95 enum class Event
96 {
97 CreateNode, ///< A file or directory entry was created.
98 DeleteNode, ///< A file or directory entry was deleted.
99 };
100
101 /// Virtual destructor.
102 virtual ~FTreeListener() {}
103
104 /// The virtual notification method.
105 /// @param file The file or directory that was modified.
106 /// @param event The type of modification.
107 virtual void Notify( File& file, Event event ) =0;
108
109}; // struct FTreeListener
110
111
112//==================================================================================================
113/// This class builds on \alib type \alib{containers;StringTree}.
114/// The contained elements (tree nodes) are of type\alib{files;FInfo} and represent entries in
115/// filesystems.
116/// Usually the tree is filled using function \alib{files;ScanFiles}.
117///
118/// ### StringTree Interface ###
119/// Public base class \alib{containers;StringTree} provides all interfaces necessary to create and
120/// delete entries, iterate and recursively walk the file tree. Please consult its documentation
121/// for further information.
122///
123/// \note As \alib{files;ScanFiles;documented with function ScanFiles}, entities of this
124/// module \alib_files_nl exclusively store entries along their <em>"Real Path"</em>, hence
125/// always resolving symbolic links. A user of this library may deviate from this
126/// "data contract".
127///
128/// ### Class File ###
129/// The base classes' method \alib{containers;StringTree::Root} is overloaded by this class
130/// and returns an instance of class \alib{files;File} instead of an instance of class
131/// alib{containers;StringTree::Cursor}.
132/// This class can be turned into a cursor using \alib{files::File;AsCursor} and then used to
133/// navigate through the tree. Then, the cursor can be cast back (or assigned) to a \b File
134/// instance.
135///
136/// ### Monotonic Behavior ###
137/// The class fulfills \ref alib_contmono_intro_strictweak "weak monotonic allocation requirements",
138/// which is achieved by recycling not only the nodes (what base type \b StringTree does by default)
139/// but also any extended node information. This is implemented with the <b>StringTree</b>
140/// handler-type \alib{files;detail::FTreeNodeHandler} on the one hand, and on the other hand,
141/// with the implementation of the method #AllocateExtendedInfo, which has to be exclusively used
142/// to attach information structs on \b FInfo elements.<br>
143/// Furthermore, class \b File (the nodes of the tree) provides method
144/// \alib{files::File;AttachCustomData}, which likewise uses the internal pool-allocator.
145///
146/// In summary, this allows an indefinite sequence of file-scan and result filtering (deletions)
147/// with using more memory than the highest resulting fill state in such sequence requires.
148//==================================================================================================
149class FTree : public StringTree<MonoAllocator, FInfo, detail::FTreeNodeHandler>
150{
151 friend struct FTreeNodeHandler;
152
153 public:
154 /// An object pool used for recycling all sorts of allocated objects as well as the
155 /// hashtable entries.
156 /// It is \ref alib_contmono_chaining "chained" to the allocator provided with construction.
157 ///
158 /// The pool may be used in accordance with the general rules imposed by camp \alib_monomem.
159 /// If so, in multithreaded environments, this object has to be locked (in addition
160 /// to all other custom locks when interfacing this type), when using this pool from custom
161 /// code.
163
164 protected:
165 /// Type alias of this classes' base class.
167
168 friend struct detail::FTreeNodeHandler; ///< Friendship declaration.
169 friend class files::File; ///< Friendship declaration.
170
171 /// Formatting information used with \alib{files;File::Format;format methods} of associated
172 /// \b File instances.
174
175 /// A caching owner and group resolver. Used with \alib{files;File::Format;format methods}
176 /// of associated \b File instances.
178
179 /// Record used to manage registered listeners.
181 {
182 FTreeListener* listener; ///< The listener to register or dispose.
183 FTreeListener::Event event; ///< The event to listen to.
184 ConstCursorHandle file; ///< If given, the files to listen to.
185 ConstCursorHandle subTree; ///< If given, the path of files to listen to.
186 system::PathStringPA fileName; ///< If given, the file's name to listen to.
187 system::PathStringPA pathPrefix; ///< If given, the start string of the file path
188 ///< to monitor.
189 system::PathStringPA pathSubstring; ///< If given, the substring to match in the path
190 ///< (including the file name) of files to monitor.
191 };
192
193 /// The list of registered listeners.
195
196 /// Implements the various overloaded listener registration methods.
197 /// @param listener The listener to register or dispose.
198 /// @param insertOrRemove Denotes registration or disposal of a listener.
199 /// @param event The event to listen to.
200 /// @param file If given, the exported value of the file to listen to.
201 /// @param subTree If given, the exported value of the subtree of files to listen to.
202 /// @param fileName If given, the file's name to listen to.
203 /// @param pathPrefix If given, the start string of the file path to monitor.
204 /// @param pathSubstring If given, the substring to match in the path (including the file name)
205 /// of the files to monitor.
207 lang::ContainerOp insertOrRemove,
209 const File* file,
210 const StringTree::Cursor* subTree,
211 const system::PathString& fileName,
212 const system::PathString& pathPrefix,
213 const system::PathString& pathSubstring );
214
215 #if DOXYGEN
216 /// Notifies registered listeners on events.
217 /// @param event The event that occurred.
218 /// @param file The file.
219 /// @param filePath The full path of the file. Might be nulled if not available, yet.
220 /// @param lock Pointer to an (optional) \alib{threads;SharedLock}.<br>
221 /// This parameter is available (and to be passed) only if the module
222 /// \alib_threads is included in the \alibbuild.
224 File& file,
225 SharedLock* lock,
226 const system::PathString& filePath );
227 #else
229 File& file
230 IF_ALIB_THREADS( , SharedLock* lock) ,
231 const system::PathString& filePath );
232 #endif
233
234 public:
235 /// Constructor.
236 /// @param allocator The allocator to use.
238 FTree( MonoAllocator& allocator );
239
240 /// Destructor.
242 ~FTree();
243
244 /// Sort of 'overloads' method \alib{monomem;StringTree::Root}, which otherwise is accessible
245 /// via <b>operator-></b> inherited by parent class \alib{monomem;TSharedMonoVal}.
246 /// In contrast to the inherited method, this version returns an instance of type \b File.
247 /// @return A file-cursor pointing to the root node of this file tree.
248 inline
249 File Root();
250
251 /// Allocates (or recycles) an appropriate information object fitting to the type of this entry.
252 /// This method must only be applied to entries of types
253 /// - \alib{files::FInfo::Types;DIRECTORY},
254 /// - \alib{files::FInfo::Types;SYMBOLIC_LINK} or
255 /// - \alib{files::FInfo::Types;SYMBOLIC_LINK_DIR}.
256 /// In debug compilations, this is asserted. It is likewise asserted that the sybolic link
257 /// information strings are empty in case the type is \alib{files::FInfo::Types;DIRECTORY}.
258 ///
259 /// @param node The node add extended information to.
260 /// @param symLinkDest In case of symbolic link types, the symbolic link target.
261 /// @param symLinkRealPath In case of symbolic link types, the symbolic link target as real
262 /// path.
264 const system::PathString& symLinkDest,
265 const system::PathString& symLinkRealPath)
266 { detail::FTreeNodeHandler::AllocateExtendedInfo( node, symLinkDest, symLinkRealPath); }
267
268 /// Deletes all custom data objects attached to any \b File in this tree.<br>
269 /// Note that this method is only applicable if all custom data objects set in any node
270 /// of this tree share the same type \p{TCustom}.
271 /// With debug-compilations this is asserted.
272 ///
273 /// @see Method \alib{files;File::AttachCustomData}.
274 /// @tparam TCustom The object type to optionally store in tree nodes.
275 template<typename TCustom>
277 for( auto& node : nodeTable ) {
278 if( node.data.custom ) {
279 ALIB_ASSERT_ERROR( &typeid(TCustom) == node.data.dbgCustomType, "FILES",
280 "CustomData to delete does not match attached type.\n"
281 "Deletion has to be performed individually by this software.\n"
282 "This method must only be used if all tree nodes have the same custom data "
283 "attached\n"
284 " Attached type: <{}>\n"
285 " Given type: <{}>" , &typeid(TCustom), node.data.dbgCustomType )
286
287 reinterpret_cast<TCustom*>( node.data.custom ) -> ~TCustom();
288 Pool.free( node.data.custom, sizeof(TCustom) );
289 node.data.custom= nullptr;
290 ALIB_DBG( node.data.dbgCustomType= nullptr; )
291 } } }
292
293 /// Recalculates the sums of the given node. This is \b not done recursively. The fix is needed
294 /// when scanning an existent directory with potentially more greedy scan parameters.
295 /// @param directory The directory to re-calculate the sums for.
297 static
298 void FixSums(Cursor directory);
299
300 /// Retrieves formatting flags which are used with method \alib{files;File::Format}.
301 /// @return Number formatting information for \b File objects associated with this file tree.
303
304 /// Retrieves formatting flags which are used with method \alib{files;File::Format}.
305 /// @return Number formatting information for \b File objects associated with this file tree.
307
308 //===================================== Listener Registration ====================================
309
310
311 #if DOXYGEN
312 /// Notifies registered listeners on events.
313 /// @param event The event that occurred.
314 /// @param file The file.
315 /// @param lock Pointer to an (optional) \alib{threads;SharedLock}.
316 /// Has to be given only if multithreaded access is performed.
317 /// If the \p{filePath} is nulled, method
318 /// \alib{threads::SharedLock;AcquireShared} will be called.<br>
319 /// This parameter is available (and to be passed) only if the module
320 /// \alib_threads is included in the \alibbuild.
321 /// @param filePath The full path of the file. Might be nulled if not available to the caller.
322 /// In this case it is internally created.<br>
323 /// Defaults to \alib{NULL_STRING}.
325 File& file ,
326 SharedLock* lock ,
327 const String& filePath= NULL_STRING );
328 #else
329 void Notify( FTreeListener::Event event,
330 File& file
331IF_ALIB_THREADS( , SharedLock* lock) ,
332 const system::PathString& filePath= system::NULL_PATH )
333 { if (HasListeners()) notifyListeners(event, file IF_ALIB_THREADS(,lock), filePath); }
334 #endif
335
336 /// @return \c true if listeners are registered with this file tree, \c false otherwise
337 bool HasListeners() { return listeners.size() > 0; }
338
339 /// Inserts or removes a listener to a specific file.
340 /// @param insertOrRemove Denotes whether the listener should be inserted or removed.
341 /// (Only enum elements \b ContainerOp::Insert or \b ContainerOp::Remove
342 /// must be passed.)
343 /// @param listener The listener to register.
344 /// @param event The event to listen to.
345 /// @param file The file to listen to.
346 /// @see Chapter \ref alib_files_monitoring of the Programmer's Manual of camp \alib_files_nl.
348 FTreeListener* listener,
350 const File& file ) {
352 "Event::Creation will never be invoked with this listener-registration-type." )
353 registerListener( listener,
354 insertOrRemove,
355 event,
356 &file, nullptr,
360 }
361
362 /// Inserts or removes a listener for all files that share the given \p{fileName}.
363 /// @param insertOrRemove Denotes whether the listener should be inserted or removed.
364 /// (Only enum elements \b ContainerOp::Insert or \b ContainerOp::Remove
365 /// must be passed.)
366 /// @param listener The listener to register.
367 /// @param event The event to listen to.
368 /// @param fileName The name of one or more files to listen to.
369 /// @see Chapter \ref alib_files_monitoring of the Programmer's Manual of camp \alib_files_nl.
371 FTreeListener* listener,
373 const system::PathString& fileName ) {
374 ALIB_ASSERT_ERROR( fileName.IsNotEmpty(), "VARIABLES", "Empty file name given." )
375 registerListener( listener, insertOrRemove, event,
376 nullptr, nullptr, fileName,
378 }
379
380
381 /// Inserts or removes a listener for all files below the subtree specified by the
382 /// given \p{cursor}.
383 /// @param insertOrRemove Denotes whether the listener should be inserted or removed.
384 /// (Only enum elements \b ContainerOp::Insert or \b ContainerOp::Remove
385 /// must be passed.)
386 /// @param listener The listener to register.
387 /// @param event The event to listen to.
388 /// @param cursor The parent node in the tree of files to monitor.
389 /// @see Chapter \ref alib_files_monitoring of the Programmer's Manual of camp \alib_files_nl.
390 void MonitorPath( lang::ContainerOp insertOrRemove,
391 FTreeListener* listener,
393 const FTree::Cursor& cursor ) {
394 registerListener( listener,
395 insertOrRemove,
396 event,
397 nullptr, &cursor,
401 }
402
403
404
405 /// Inserts or removes a listener for all files below the subtree specified by the
406 /// given \p{startPath}.
407 /// \attention Note that the parameter \p{pathPrefix} has to be a portion of a
408 /// \alib{system;Path::MakeReal;real path}.
409 /// @param insertOrRemove Denotes whether the listener should be inserted or removed.
410 /// (Only enum elements \b ContainerOp::Insert or \b ContainerOp::Remove
411 /// must be passed.)
412 /// @param listener The listener to register.
413 /// @param event The event to listen to.
414 /// @param pathPrefix The path prefix of the subtree of files to monitor. Note that a
415 /// missing leading separator character will be added.
416 /// @see Chapter \ref alib_files_monitoring of the Programmer's Manual of camp \alib_files_nl.
418 FTreeListener* listener,
420 const system::PathString& pathPrefix ) {
421 ALIB_ASSERT_ERROR( pathPrefix.IsNotEmpty(), "VARIABLES", "Empty path prefix given." )
422 registerListener( listener,
423 insertOrRemove,
424 event,
425 nullptr, nullptr,
427 }
428
429 /// Inserts or removes a listener for all files whose path (excluding the file name) contains
430 /// the given \p{pathSubstring}.
431 /// \attention Note that the parameter \p{pathSubstring} has to be a portion of a
432 /// \alib{system;Path::MakeReal;real path}.
433 /// @param insertOrRemove Denotes whether the listener should be inserted or removed.
434 /// (Only enum elements \b ContainerOp::Insert or \b ContainerOp::Remove
435 /// must be passed.)
436 /// @param listener The listener to register.
437 /// @param event The event to listen to.
438 /// @param pathSubstring The substring to match in the path (including the file name)
439 /// of the files to monitor.
440 /// @see Chapter \ref alib_files_monitoring of the Programmer's Manual of camp \alib_files_nl.
442 FTreeListener* listener,
444 const system::PathString& pathSubstring ) {
445 ALIB_ASSERT_ERROR( pathSubstring.IsNotEmpty(), "VARIABLES", "Empty path substring given." )
446 registerListener( listener,
447 insertOrRemove,
448 event,
449 nullptr, nullptr,
451 pathSubstring );
452 }
453
454 /// Removes all registrations of the given listener.
455 /// @param listener The listener to remove.
456 /// @return The number of registrations that have been removed.
457 /// @see Chapter \ref alib_files_monitoring of the Programmer's Manual of camp \alib_files_nl.
459 int MonitorStop( FTreeListener* listener );
460}; // FTree
461
462
463/// Utility type which implements \alib{monomem;TSharedMonoVal} with class \alib{files;FTree}.
464/// The result of combining both is an automatic pointer to a \b %FTree that is "self-contained"
465/// in the first buffer of a \alib{MonoAllocator} together with the allocator itself.
466/// The tree is deleted and all associated memory is freed when the last copy of the pointer
467/// goes out of scope.
468///
469/// Along with the \b FTree, this shared object includes a \alib{threads;SharedLock}.
470/// See chapter \ref alib_contmono_smv_locking of the Programmer's Manual of module \alib_monomem
471/// for further information on how to protect the contents of this type against
472/// thread-racing-conditions.
473///
474/// @tparam TLock The lock type passed to the template parameter of parent type
475/// \alib{monomem;TSharedMonoVal} with the same name.<br>
476/// With the inclusion of module \alib_threads in the \alibbuild, the type-alias
477/// #alib::SharedFTree chooses type \alib{threads;SharedLock}.<br>
478/// Otherwise, in case \alib is compiled without threading support, the alias chooses
479/// <c>void</c>.<br>
480/// If it is assured that no racing-conditions occur with shared instances in
481/// multithreaded software, the using code may pass <c>void</c> here as well.
482template<typename TLock>
483struct TSharedFTree : monomem::TSharedMonoVal<FTree, HeapAllocator, TLock>
484{
485 /// Exposed shortcut to the base type.
487
488 /// Constructs an empty instance, hence a cleared automatic pointer.
489 TSharedFTree() =default;
490
491 /// Constructs an empty instance from \c std::nullptr.
492 /// This constructor is necessary to allow assignment of \c nullptr to values of this type,
493 /// which clears the automatic pointer.
494 TSharedFTree(std::nullptr_t) noexcept {}
495
496 /// Constructor.
497 /// Calls the constructor of parent \b TSharedMonoVal and then invokes
498 /// \alib{monomem;TSharedMonoVal::ConstructT} passing the mono allocator that the
499 /// parent creates this instance in.<br>
500 /// Furthermore calls DbgCriticalSections to enable assertions to locked usage.
501 /// @param initialBufferSizeInKB The initial size of memory buffers.
502 /// Passed to the allocator given with parent class
503 /// \alib{monomem;TSharedMonoVal}.
504 /// @param bufferGrowthInPercent Optional growth factor in percent, applied to the buffer size
505 /// with each next buffer allocation.
506 /// Passed to the allocator given with parent class
507 /// \alib{monomem;TSharedMonoVal}.
508 /// Should be set to \c 200, to double the size with each
509 /// allocation.
510 /// Defaults to \c 200.
511 TSharedFTree( size_t initialBufferSizeInKB,
512 unsigned bufferGrowthInPercent = 200 )
513 : Base(initialBufferSizeInKB, bufferGrowthInPercent) {
516 ALIB_DBG(Base::GetAllocator().DbgName= "SharedFTree";)
517 }
518
519 /// Defaulted copy-assignment operator.
520 /// @return A reference to <c>this</c>.
522
523 /// Destructor.
524 /// Calls #DbgCriticalSections to stop checking the integrated \p{TLock}.
526
527 #if DOXYGEN
528 /// Enables or disables critical section checks between the contained \p{T} and the likewise
529 /// contained \p{TLock}.<br>
530 /// In case \p{TLock} equals <c>void</c> or if symbol \ref ALIB_DEBUG_CRITICAL_SECTIONS is not
531 /// set, this method is empty (and its use is optimized out).
532 /// @param onOff The switch.
534 #else
535 template<typename TRequires= typename Base::LockType>
536 requires( !std::same_as<TRequires, void> )
538 #if ALIB_DEBUG_CRITICAL_SECTIONS
539 if ( !Base::IsNulled() ) {
540 if( onOff == lang::Switch::On ) {
541 Base::Self().NodeTable().dcs .DCSLock= &Base::GetLock();
544 }
545 else {
546 Base::Self().NodeTable().dcs .DCSLock= nullptr;
547 Base::GetAllocator().DbgCriticalSectionsPH.Get()->DCSLock= nullptr;
548 Base::Self().Pool .DCSLock= nullptr;
549 } }
550 #else
551 (void) onOff;
552 #endif
553 }
554
555 template<typename TRequires= typename Base::LockType>
556 requires std::same_as<TRequires, void>
558 #endif
559
560 /// Clears all scanned or otherwise inserted data and re-initializes this object to its
561 /// constructor defaults and resets the \b MonoAllocator of the parent class.<br>
562 ///
563 /// All shared instances remain valid (while, of course, their content is likewise reset).
564 void Reset() {
565 // just invoke parent's reset method passing the mono allocator to the constructor.
569 }
570
571}; // struct TSharedFTree
572
573//==================================================================================================
574//================================ Implementation of the node mainer ===============================
575//==================================================================================================
576#if !DOXYGEN
578
579void detail::FTreeNodeHandler::InitializeNode( TTree::Node& node, TTree& tree )
580{ node.name.storage.Allocate( static_cast<FTree&>(tree).Pool, node.name.key ); }
581
582void detail::FTreeNodeHandler::FreeNode( TTree::Node& node, TTree& tree ) {
583 // delete node name
584 auto& pool= static_cast<FTree&>(tree).Pool;
585
586 if ( node.name.storage.Length() )
587 pool.free( const_cast<TTree::CharacterType*>(node.name.storage.Buffer()),
588 size_t(node.name.storage.Length()) * sizeof(TTree::CharacterType) );
589
590 // recycle extended info structs
591 FInfo& value= node.data;
592 auto extendedInfo= value.GetExtendedInfo();
593 if( extendedInfo == nullptr )
594 return;
595
596 if( value.IsSymbolicLink() ) {
597 // delete old values
598 FInfo::EISymLinkFile& ei= *static_cast<FInfo::EISymLinkFile*>(extendedInfo);
599
600 if( ei.RealTarget.Buffer() != ei.Target.Buffer()
601 && ei.RealTarget.Buffer() != nullptr )
602 pool().Free( ei.RealTarget.Buffer(), ei.RealTarget.Length() + 1 );
603
604 if( ei.Target.Buffer() != nullptr )
605 pool().Free( ei.Target.Buffer(), ei.Target.Length() + 1 );
606
607 if( value.Type() == FInfo::Types::SYMBOLIC_LINK )
608 pool().Delete( static_cast<FInfo::EISymLinkFile*>(extendedInfo) );
609 else
610 pool().Delete( static_cast<FInfo::EISymLinkDir*>(extendedInfo) );
611
612 // clear to be able to check double use in debug mode
613 ALIB_DBG( value.SetExtendedInfo(nullptr) );
614 return;
615 }
616
618 "FILES", "Given node is not a directory or symbolic link but still has extendedInfo set." )
619
620 pool().Delete( reinterpret_cast<FInfo::EIDirectory*>(extendedInfo) );
621
622 // clear to be able to check double use in debug mode
623 ALIB_DBG( value.SetExtendedInfo(nullptr) );
624}
625#include "ALib.Lang.CIMethods.H"
626#endif
627
628
629//==================================================================================================
630/// This class represents nodes in \alib{files;FTree} instances.
631/// While class \b FTree is just a rather small wrapper around its base class
632/// \alib{containers;StringTree}, this class \b File is a wrapper around class
633/// \alib{containers;StringTree::Cursor}.
634/// With that, instances of this class are very lightweight and contain only two pointers: One
635/// pointing to the \b %FTree that an instance originates from, the second pointing to the
636/// node in the tree.
637///
638/// It is important to understand that this class has three interfaces.
639/// 1. The direct interface as exposed with this class.
640/// 2. Using <c>operator-></c> the attached data instance of type \alib{files;FInfo} is accessed.
641/// 3. The method #AsCursor casts an instance to the (otherwise protected) type \b Cursor of the
642/// underlying string tree.
643///
644/// To get a thorough understanding of why this split exists and what purpose which of the
645/// three interfaces serve, a basic understanding of container type class
646/// \alib{containers;StringTree} is very helpful.
647/// A similar design principle is implemented with class \alib{variables;Variable} of module
648/// \alib_variables. A technical explanation to why base class <b>FTree::Cursor</b> is protected
649/// there in the same fashion is \alib{variables;Variable::AsCursor;given here}.
650///
651/// @see
652/// - For a quick tutorial about using \alib files, consult the tutorial-style
653/// \ref alib_mod_files "Programmer's Manual" of camp \alib_files_nl.
654/// - For this class, a \ref alibtools_debug_helpers_gdb "pretty printer" for the
655/// GNU debugger is provided.
656/// - Instances of this type are \ref alib_strings_assembly_ttostring "appendable" to
657/// class \b %AString. If done, the full path and file name is written to the target string.
658//==================================================================================================
659class File : protected FTree::Cursor
660{
661 public:
662 /// The base cursor type of the internal \b StringTree. This type is used to perform
663 /// cursor operations on \b FTree instances.
665
666 /// The constant version of type #Cursor.
668
669
670 /// Returns a \c reference to the file tree that this file resides in.
671 /// @return The associated file tree instance.
672 FTree& GetFTree() const { return static_cast<FTree&>(Tree()); }
673
674 File() =default;
675
676 /// Constructor taking a file tree. After construction, this file will point to the root
677 /// node <c>"/"</c> of the tree.
678 /// @param pTree The tree to associate this file instance with.
679 File( FTree& pTree )
680 : Cursor( pTree.Root() ) {}
681
682 /// Constructs an instance of this type from its base type.
683 /// This constructor is for advanced use when direct operations with class \b StringTree and
684 /// its cursor and iterator types are performed.
685 /// @param cursor The \b StringTree cursor representing a file.
686 File( const Cursor& cursor )
687 : Cursor(cursor) {}
688
689 /// Sets this \b Cursor to point to the same file (node in the \alib{files;FTree}) as the given
690 /// \p{other}.
691 /// @param other The node to let this file instance point to.
692 /// @return A reference to \c this.
693 File& operator=( const Cursor& other ) { Cursor::operator=( other ); return *this; }
694
695 /// Provides \c const access to members of contained \alib{files;FInfo} record. Note that
696 /// access to a mutable version of the type is available with method #GetMutableFInfo.
697 /// @return A non-writable pointer to the embedded \b FInfo data.
698 const FInfo* operator->() const { return Cursor::operator->(); }
699
700 /// Provides \c access to members of contained \alib{files;FInfo} record. Note that
701 /// \c const access is available with method #operator->.<br>
702 /// Changes to the values should be done with caution. Usually the values are only set when
703 /// scanning files or using certain interface methods of this class.
704 /// @return A \b writable pointer to the embedded \b FInfo data.
705 FInfo& GetMutableFInfo() { return Value(); }
706
707 /// This is an explicit <c>cast operator</c> to the protected base class.
708 /// \note For details on the code design which makes this method necessary, consult the
709 /// documentation of the same concept found with method \alib{variables;Variable::AsCursor}.
710 /// @return This instance cast 'down' to its protected base class.
711 Cursor& AsCursor() { return static_cast<Cursor&>(*this); }
712
713 /// \c const version of the <c>cast operator</c> to the protected base class.
714 /// @return This instance cast 'down' to its protected base class.
715 const Cursor& AsCursor() const { return static_cast<const Cursor&>(*this); }
716
717
719 /// Publish protected method
720 /// \doxlinkproblem{classalib_1_1containers_1_1StringTree_1_1TCursor.html;a58dad13c22c77ff79290aa72770b06ce;StringTree::TCursor::Name}.
721 /// @return A constant reference to the name of the represented node.
722 using Cursor::Name;
724
725 /// Returns the substring from the beginning of \b %Name() up to (and not including) the last
726 /// period <c>'.'</c> character which is not located at the start of the name.
727 /// With that, edge cases are treated as follows:
728 /// - A filename like "filename.ext.txt" -> "filename.ext"
729 /// - A filename like ".profile" results to identity ".profile".
730 /// @return The filename excluding the #Extension.
732 system::PathString result= Name();
733 auto dotPos= result.LastIndexOf('.');
734 return dotPos < 2 ? result
735 : result.Substring( 0, dotPos );
736 }
737
738 /// Returns the file extension, which is the substring behind the last period <c>'.'</c>
739 /// character which is not located at the start of the name.
740 /// (A filename like ".profile" is not treated to have an extension).
741 /// @return The extension found in the filename. An empty string if none is found.
743 auto dotPos= Name().LastIndexOf('.');
744 return dotPos < 2 ? system::EMPTY_PATH
745 : Name().Substring( dotPos + 1 );
746 }
747
748 /// Returns the path to this file. This excludes this files' name as well as a trailing
749 /// separation character. If this file represents the root folder of the file tree,
750 /// nothing is written to \p{target}.
751 ///
752 /// @see To receive the full path of this file, including this %files' name, use
753 /// #AsCursor and invoke
754 /// \doxlinkproblem{classalib_1_1containers_1_1StringTree_1_1TCursor.html;a095127b50447399e888b0d382e82014d;Cursor::AssemblePath}.
755
756 /// @param target The string buffer to append the path to.
757 /// @param targetData Denotes whether \p{target} should be cleared before
758 /// appending the path. Defaults to \b CurrentData::Clear.
759 /// @return The given \b AString to allow concatenated operations.
762 if( targetData == lang::CurrentData::Clear )
763 target.Reset();
764 if( !AsCursor().IsRoot() )
765 AsCursor().Parent().AssemblePath(target, lang::CurrentData::Keep);
766 return target;
767 }
768
769 /// Retrieves the file's owner's name.
770 /// @return The name of the owner of the file.
771 const NString& GetOwnerName() const { return GetFTree().GetOGResolver().GetOwnerName(Value());}
772
773 /// Retrieves the file's group name.
774 /// @return The name of the group of the file.
775 const NString& GetGroupName() const { return GetFTree().GetOGResolver().GetGroupName(Value());}
776
777 /// Tests if custom data is attached to this file.
778 /// @see Methods #AttachCustomData, #GetCustomData, #DeleteCustomData, and
779 /// \alib{files;FTree::DeleteAllCustomData}.
780 /// @return <c>true</c> if custom data is attached to this file, <c>false</c> otherwise.
781 bool HasCustomData() const { return Value().custom != nullptr; }
782
783 /// Retrieves a custom data object.
784 /// With debug-compilations it is asserted that #HasCustomData() returns <c>true</c>
785 /// and that \p{TCustom} is the same as set.
786 /// @tparam TCustom The type of custom data requested. In case no data was previously attached,
787 /// yet, the constructor of this type is called on the new allocated memory.
788 /// @see Methods #AttachCustomData, #HasCustomData, #DeleteCustomData, and
789 /// \alib{files;FTree::DeleteAllCustomData}.
790 /// @return The custom data record.
791 template<typename TCustom>
792 TCustom& GetCustomData() {
793 ALIB_ASSERT_ERROR( Value().custom != nullptr, "FILES", "No custom data set." )
794 ALIB_ASSERT_ERROR( &typeid(TCustom) == Value().dbgCustomType, "FILES",
795 "Requested custom object type mismatch.\n"
796 " Attached type: <{}>\n"
797 " Given type: <{}>" , &typeid(TCustom), Value().dbgCustomType )
798
799 return *reinterpret_cast<TCustom*>( Value().custom );
800 }
801
802 /// Allocates a custom object attached to this file using the
803 /// \alib{monomem;TPoolAllocator;PoolAllocator} of the \b FTree.
804 ///
805 /// @see Methods #GetCustomData, #HasCustomData, #DeleteCustomData, and
806 /// \alib{files;FTree::DeleteAllCustomData}.
807 /// @tparam TCustom The type of custom data associated to the \b FTree that this file belongs
808 /// to.
809 /// @tparam TArgs Types of the variadic arguments \p{args} that construct \p{TCustom}.
810 /// @param args Variadic arguments forwarded to the constructor of \p{TCustom}.
811 /// @return The custom data record.
812 template<typename TCustom, typename... TArgs>
813 TCustom& AttachCustomData(TArgs&&... args) {
814 ALIB_ASSERT_ERROR( Value().custom == nullptr, "FILES", "Custom data already set." )
815
816 auto* custom= GetFTree().Pool().template New<TCustom>( std::forward<TArgs>(args)... );
817 Value().custom= custom;
818 ALIB_DBG(Value().dbgCustomType= &typeid(TCustom); )
819 return *custom;
820 }
821
822 /// Destructs and deletes the custom data attached to this file.
823 /// With debug-compilations it is asserted that #HasCustomData() returns <c>true</c>
824 /// and that \p{TCustom} is the same as set.
825 /// @see Methods #AttachCustomData, #GetCustomData, #HasCustomData, and
826 /// \alib{files;FTree::DeleteAllCustomData}.
827 /// @tparam TCustom The object type to optionally store in tree nodes.
828 template<typename TCustom>
831 GetFTree().Pool.free( Value().custom, sizeof(TCustom) );
832 Value().custom= nullptr;
833 }
834
835 /// Writes the permission flags to the given \p{target} string in the
836 /// same format as GNU/Linux command <em>'ls -l'</em> does.
837 /// @param target The target string to write into.
838 /// @return The given target to allow concatenated calls.
839 AString& FormatAccessRights(AString& target) const;
840
841
842 /// Writes formatted information on this file to given string buffer \p{target}.
843 /// Within the pattern string \p{format}, different symbols are interpreted as tokens.
844 /// Spaces between tokens are written as given.
845 /// Strings within the format text that should not be interpreted as tokens may be given
846 /// in single quotes.
847 /// Two consecutive single quotes will be replaced to one single quote.<br>
848 ///
849 /// Tokens are defined in lower case letters.
850 /// If given with upper case letters, the generated string is converted to upper case letters.
851 ///
852 /// This method supports the following tokens:
853 ///
854 /// <center>Token</center> | <center>Description</center>
855 /// - - - - - - - - - - - - | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
856 /// a |Invokes #FormatAccessRights.</TD> </TR>
857 /// dm{DATEFORMAT}|The \alib{files::FInfo;MDate;modification date} of this file. This token is optionally followed by a "DATEFORMAT" string given in curly braces. For specification information, see \alib{format;CalendarDateTime::Format}.</TD> </TR>
858 /// db{DATEFORMAT}|Same as 'dm', but uses the \alib{files::FInfo;BDate;creation date} of this file.</TD> </TR>
859 /// dc{DATEFORMAT}|Same as 'dm', but uses the \alib{files::FInfo;CDate;change date} of this file.</TD> </TR>
860 /// da{DATEFORMAT}|Same as 'dm', but uses the \alib{files::FInfo;ADate;date of last access} to this file.</TD> </TR>
861 /// fx |Prints <c>'m'</c> if \alib{files::FInfo;IsCrossingFS} returns \c true, <c>'-'</c> otherwise.
862 /// fa |Prints <c>'a'</c> if \alib{files::FInfo;IsArtificialFS} returns \c true, <c>'-'</c> otherwise.
863 /// gi[{width[,alignment]}] |The ID of the user group of the file.
864 /// gn[{width[,alignment]}] |The name of the user group of the file.
865 /// h |The \alib{files::FInfo;QtyHardLinks;number of hard links} pointing to this file.</TD> </TR>
866 /// l |In case of Symbolic links, prints " -> linktarget". if the linktarget is a relative path, then the absolute path is appended in round brackets.</TD> </TR>
867 /// na |The name of the file.</TD> </TR>
868 /// ns |The \alib{files::File;Stem;stem} of the file.</TD> </TR>
869 /// ne |The \alib{files::File;Extension;extension} of the file.</TD> </TR>
870 /// np |The \alib{files::File;Path;path} to the file, excluding the file name and a trailing separation character.</TD> </TR>
871 /// oi[{width[,alignment]}] |The ID of the owner of the file.
872 /// on[{width[,alignment]}] |The name of the owner of the file.
873 /// q |The scan \alib{files::FInfo;Quality;quality} as resourced with enum \alib{files::FInfo;Qualities}.</TD> </TR>
874 /// rd |Recursively counted subfolders.</TD> </TR>
875 /// rf |Recursively counted files.</TD> </TR>
876 /// re |Recursively counted access errors.</TD> </TR>
877 /// rb |Recursively counted broken links.</TD> </TR>
878 /// qqq |The scan \alib{files::FInfo;Quality;quality}, encoded in three characters. The conversion is resourced with enum \alib{files::FInfo;Qualities3Letters}.</TD> </TR>
879 /// s[{unit}] |The size of the file. See the explanation below.</TD> </TR>
880 /// t |The \alib{files::FInfo;Type;type}, encoded in a single character. The conversion is resourced with enum \alib{files::FInfo;TypeNames1Letter}.</TD> </TR>
881 /// tt |The \alib{files::FInfo;Type;type}, encoded in two characters. The conversion is resourced with enum \alib{files::FInfo;TypeNames2Letters}.</TD> </TR>
882 /// ttt |The \alib{files::FInfo;Type;type}, encoded in three characters. The conversion is resourced with enum \alib{files::FInfo;TypeNames3Letters}.</TD> </TR>
883 /// tttt |The \alib{files::FInfo;Type;type}, as a full word. The conversion is resourced with enum \alib{files::FInfo;Types}.</TD> </TR>
884 ///
885 /// \par Fields and Alignment
886 /// Any of the tokens above may be followd by <b>{width[,Alignment]}</b>. In words:
887 /// a pair of curly braces that contains an integral value specifying a field width
888 /// and, optionally and seperated by a comma, an \alib{lang;Alignment,alignment} specifier.
889 /// If so, a corresponding field, using spaces as padding character, is printed.
890 ///
891 /// \par Printing sizes:
892 /// Token <c>"s[(unit)]"</c> is used to print file sizes.
893 /// The optional unit string in curly braces may have one the following values:
894 /// - <c>IEC</c>: Chooses \alib{format;ByteSizeIEC;IEC standard} with automatic
895 /// detection of an approiate magnitude. The unit of the magnitude found (<c>"B"</c>,
896 /// <c>"KiB"</c>, <c>"MiB"</c>, <c>"GiB"</c>,...) is added to the output.
897 /// This is the default, if the optional unit-partis omited.
898 /// - <c>SI</c>: Chooses \alib{format;ByteSizeSI;SI standard} with automatic
899 /// detection of an approiate magnitude. The unit of the magnitude found (<c>"B"</c>,
900 /// <c>"kB"</c>, <c>"MB"</c>, <c>"GB"</c>,...) is added to the output.
901 /// - One of the more than 20 possible entity names of either IEC or SI standard.
902 /// In this case, the unit is \b not included after the number, because this way it can be
903 /// optionally added to the format string by using a pair of single quotes <c>'</c>.
904 /// \par
905 /// With the two automatic modes <c>IEC</c> and <c>SI</c>, namespace function
906 /// \alib{format::FormatByteSize} is used.<br>
907 ///
908 /// \par
909 /// For formatting the file size numbers, this method retrieves formatting hints with
910 /// \alib{files;FTree::GetNumberFormat}. With that, the details of the format can
911 /// be specified "per FTree". Manipulations of this object before invoking this methods,
912 /// allows specifying output widths, group characters, decimal separation character, and so
913 /// forth.
914 ///
915 ///
916 /// \par Printing owner and group:
917 /// For printing owner and group names, those have to be queried from the OS.
918 /// To increase performance, the resolver utility instance received with
919 /// \alib{files;FTree::GetOGResolver} is used. The use of this instance has to be protected
920 /// against racing conditions in multithreaded applications. This means if two threads
921 /// invoke this method on \b %File object that belong to the same \b %FTree, a locking
922 /// mechanism has to be used, to avoid undefined behavior. (For example, by using class
923 /// \alib{threads;Lock}.)
924 ///
925 /// \par Sample
926 /// As a sample, the following format string mimics the output of GNU/Linux console command
927 /// <em>ls -l</em>:
928 ///
929 /// "ta h on gn s dm nal"
930 ///
931 /// @see This method is invoked by \alib{files;FFormat_File}, which is an implementation of
932 /// box-function \alib{format;FFormat}. With hat, objects of this type can be used
933 /// as arguments for \alib{format;FormatterPythonStyle}.
934 /// The format specifier passed to this method has to be placed behind the colon
935 /// in the placeholder field, as in <c>"{:FORMATSPEC}"</c>.
936 /// If no format string is given in the placeholder, the string
937 /// <b>"ta h on gn s dm nal"</b> is used, which is resourced in camp
938 /// \alib{FILES} under key <b>"FFMT"</b>.
939 ///
940 ///
941 /// @param format The format pattern string.
942 /// @param target A reference to an AString that gets the result of the format processing
943 /// appended.
944 /// @param targetData If \c CurrentData::Keep (the default) the string is appended to \p{target}.
945 /// if \c CurrentData::Clear, \p{target} is cleared.
946 /// @param numberFormat The number format specification to use. Defaults to \c nullptr which
947 /// chooses \alib{format;NumberFormat::Computational}.
948 /// @returns \p{target} (for convenience).
950 AString& Format( Substring format,
951 AString& target,
953 NumberFormat* numberFormat = nullptr ) const;
954
955}; // class File
956
957//==================================================================================================
958//============================= Implementation of inlines of class FTree ===========================
959//==================================================================================================
960File FTree::Root() { return File( base::Root() ); }
961
962//==================================================================================================
963//==================================== Box-function FFormat_File ===================================
964//==================================================================================================
965/// This implementation of boxing function \b FFormat for objects of type \b File, simply
966/// invokes the method \alib{files;File::Format} and thus, using the format specification is given
967/// with that method.
968///
969/// Note that the \alib{strings;TNumberFormat;NumberFormat} instance used for formatting file sizes
970/// and similar, does not use the instance given with parameter \p{nf}. Instead, the instance
971/// retrieved with \alib{files;FTree::GetNumberFormat} is used. This feature enables to
972/// determine the number format separately for file data output, independent of the settings the
973/// formater uses.
974///
975/// If the parameter \p{formatSpec} is empty, the string <b>"ta h on gn s dm nal"</b> is used,
976/// which is resourced in camp \alib{FILES} under the key <b>"FFMT"</b>.
977///
978/// @param box The box containing the file object.
979/// @param formatSpec The format string.
980/// @param nf The number format specification to use.
981/// @param target The target string to write to.
982void FFormat_File( const Box& box, const String& formatSpec, NumberFormat& nf, AString& target );
983
984} // namespace alib[::files]
985
986/// Type alias in namespace \b alib.
988
989#if !ALIB_SINGLE_THREADED || DOXYGEN
990DOX_MARKER([DOX_MANUAL_ALIASES_FTREE])
991/// Type alias in namespace \b alib.
992using SharedFTree= files::TSharedFTree<SharedLock>;
993DOX_MARKER([DOX_MANUAL_ALIASES_FTREE])
994#else
996#endif
997
998/// Type alias in namespace \b alib.
1000
1001} // namespace [alib]
1002
1003
1004//##################################################################################################
1005// struct AppendableTraits<Cursor>
1006//##################################################################################################
1007
1008// Faking all template specializations of namespace strings for doxygen into namespace
1009// strings::APPENDABLES to keep the documentation of namespace string clean!
1010namespace alib::strings {
1011#if DOXYGEN
1012namespace APPENDABLES {
1013#endif
1014
1015/// Specialization of functor \alib{strings;AppendableTraits} for type \alib{files;File}.
1017{
1018 /// Writes the file's complete path (including the filename) to the given AString.
1019 /// @param target The \b NAString that \b Append was invoked on.
1020 /// @param file The file.
1022};
1023
1024/// Specialization of functor \alib{strings;AppendableTraits} for type \alib{files;File}.
1026{
1027 /// Writes the file's complete path (including the filename) to the given AString.
1028 /// @param target The \b WAString that \b Append was invoked on.
1029 /// @param file The file.
1031};
1032
1033#if DOXYGEN
1034} // namespace alib::strings[APPENDABLES]
1035#endif
1036} // namespace [alib::strings]
1037
1038
1039
1041
1042
1043
1044
1045//-------------------------------------------- Debug Dump ------------------------------------------
1046#if ALIB_DEBUG
1047ALIB_EXPORT namespace alib::files {
1048
1049 /// The format string used with namespace function \alib{files;DbgDump}.<br>
1050 /// Defaults to <c>"{:ta h{2,r} on{10,r} gn{10,r} s(IEC){10,r} dm qqq FxFa (rd{3r}' D' rf{3r}' F' re{2r}' EA' rb{2r}'BL) 'nf l}\n"</c><br>
1051 /// This global variable is only available with debug-compilations.
1052 extern String DBG_DUMP_FORMAT;
1053
1054/// Dumps the given branch of this object's tree.<br>
1055/// This function is only available with debug-compilations.
1056/// @param target The target string buffer.
1057/// @param tree The tree to dump.
1058/// @param includedTypes Optional filter for types. Defaults to 'all'.
1059/// @param startNode The start node. If this is not
1060/// \doxlinkproblem{classalib_1_1monomem_1_1StringTree_1_1TCursor.html;ac532c4b500b1a85ea22217f2c65a70ed;a valid node;alib::monomem::StringTree::TCursor::IsValid},
1061/// the root node is chosen. Defaults to an invalid cursor.
1062/// @param depth The maximum depth of recursion. Defaults to unlimited depth.
1063/// @return The given \p{target} to allow concatenated operations.
1066 FTree& tree ,
1068 FTree::Cursor startNode = FTree::Cursor(),
1069 unsigned depth = (std::numeric_limits<unsigned int>::max)() );
1070
1071
1072
1073} // namespace [alib::files]
1074#endif
StringTree(AllocatorType &allocator, CharacterType pathSeparator)
The entry type which is embedded in each tree node.
Definition finfo.inl:15
constexpr ExtendedEntryInfo * GetExtendedInfo() const
Definition finfo.inl:405
@ DIRECTORY
Directory/folder.
Definition finfo.inl:26
ALIB_DLL FTree(MonoAllocator &allocator)
Definition ftree.cpp:114
PoolAllocator Pool
Definition ftree.inl:162
ALIB_DLL void notifyListeners(FTreeListener::Event event, File &file, SharedLock *lock, const system::PathString &filePath)
Definition ftree.cpp:224
NumberFormat numberFormat
Definition ftree.inl:173
void AllocateExtendedInfo(Cursor &node, const system::PathString &symLinkDest, const system::PathString &symLinkRealPath)
Definition ftree.inl:263
OwnerAndGroupResolver ogResolver
Definition ftree.inl:177
bool HasListeners()
Definition ftree.inl:337
void MonitorFilesByName(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const system::PathString &fileName)
Definition ftree.inl:370
void DeleteAllCustomData()
Definition ftree.inl:276
ALIB_DLL int MonitorStop(FTreeListener *listener)
Definition ftree.cpp:204
friend class files::File
Friendship declaration.
Definition ftree.inl:169
void MonitorPath(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const FTree::Cursor &cursor)
Definition ftree.inl:390
OwnerAndGroupResolver & GetOGResolver()
Definition ftree.inl:306
NumberFormat & GetNumberFormat()
Definition ftree.inl:302
void MonitorPathSubstring(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const system::PathString &pathSubstring)
Definition ftree.inl:441
void MonitorPathPrefix(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const system::PathString &pathPrefix)
Definition ftree.inl:417
ALIB_DLL void registerListener(FTreeListener *listener, lang::ContainerOp insertOrRemove, FTreeListener::Event event, const File *file, const StringTree::Cursor *subTree, const system::PathString &fileName, const system::PathString &pathPrefix, const system::PathString &pathSubstring)
Definition ftree.cpp:156
ListMA< ListenerRecord > listeners
The list of registered listeners.
Definition ftree.inl:194
ALIB_DLL ~FTree()
Destructor.
Definition ftree.cpp:131
static ALIB_DLL void FixSums(Cursor directory)
Definition ftree.cpp:261
StringTree< MonoAllocator, FInfo, detail::FTreeNodeHandler > base
Type alias of this classes' base class.
Definition ftree.inl:166
void Notify(FTreeListener::Event event, File &file, SharedLock *lock, const String &filePath=NULL_STRING)
void MonitorDistinctFile(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const File &file)
Definition ftree.inl:347
Path & AssemblePath(Path &target, lang::CurrentData targetData=lang::CurrentData::Clear) const
Definition ftree.inl:760
const FInfo * operator->() const
Definition ftree.inl:698
TCustom & GetCustomData()
Definition ftree.inl:792
FTree & GetFTree() const
Definition ftree.inl:672
FInfo & GetMutableFInfo()
Definition ftree.inl:705
TCustom & AttachCustomData(TArgs &&... args)
Definition ftree.inl:813
FTree::Cursor Cursor
Definition ftree.inl:664
const NString & GetOwnerName() const
Definition ftree.inl:771
bool HasCustomData() const
Definition ftree.inl:781
FTree::ConstCursor ConstCursor
The constant version of type Cursor.
Definition ftree.inl:667
File & operator=(const Cursor &other)
Definition ftree.inl:693
system::PathString Extension() const
Definition ftree.inl:742
const NString & GetGroupName() const
Definition ftree.inl:775
File(FTree &pTree)
Definition ftree.inl:679
ALIB_WARNINGS_RESTORE system::PathString Stem() const
Definition ftree.inl:731
Cursor & AsCursor()
Definition ftree.inl:711
File(const Cursor &cursor)
Definition ftree.inl:686
const Cursor & AsCursor() const
Definition ftree.inl:715
void DeleteCustomData()
Definition ftree.inl:829
lang::Placeholder< lang::DbgCriticalSections > DbgCriticalSectionsPH
bool IsNulled() const noexcept
AllocatorType & GetAllocator() noexcept
constexpr bool IsNotEmpty() const
Definition string.inl:369
integer LastIndexOf(TChar needle, integer startIndex=MAX_LEN) const
Definition string.inl:925
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
Definition string.inl:384
#define ALIB_DLL
Definition alib.inl:503
#define IF_ALIB_THREADS(...)
Definition alib.inl:401
#define ALIB_WARNINGS_RESTORE
Definition alib.inl:719
#define ALIB_ASSERT_WARNING(cond, domain,...)
Definition alib.inl:1067
#define ALIB_WARNINGS_IGNORE_DOCS
Definition alib.inl:702
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
#define ALIB_EXPORT
Definition alib.inl:497
#define ALIB_DBG(...)
Definition alib.inl:853
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
This namespace implements internals of namespace alib::files.
Definition ftree.cpp:60
alib::containers::detail::StringTreeBase< MonoAllocator, FInfo, FTreeNodeHandler, Recycling::Private > TTree
A shortcut to the base class of the base class of class FTree.
Definition ftree.inl:20
void FFormat_File(const Box &box, const String &formatSpec, NumberFormat &nf, AString &target)
Definition file.cpp:387
String DBG_DUMP_FORMAT
ALIB_DLL AString & DbgDump(AString &target, FTree &tree, EnumBitSet< FInfo::Types > includedTypes=EnumBitSet< FInfo::Types >(true), FTree::Cursor startNode=FTree::Cursor(), unsigned depth=(std::numeric_limits< unsigned int >::max)())
ContainerOp
Denotes standard container operations.
Switch
Denotes if sth. is switched on or off.
@ On
Switch it on, switched on, etc.
@ Off
Switch it off, switched off, etc.
@ Keep
Chooses not no clear existing data.
@ Clear
Chooses to clear existing data.
void Destruct(T &object)
Definition tmp.inl:82
strings::TString< PathCharType > PathString
The string-type used with this ALib Module.
Definition path.inl:33
constexpr PathString NULL_PATH
A nulled path string.
Definition path.inl:51
strings::TAString< PathCharType, PoolAllocator > PathStringPA
A pool-allocated string representing a path.
Definition path.inl:46
constexpr PathString EMPTY_PATH
An empty path string.
Definition path.inl:54
std::filesystem::path::value_type PathCharType
Definition path.inl:12
files::FInfo FInfo
Type alias in namespace alib.
Definition finfo.inl:606
threads::SharedLock SharedLock
Type alias in namespace alib.
constexpr String NULL_STRING
A nulled string of the default character type.
Definition string.inl:2271
files::TSharedFTree< SharedLock > SharedFTree
Type alias in namespace alib.
Definition ftree.inl:992
files::File File
Type alias in namespace alib.
Definition ftree.inl:999
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
containers::List< T, MonoAllocator, TRecycling > ListMA
Type alias in namespace alib.
Definition list.inl:693
lang::TBitSet< TEnum, enumops::IterableTraits< TEnum >::End, enumops::IterableTraits< TEnum >::Begin > EnumBitSet
files::FTree FTree
Type alias in namespace alib.
Definition ftree.inl:987
characters::wchar wchar
Type alias in namespace alib.
monomem::TPoolAllocator< MonoAllocator > PoolAllocator
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2198
strings::TNumberFormat< character > NumberFormat
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
system::Path Path
Type alias in namespace alib.
Definition path.inl:376
characters::nchar nchar
Type alias in namespace alib.
boxing::Box Box
Type alias in namespace alib.
Definition box.inl:1149
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189
strings::TSubstring< character > Substring
Type alias in namespace alib.
HashTable< TAllocator, typename NodeKey::ValueDescriptor, typename NodeKey::Hash, typename NodeKey::EqualTo, lang::Caching::Enabled, TRecycling > nodeTable
virtual void Notify(File &file, Event event)=0
virtual ~FTreeListener()
Virtual destructor.
Definition ftree.inl:102
Event
The type of change that imposes the notification of a listener.
Definition ftree.inl:96
@ DeleteNode
A file or directory entry was deleted.
Definition ftree.inl:98
@ CreateNode
A file or directory entry was created.
Definition ftree.inl:97
Record used to manage registered listeners.
Definition ftree.inl:181
FTreeListener::Event event
The event to listen to.
Definition ftree.inl:183
system::PathStringPA fileName
If given, the file's name to listen to.
Definition ftree.inl:186
ConstCursorHandle file
If given, the files to listen to.
Definition ftree.inl:184
ConstCursorHandle subTree
If given, the path of files to listen to.
Definition ftree.inl:185
system::PathStringPA pathSubstring
Definition ftree.inl:189
FTreeListener * listener
The listener to register or dispose.
Definition ftree.inl:182
system::PathStringPA pathPrefix
Definition ftree.inl:187
void DbgCriticalSections(lang::Switch onOff)
TSharedFTree()=default
Constructs an empty instance, hence a cleared automatic pointer.
TSharedFTree & operator=(const TSharedFTree &)=default
TSharedFTree(std::nullptr_t) noexcept
Definition ftree.inl:494
monomem::TSharedMonoVal< FTree, HeapAllocator, TLock > Base
Exposed shortcut to the base type.
Definition ftree.inl:486
TSharedFTree(size_t initialBufferSizeInKB, unsigned bufferGrowthInPercent=200)
Definition ftree.inl:511
system::PathCharType CharacterType
Definition ftree.inl:40
static void InitializeNode(TTree::Node &node, TTree &tree)
static void FreeNode(TTree::Node &node, TTree &tree)
static ALIB_DLL void AllocateExtendedInfo(StringTree< MonoAllocator, FInfo, detail::FTreeNodeHandler >::Cursor &node, const system::PathString &symLinkDest, const system::PathString &symLinkRealPath)
Definition ftree.cpp:63
system::PathString NameStringType
Definition ftree.inl:44
ALIB_DLL void operator()(TAString< nchar, lang::HeapAllocator > &target, const files::File &file)
ALIB_DLL void operator()(TAString< wchar, lang::HeapAllocator > &target, const files::File &file)