8#ifndef HPP_ALIB_FILES_FTREE
9#define HPP_ALIB_FILES_FTREE 1
16#include "alib/containers/stringtree.hpp"
23namespace alib {
namespace files {
26template<
typename TLock>
struct TSharedFTree;
32struct FTreeNodeHandler;
167 friend struct FTreeNodeHandler;
292 template<
typename TCustom>
297 if( node.data.custom )
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" )
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; )
372 "Event::Creation will never be invoked with this listener-registration-type.")
397 nullptr,
nullptr, fileName,
506template<
typename TLock>
536 unsigned int bufferGrowthInPercent = 200 )
537 :
Base(initialBufferSizeInKB, bufferGrowthInPercent)
560 template<
typename TIf=
typename Base::LockType>
564 #if ALIB_DEBUG_CRITICAL_SECTIONS
583 template<
typename TIf=
typename Base::LockType>
610 node.name.storage.Allocate(
static_cast<FTree&
>(tree).Pool, node.name.key );
616 auto& pool=
static_cast<FTree&
>(tree).Pool;
618 if ( node.name.storage.Length() )
623 FInfo& value= node.data;
625 if( extendedInfo ==
nullptr )
628 if( value.IsSymbolicLink() )
631 FInfo::EISymLinkFile& ei= *
static_cast<FInfo::EISymLinkFile*
>(extendedInfo);
633 if( ei.RealTarget.Buffer() != ei.Target.Buffer()
634 && ei.RealTarget.Buffer() !=
nullptr )
635 pool().Free( ei.RealTarget.Buffer(), ei.RealTarget.Length() + 1 );
637 if( ei.Target.Buffer() !=
nullptr )
638 pool().Free( ei.Target.Buffer(), ei.Target.Length() + 1 );
641 pool().Delete(
static_cast<FInfo::EISymLinkFile*
>(extendedInfo) );
643 pool().Delete(
static_cast<FInfo::EISymLinkDir*
>(extendedInfo) );
646 ALIB_DBG( value.SetExtendedInfo(
nullptr) );
651 "FILES",
"Given node is not a directory or symbolic link but still has extendedInfo set.")
653 pool().Delete( reinterpret_cast<
FInfo::EIDirectory*>(extendedInfo) );
656 ALIB_DBG( value.SetExtendedInfo(
nullptr) );
658#include "alib/lang/callerinfo_methods.hpp"
706 {
return static_cast<FTree&
>(Tree()); }
714 :
Cursor( pTree.Root() ) {}
729 Cursor::operator=( other );
771 return dotPos < 2 ? result
782 return dotPos < 2 ? lang::system::EMPTY_PATH
783 : Name().Substring( dotPos + 1 );
801 if( targetData == lang::CurrentData::Clear )
803 if( !AsCursor().IsRoot() )
804 AsCursor().Parent().AssemblePath(target, lang::CurrentData::Keep);
822 return Value().custom !=
nullptr;
833 template<
typename TCustom>
837 "No custom data set." )
839 "Requested custom object type mismatch." )
841 return *
reinterpret_cast<TCustom*
>( Value().custom );
854 template<
typename TCustom,
typename... TArgs>
858 "Custom data already set." )
860 auto* custom= GetFTree().Pool().template New<TCustom>( std::forward<TArgs>(args)... );
861 Value().custom= custom;
862ALIB_DBG(Value().dbgCustomType= &
typeid(TCustom); )
872 template<
typename TCustom>
875 lang::Destruct(GetCustomData<TCustom>());
876 GetFTree().Pool.free( Value().custom,
sizeof(TCustom) );
877 Value().custom=
nullptr;
1036#if ALIB_THREADS || DOXYGEN
1037DOX_MARKER([DOX_MANUAL_ALIASES_FTREE])
1040DOX_MARKER([DOX_MANUAL_ALIASES_FTREE])
1059namespace APPENDABLES {
1116 unsigned int depth = (std::numeric_limits<unsigned int>::max)() );
TCursor< false > Cursor
The mutable version of type StringTree::TCursor<TConst>.
The entry type which is embedded in each tree node.
constexpr ExtendedEntryInfo * GetExtendedInfo() const
@ DIRECTORY
Directory/folder.
NumberFormat numberFormat
ALIB_API ~FTree()
Destructor.
ALIB_API int MonitorStop(FTreeListener *listener)
void AllocateExtendedInfo(Cursor &node, const lang::system::PathString &symLinkDest, const lang::system::PathString &symLinkRealPath)
void DeleteAllCustomData()
List< MonoAllocator, ListenerRecord > listeners
The list of registered listeners.
void MonitorFilesByName(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const lang::system::PathString &fileName)
OwnerAndGroupResolver & GetOGResolver()
ALIB_API void notifyListeners(FTreeListener::Event event, File &file, SharedLock *lock, const lang::system::PathString &filePath)
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)
void MonitorPathSubstring(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const lang::system::PathString &pathSubstring)
OwnerAndGroupResolver ogResolver
static ALIB_API void FixSums(Cursor directory)
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)
NumberFormat & GetNumberFormat()
void MonitorPath(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const FTree::Cursor &cursor)
void MonitorDistinctFile(lang::ContainerOp insertOrRemove, FTreeListener *listener, FTreeListener::Event event, const File &file)
const FInfo * operator->() const
ALIB_WARNINGS_RESTORE lang::system::PathString Stem() const
TCustom & GetCustomData()
File & operator=(const Cursor &other)
const NString & GetGroupName() const
const Cursor & AsCursor() const
lang::system::PathString Extension() const
FInfo & GetMutableFInfo()
bool HasCustomData() const
Path & AssemblePath(Path &target, lang::CurrentData targetData=lang::CurrentData::Clear) const
const NString & GetOwnerName() const
File(const Cursor &cursor)
TCustom & AttachCustomData(TArgs &&... args)
lang::Placeholder< lang::DbgCriticalSections > DbgCriticalSectionsPH
void free(void *mem, size_t size)
AllocatorType & GetAllocator() noexcept
TLock & GetLock() const noexcept
bool IsNulled() const noexcept
void ConstructT(TArgs &&... args)
void Reset(TArgs &&... args)
constexpr bool IsNotEmpty() const
TString< TChar > Substring(integer regionStart, integer regionLength=MAX_LEN) const
ALIB_WARNINGS_RESTORE integer LastIndexOf(TChar needle, integer startIndex=MAX_LEN) const
#define ALIB_ASSERT_MODULE(modulename)
#define IF_ALIB_THREADS(...)
#define ATMP_VOID_IF(Cond)
#define ALIB_WARNINGS_RESTORE
#define ALIB_WARNINGS_IGNORE_DOCS
#define ALIB_BOXING_VTABLE_DECLARE(TMapped, Identifier)
#define ATMP_EQ( T, TEqual)
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_ASSERT_WARNING(cond,...)
alib::containers::detail::StringTreeBase< MonoAllocator, FInfo, FTreeNodeHandler, Recycling::Private > TTree
A shortcut to the base class of the base class of class FTree.
void FFormat_File(const alib::Box &box, const alib::String &formatSpec, alib::NumberFormat &nf, alib::AString &target)
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.
strings::TString< PathCharType > PathString
The string-type used with this ALib Module.
std::filesystem::path::value_type PathCharType
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.
files::File File
Type alias in namespace alib.
characters::wchar wchar
Type alias in namespace alib.
monomem::TMonoAllocator< lang::HeapAllocator > MonoAllocator
files::FInfo FInfo
Type alias in namespace alib.
files::FTree FTree
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
constexpr String NULL_STRING
A nulled string of the default character type.
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.
Event
The type of change that imposes the notification of a listener.
@ 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.
ConstCursorHandle subTree
If given, the path of files to listen to.
lang::system::PathStringPA pathSubstring
FTreeListener::Event event
The event to listen to.
FTreeListener * listener
The listener to register or dispose.
ConstCursorHandle file
If given, the files to listen to.
lang::system::PathStringPA pathPrefix
lang::system::PathStringPA fileName
If given, the file's name to listen to.
TSharedFTree & operator=(const TSharedFTree &)=default
TSharedFTree(std::nullptr_t) noexcept
TSharedFTree(size_t initialBufferSizeInKB, unsigned int bufferGrowthInPercent=200)
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)
static void InitializeNode(TTree &tree, TTree::Node &node)
lang::system::PathCharType CharacterType
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)