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