1*d0815ca0SIngo Weinhold /* 2*d0815ca0SIngo Weinhold * Copyright 2013, Haiku, Inc. All Rights Reserved. 3*d0815ca0SIngo Weinhold * Distributed under the terms of the MIT License. 4*d0815ca0SIngo Weinhold * 5*d0815ca0SIngo Weinhold * Authors: 6*d0815ca0SIngo Weinhold * Ingo Weinhold <ingo_weinhold@gmx.de> 7*d0815ca0SIngo Weinhold */ 8*d0815ca0SIngo Weinhold #ifndef _MERGED_DIRECTORY_H 9*d0815ca0SIngo Weinhold #define _MERGED_DIRECTORY_H 10*d0815ca0SIngo Weinhold 11*d0815ca0SIngo Weinhold 12*d0815ca0SIngo Weinhold #include <EntryList.h> 13*d0815ca0SIngo Weinhold #include <ObjectList.h> 14*d0815ca0SIngo Weinhold 15*d0815ca0SIngo Weinhold 16*d0815ca0SIngo Weinhold class BDirectory; 17*d0815ca0SIngo Weinhold 18*d0815ca0SIngo Weinhold 19*d0815ca0SIngo Weinhold class BMergedDirectory : public BEntryList { 20*d0815ca0SIngo Weinhold public: 21*d0815ca0SIngo Weinhold // policy how to handle equally named entries in different 22*d0815ca0SIngo Weinhold // directories 23*d0815ca0SIngo Weinhold enum BPolicy { 24*d0815ca0SIngo Weinhold B_ALLOW_DUPLICATES, 25*d0815ca0SIngo Weinhold B_ALWAYS_FIRST, 26*d0815ca0SIngo Weinhold B_COMPARE 27*d0815ca0SIngo Weinhold }; 28*d0815ca0SIngo Weinhold 29*d0815ca0SIngo Weinhold public: 30*d0815ca0SIngo Weinhold BMergedDirectory( 31*d0815ca0SIngo Weinhold BPolicy policy = B_ALWAYS_FIRST); 32*d0815ca0SIngo Weinhold virtual ~BMergedDirectory(); 33*d0815ca0SIngo Weinhold 34*d0815ca0SIngo Weinhold status_t Init(); 35*d0815ca0SIngo Weinhold 36*d0815ca0SIngo Weinhold BPolicy Policy() const; 37*d0815ca0SIngo Weinhold void SetPolicy(BPolicy policy); 38*d0815ca0SIngo Weinhold 39*d0815ca0SIngo Weinhold status_t AddDirectory(BDirectory* directory); 40*d0815ca0SIngo Weinhold status_t AddDirectory(const char* path); 41*d0815ca0SIngo Weinhold 42*d0815ca0SIngo Weinhold virtual status_t GetNextEntry(BEntry* entry, 43*d0815ca0SIngo Weinhold bool traverse = false); 44*d0815ca0SIngo Weinhold virtual status_t GetNextRef(entry_ref* ref); 45*d0815ca0SIngo Weinhold virtual int32 GetNextDirents(struct dirent* direntBuffer, 46*d0815ca0SIngo Weinhold size_t bufferSize, 47*d0815ca0SIngo Weinhold int32 maxEntries = INT_MAX); 48*d0815ca0SIngo Weinhold virtual status_t Rewind(); 49*d0815ca0SIngo Weinhold virtual int32 CountEntries(); 50*d0815ca0SIngo Weinhold 51*d0815ca0SIngo Weinhold protected: 52*d0815ca0SIngo Weinhold virtual bool ShallPreferFirstEntry(const entry_ref& entry1, 53*d0815ca0SIngo Weinhold int32 index1, const entry_ref& entry2, 54*d0815ca0SIngo Weinhold int32 index2); 55*d0815ca0SIngo Weinhold // always invoked with index1 < index2 56*d0815ca0SIngo Weinhold 57*d0815ca0SIngo Weinhold private: 58*d0815ca0SIngo Weinhold typedef BObjectList<BDirectory> DirectoryList; 59*d0815ca0SIngo Weinhold struct EntryNameSet; 60*d0815ca0SIngo Weinhold 61*d0815ca0SIngo Weinhold private: 62*d0815ca0SIngo Weinhold bool _IsBestEntry(const char* name); 63*d0815ca0SIngo Weinhold 64*d0815ca0SIngo Weinhold private: 65*d0815ca0SIngo Weinhold DirectoryList fDirectories; 66*d0815ca0SIngo Weinhold BPolicy fPolicy; 67*d0815ca0SIngo Weinhold int32 fDirectoryIndex; 68*d0815ca0SIngo Weinhold EntryNameSet* fVisitedEntries; 69*d0815ca0SIngo Weinhold }; 70*d0815ca0SIngo Weinhold 71*d0815ca0SIngo Weinhold 72*d0815ca0SIngo Weinhold #endif // _MERGED_DIRECTORY_H 73