• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- LDSectionFactory.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/LD/LDSectionFactory.h>
10 
11 using namespace mcld;
12 
13 //==========================
14 // LDSectionFactory
LDSectionFactory(size_t pNum)15 LDSectionFactory::LDSectionFactory(size_t pNum)
16   : GCFactory<LDSection, 0>(pNum) {
17 }
18 
~LDSectionFactory()19 LDSectionFactory::~LDSectionFactory()
20 {
21 }
22 
produce(const std::string & pName,LDFileFormat::Kind pKind,uint32_t pType,uint32_t pFlag)23 LDSection* LDSectionFactory::produce(const std::string& pName,
24                                    LDFileFormat::Kind pKind,
25                                    uint32_t pType,
26                                    uint32_t pFlag)
27 {
28   // create a LDSection
29   LDSection* result = allocate();
30   new (result) LDSection(pName, pKind, pType, pFlag);
31   return result;
32 }
33 
destroy(LDSection * & pSection)34 void LDSectionFactory::destroy(LDSection*& pSection)
35 {
36   // do not recycle LDSection. HeaderFactory will do that job.
37   deallocate(pSection);
38 }
39 
find(const std::string & pName)40 LDSection* LDSectionFactory::find(const std::string& pName)
41 {
42   iterator sect_iter, sect_end = end();
43   for (sect_iter = begin(); sect_iter != sect_end; ++sect_iter)
44     if ((*sect_iter).name() == pName)
45       break;
46   if (sect_iter == sect_end)
47     return NULL;
48   return &(*sect_iter);
49 }
50