1 //===- SectionData.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_LD_SECTION_DATA_H 10 #define MCLD_LD_SECTION_DATA_H 11 #ifdef ENABLE_UNITTEST 12 #include <gtest.h> 13 #endif 14 15 #include <llvm/ADT/ilist.h> 16 #include <llvm/ADT/ilist_node.h> 17 #include <llvm/Support/DataTypes.h> 18 19 #include <mcld/Config/Config.h> 20 #include <mcld/Support/Allocators.h> 21 #include <mcld/Fragment/Fragment.h> 22 23 namespace mcld { 24 25 class LDSection; 26 27 /** \class SectionData 28 * \brief SectionData provides a container for all Fragments. 29 */ 30 class SectionData 31 { 32 private: 33 friend class Chunk<SectionData, MCLD_SECTIONS_PER_INPUT>; 34 35 SectionData(); 36 explicit SectionData(LDSection &pSection); 37 38 SectionData(const SectionData &); // DO NOT IMPLEMENT 39 SectionData& operator=(const SectionData &); // DO NOT IMPLEMENT 40 41 public: 42 typedef llvm::iplist<Fragment> FragmentListType; 43 44 typedef FragmentListType::reference reference; 45 typedef FragmentListType::const_reference const_reference; 46 47 typedef FragmentListType::iterator iterator; 48 typedef FragmentListType::const_iterator const_iterator; 49 50 typedef FragmentListType::reverse_iterator reverse_iterator; 51 typedef FragmentListType::const_reverse_iterator const_reverse_iterator; 52 53 public: 54 static SectionData* Create(LDSection& pSection); 55 56 static void Destroy(SectionData*& pSection); 57 58 static void Clear(); 59 60 const LDSection& getSection() const { return *m_pSection; } 61 LDSection& getSection() { return *m_pSection; } 62 63 FragmentListType &getFragmentList() { return m_Fragments; } 64 const FragmentListType &getFragmentList() const { return m_Fragments; } 65 66 size_t size() const { return m_Fragments.size(); } 67 68 bool empty() const { return m_Fragments.empty(); } 69 70 reference front () { return m_Fragments.front(); } 71 const_reference front () const { return m_Fragments.front(); } 72 reference back () { return m_Fragments.back(); } 73 const_reference back () const { return m_Fragments.back(); } 74 75 const_iterator begin () const { return m_Fragments.begin(); } 76 iterator begin () { return m_Fragments.begin(); } 77 const_iterator end () const { return m_Fragments.end(); } 78 iterator end () { return m_Fragments.end(); } 79 const_reverse_iterator rbegin() const { return m_Fragments.rbegin(); } 80 reverse_iterator rbegin() { return m_Fragments.rbegin(); } 81 const_reverse_iterator rend () const { return m_Fragments.rend(); } 82 reverse_iterator rend () { return m_Fragments.rend(); } 83 84 private: 85 FragmentListType m_Fragments; 86 LDSection* m_pSection; 87 88 }; 89 90 } // namespace of mcld 91 92 #endif 93 94