1//===- LDSectionFactory.h -------------------------------------------------===//
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#ifndef MCLD_LDSECTION_FACTORY_H
10#define MCLD_LDSECTION_FACTORY_H
11#ifdef ENABLE_UNITTEST
12#include <gtest.h>
13#endif
14
15#include <string>
16
17#include <mcld/Support/GCFactory.h>
18#include <mcld/LD/LDSection.h>
19#include <mcld/LD/LDFileFormat.h>
20
21namespace mcld
22{
23
24/** \class LDSectionFactory
25 *  \brief provide the interface to create and delete section data for output
26 */
27class LDSectionFactory : public GCFactory<LDSection, 0>
28{
29public:
30  /// LDSectionFactory - the factory of LDSection
31  /// pNum is the average number of the LDSections in the system.
32  LDSectionFactory(size_t pNum);
33  ~LDSectionFactory();
34
35  /// produce - produce an empty section information.
36  /// This function will create an empty SectionData and its LDSection.
37  /// @param pName - The name of the section.
38  /// @param pKind - The kind of the section. Used to create default section map
39  /// @param pType - sh_type in ELF.
40  /// @param pFlag - is the same as sh_flags.
41  LDSection* produce(const std::string& pName,
42                     LDFileFormat::Kind pKind,
43                     uint32_t pType,
44                     uint32_t pFlag);
45
46  /// destroy - destruct the LDSection.
47  /// @oaram - the reference of the pointer to the destructed LDSection.
48  ///          after the destruction, the pointer is set to zero.
49  void destroy(LDSection*& pSD);
50
51  /// find - find the LDSection* in factory from the given section name.
52  ///        return NULL if not found.
53  /// @param pName - the name of section
54  LDSection* find(const std::string& pName);
55};
56
57} // namespace of mcld
58
59#endif
60
61