1/* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _PACKAGE__HPKG__PRIVATE__STACKER_H_ 6#define _PACKAGE__HPKG__PRIVATE__STACKER_H_ 7 8 9namespace BPackageKit { 10 11namespace BHPKG { 12 13namespace BPrivate { 14 15 16template<typename Type> 17class Stacker { 18public: 19 Stacker(Type*& location, Type* element) 20 : 21 fLocation(&location), 22 fPreviousElement(location) 23 { 24 *fLocation = element; 25 } 26 27 Stacker(Type** location, Type* element) 28 : 29 fLocation(location), 30 fPreviousElement(*location) 31 { 32 *fLocation = element; 33 } 34 35 ~Stacker() 36 { 37 if (fLocation != NULL) 38 *fLocation = fPreviousElement; 39 } 40 41private: 42 Type** fLocation; 43 Type* fPreviousElement; 44}; 45 46 47} // namespace BPrivate 48 49} // namespace BHPKG 50 51} // namespace BPackageKit 52 53 54#endif // _PACKAGE__HPKG__PRIVATE__STACKER_H_ 55