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