1 //===- AttributeFactory.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/MCLDAttribute.h" 10 #include "mcld/MC/AttributeFactory.h" 11 12 using namespace mcld; 13 14 //========================== 15 // AttributeFactory AttributeFactory()16AttributeFactory::AttributeFactory() 17 : m_AttrSet() { 18 m_AttrSet.push_back(new mcld::Attribute()); 19 m_pLast = new AttributeProxy(*this, *m_AttrSet.front()); 20 } 21 AttributeFactory(size_t pNum)22AttributeFactory::AttributeFactory(size_t pNum) 23 : m_AttrSet() { 24 m_AttrSet.reserve(pNum); 25 m_AttrSet.push_back(new mcld::Attribute()); 26 m_pLast = new AttributeProxy(*this, *m_AttrSet.front()); 27 } 28 ~AttributeFactory()29AttributeFactory::~AttributeFactory() 30 { 31 iterator cur = m_AttrSet.begin(); 32 iterator aEnd = m_AttrSet.end(); 33 while(cur != aEnd) { 34 delete (*cur); 35 ++cur; 36 } 37 m_AttrSet.clear(); 38 delete m_pLast; 39 } 40 reserve(size_t pNum)41void AttributeFactory::reserve(size_t pNum) 42 { 43 m_AttrSet.reserve(pNum); 44 } 45 predefined()46Attribute &AttributeFactory::predefined() 47 { 48 return *m_AttrSet.front(); 49 } 50 predefined() const51const Attribute &AttributeFactory::predefined() const 52 { 53 return *m_AttrSet.front(); 54 } 55 produce()56AttributeProxy* AttributeFactory::produce() 57 { 58 m_pLast->change(m_AttrSet.front()); 59 return m_pLast->clone(); 60 } 61 last()62AttributeProxy& AttributeFactory::last() 63 { 64 return *m_pLast; 65 } 66 last() const67const AttributeProxy& AttributeFactory::last() const 68 { 69 return *m_pLast; 70 } 71 exists(const Attribute & pAttr) const72Attribute* AttributeFactory::exists(const Attribute& pAttr) const 73 { 74 const_iterator cur = m_AttrSet.begin(); 75 const_iterator aEnd = m_AttrSet.end(); 76 while(cur != aEnd) { 77 if (*(*cur) == pAttr) { 78 m_pLast->change(*cur); 79 return *cur; 80 } 81 ++cur; 82 } 83 return 0; 84 } 85 record(mcld::Attribute & pAttr)86void AttributeFactory::record(mcld::Attribute &pAttr) 87 { 88 m_AttrSet.push_back(&pAttr); 89 m_pLast->change(m_AttrSet.back()); 90 } 91 92