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 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 27 UnpackingAttributeDirectoryCookie::~UnpackingAttributeDirectoryCookie() 28 { 29 if (fPackageNode != NULL) 30 fPackageNode->ReleaseReference(); 31 } 32 33 34 /*static*/ status_t 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 49 UnpackingAttributeDirectoryCookie::Rewind() 50 { 51 if (fPackageNode != NULL) 52 fAttribute = fPackageNode->Attributes().Head(); 53 54 return AutoPackageAttributeDirectoryCookie::Rewind(); 55 } 56 57 58 String 59 UnpackingAttributeDirectoryCookie::CurrentCustomAttributeName() 60 { 61 return fAttribute != NULL ? fAttribute->Name() : String(); 62 } 63 64 65 String 66 UnpackingAttributeDirectoryCookie::NextCustomAttributeName() 67 { 68 if (fAttribute != NULL) 69 fAttribute = fPackageNode->Attributes().GetNext(fAttribute); 70 return fAttribute != NULL ? fAttribute->Name() : String(); 71 } 72