xref: /haiku/src/add-ons/kernel/file_systems/packagefs/nodes/UnpackingAttributeDirectoryCookie.cpp (revision 4c61288e73ab85766ae2709a38809384cd7ed489)
1 /*
2  * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "UnpackingAttributeDirectoryCookie.h"
8 
9 #include "DebugSupport.h"
10 #include "PackageNode.h"
11 
12 
UnpackingAttributeDirectoryCookie(PackageNode * packageNode)13 UnpackingAttributeDirectoryCookie::UnpackingAttributeDirectoryCookie(
14 	PackageNode* packageNode)
15 	:
16 	AutoPackageAttributeDirectoryCookie(),
17 	fPackageNode(packageNode),
18 	fAttribute(NULL)
19 {
20 	if (fPackageNode != NULL) {
21 		fPackageNode->AcquireReference();
22 		fAttribute = fPackageNode->Attributes().Head();
23 	}
24 }
25 
26 
~UnpackingAttributeDirectoryCookie()27 UnpackingAttributeDirectoryCookie::~UnpackingAttributeDirectoryCookie()
28 {
29 	if (fPackageNode != NULL)
30 		fPackageNode->ReleaseReference();
31 }
32 
33 
34 /*static*/ status_t
Open(PackageNode * packageNode,AttributeDirectoryCookie * & _cookie)35 UnpackingAttributeDirectoryCookie::Open(PackageNode* packageNode,
36 	AttributeDirectoryCookie*& _cookie)
37 {
38 	UnpackingAttributeDirectoryCookie* cookie = new(std::nothrow)
39 		UnpackingAttributeDirectoryCookie(packageNode);
40 	if (cookie == NULL)
41 		return B_NO_MEMORY;
42 
43 	_cookie = cookie;
44 	return B_OK;
45 }
46 
47 
48 status_t
Rewind()49 UnpackingAttributeDirectoryCookie::Rewind()
50 {
51 	if (fPackageNode != NULL)
52 		fAttribute = fPackageNode->Attributes().Head();
53 
54 	return AutoPackageAttributeDirectoryCookie::Rewind();
55 }
56 
57 
58 String
CurrentCustomAttributeName()59 UnpackingAttributeDirectoryCookie::CurrentCustomAttributeName()
60 {
61 	return fAttribute != NULL ? fAttribute->Name() : String();
62 }
63 
64 
65 String
NextCustomAttributeName()66 UnpackingAttributeDirectoryCookie::NextCustomAttributeName()
67 {
68 	if (fAttribute != NULL)
69 		fAttribute = fPackageNode->Attributes().GetNext(fAttribute);
70 	return fAttribute != NULL ? fAttribute->Name() : String();
71 }
72