1/* 2 * Copyright (c) 2000-2001,2003-2004 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 25// 26// adornment - generic attached-storage facility 27// 28#include "adornments.h" 29#include <security_utilities/utilities.h> 30#include <security_utilities/debugging.h> 31 32 33namespace Security { 34 35 36// 37// Adornment needs a virtual destructor for safe deletion. 38// 39Adornment::~Adornment() 40{ } 41 42 43// 44// Adornable deletes all pointed-to objects when it dies. 45// 46Adornable::~Adornable() 47{ 48 clearAdornments(); 49} 50 51 52// 53// Primitive (non-template) adornment operations 54// 55Adornment *Adornable::getAdornment(Key key) const 56{ 57 if (mAdornments) { 58 AdornmentMap::const_iterator it = mAdornments->find(key); 59 return (it == mAdornments->end()) ? NULL : it->second; 60 } else 61 return NULL; // nada 62} 63 64void Adornable::setAdornment(Key key, Adornment *ad) 65{ 66 Adornment *&slot = adornmentSlot(key); 67 delete slot; 68 slot = ad; 69} 70 71Adornment *Adornable::swapAdornment(Key key, Adornment *ad) 72{ 73 std::swap(ad, adornmentSlot(key)); 74 return ad; 75} 76 77Adornment *&Adornable::adornmentSlot(Key key) 78{ 79 if (!mAdornments) 80 mAdornments = new AdornmentMap; 81 return (*mAdornments)[key]; 82} 83 84void Adornable::clearAdornments() 85{ 86 if (mAdornments) { 87 for_each_map_delete(mAdornments->begin(), mAdornments->end()); 88 delete mAdornments; 89 mAdornments = NULL; 90 } 91} 92 93} // end namespace Security 94