1 //===- AttributeSet.cpp ---------------------------------------------------===// 2 // 3 // The MCLinker Project 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include "mcld/MC/AttributeSet.h" 10 11 #include "mcld/MC/Attribute.h" 12 13 #include <cstddef> 14 15 namespace mcld { 16 17 //===----------------------------------------------------------------------===// 18 // AttributeSet 19 //===----------------------------------------------------------------------===// AttributeSet(unsigned int pNum,const Attribute & pPredefined)20AttributeSet::AttributeSet(unsigned int pNum, const Attribute& pPredefined) 21 : m_AttrSet(), m_Predefined(pPredefined) { 22 m_AttrSet.reserve(pNum); 23 } 24 ~AttributeSet()25AttributeSet::~AttributeSet() { 26 iterator cur = m_AttrSet.begin(); 27 iterator aEnd = m_AttrSet.end(); 28 29 while (cur != aEnd) { 30 delete (*cur); 31 ++cur; 32 } 33 } 34 exists(const Attribute & pAttr) const35Attribute* AttributeSet::exists(const Attribute& pAttr) const { 36 if (m_Predefined == pAttr) 37 return const_cast<Attribute*>(&m_Predefined); 38 39 const_iterator cur = m_AttrSet.begin(); 40 const_iterator aEnd = m_AttrSet.end(); 41 while (cur != aEnd) { 42 if (*(*cur) == pAttr) { 43 return *cur; 44 } 45 ++cur; 46 } 47 return NULL; 48 } 49 record(mcld::Attribute & pAttr)50void AttributeSet::record(mcld::Attribute& pAttr) { 51 m_AttrSet.push_back(&pAttr); 52 } 53 54 } // namespace mcld 55