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