Since BObjectList is a template class, this only breaks ABI where BObjectList was exposed in public methods, and even then it's only a name mangling break and we should be able to add compatibility methods if necessary. (The old "bool owning" member variable is left intact for ABI compatibility, for the moment, though it's otherwise unused now.) Tracker's PoseList is the only remaining type that has a "bool owning" switch in the constructor rather than template parameters. This should significantly improve the output of static code analysis tools that previously detected list operations as causing use-after-frees and double-frees, as well as make code maintenance easier by making it easier to determine what list owns (or does not own) an object. It should also be a minor performance optimization, since the branches for calls to delete/free should now be optimized out altogether. Still boots to desktop and Tracker, Deskbar, Debugger all tested and verified as working. Change-Id: If2a24a6f0d22e7a506ef554fcfdd328907279ed4 Reviewed-on: https://review.haiku-os.org/c/haiku/+/8915 Reviewed-by: waddlesplash <[email protected]>
73 lines
1.6 KiB
C++
73 lines
1.6 KiB
C++
/*
|
|
* Copyright 2013, Haiku, Inc. All Rights Reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*
|
|
* Authors:
|
|
* Ingo Weinhold <[email protected]>
|
|
*/
|
|
#ifndef _MERGED_DIRECTORY_H
|
|
#define _MERGED_DIRECTORY_H
|
|
|
|
|
|
#include <EntryList.h>
|
|
#include <ObjectList.h>
|
|
|
|
|
|
class BDirectory;
|
|
|
|
|
|
class BMergedDirectory : public BEntryList {
|
|
public:
|
|
// policy how to handle equally named entries in different
|
|
// directories
|
|
enum BPolicy {
|
|
B_ALLOW_DUPLICATES,
|
|
B_ALWAYS_FIRST,
|
|
B_COMPARE
|
|
};
|
|
|
|
public:
|
|
BMergedDirectory(
|
|
BPolicy policy = B_ALWAYS_FIRST);
|
|
virtual ~BMergedDirectory();
|
|
|
|
status_t Init();
|
|
|
|
BPolicy Policy() const;
|
|
void SetPolicy(BPolicy policy);
|
|
|
|
status_t AddDirectory(BDirectory* directory);
|
|
status_t AddDirectory(const char* path);
|
|
|
|
virtual status_t GetNextEntry(BEntry* entry,
|
|
bool traverse = false);
|
|
virtual status_t GetNextRef(entry_ref* ref);
|
|
virtual int32 GetNextDirents(struct dirent* direntBuffer,
|
|
size_t bufferSize,
|
|
int32 maxEntries = INT_MAX);
|
|
virtual status_t Rewind();
|
|
virtual int32 CountEntries();
|
|
|
|
protected:
|
|
virtual bool ShallPreferFirstEntry(const entry_ref& entry1,
|
|
int32 index1, const entry_ref& entry2,
|
|
int32 index2);
|
|
// always invoked with index1 < index2
|
|
|
|
private:
|
|
typedef BObjectList<BDirectory, true> DirectoryList;
|
|
struct EntryNameSet;
|
|
|
|
private:
|
|
void _FindBestEntry(dirent* direntBuffer);
|
|
|
|
private:
|
|
DirectoryList fDirectories;
|
|
BPolicy fPolicy;
|
|
int32 fDirectoryIndex;
|
|
EntryNameSet* fVisitedEntries;
|
|
};
|
|
|
|
|
|
#endif // _MERGED_DIRECTORY_H
|