2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
8 #ifndef _NOT_OWNING_ENTRY_REF_H
9 #define _NOT_OWNING_ENTRY_REF_H
19 /*! entry_ref subclass that avoids cloning the entry name.
21 Therefore initialization is cheaper and cannot fail. It derives from
22 entry_ref for convenience. However, care must be taken that:
23 - the name remains valid while the object is in use,
24 - the object isn't passed as an entry_ref to a function that modifies it.
26 class NotOwningEntryRef
: public entry_ref
{
32 NotOwningEntryRef(dev_t device
, ino_t directory
, const char* name
)
34 SetTo(device
, directory
, name
);
37 NotOwningEntryRef(const node_ref
& directoryRef
, const char* name
)
39 SetTo(directoryRef
, name
);
42 NotOwningEntryRef(const entry_ref
& other
)
52 NotOwningEntryRef
& SetTo(dev_t device
, ino_t directory
, const char* name
)
54 this->device
= device
;
55 this->directory
= directory
;
56 this->name
= const_cast<char*>(name
);
60 NotOwningEntryRef
& SetTo(const node_ref
& directoryRef
, const char* name
)
62 return SetTo(directoryRef
.device
, directoryRef
.node
, name
);
65 node_ref
DirectoryNodeRef() const
67 return node_ref(device
, directory
);
70 NotOwningEntryRef
& SetDirectoryNodeRef(const node_ref
& directoryRef
)
72 device
= directoryRef
.device
;
73 directory
= directoryRef
.node
;
77 NotOwningEntryRef
& operator=(const entry_ref
& other
)
79 return SetTo(other
.device
, other
.directory
, other
.name
);
84 } // namespace BPrivate
87 using ::BPrivate::NotOwningEntryRef
;
90 #endif // _NOT_OWNING_ENTRY_REF_H