paludis  Version 1.4.2
elf_dynamic_section.hh
1 /* vim: set sw=4 sts=4 et foldmethod=syntax : */
2 
3 /*
4  * Copyright (c) 2007 Tiziano Müller
5  * Copyright (c) 2007 David Leverton
6  *
7  * This file is part of the Paludis package manager. Paludis is free software;
8  * you can redistribute it and/or modify it under the terms of the GNU General
9  * Public License version 2, as published by the Free Software Foundation.
10  *
11  * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
18  * Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 #ifndef PALUDIS_GUARD_PALUDIS_UTIL_ELF_DYNAMIC_SECTION_HH
22 #define PALUDIS_GUARD_PALUDIS_UTIL_ELF_DYNAMIC_SECTION_HH 1
23 
24 #include <paludis/util/elf_sections.hh>
25 #include <paludis/util/clone.hh>
27 #include <paludis/util/pimp.hh>
28 #include <paludis/util/wrapped_forward_iterator-fwd.hh>
29 #include <paludis/util/visitor.hh>
30 #include <paludis/util/type_list.hh>
31 #include <memory>
32 #include <string>
33 #include <iosfwd>
34 
35 namespace paludis
36 {
37  template <typename ElfType_> class DynamicEntry;
38  template <typename ElfType_> class DynamicEntryUnknown;
39  template <typename ElfType_> class DynamicEntryValue;
40  template <typename ElfType_> class DynamicEntryPointer;
41  template <typename ElfType_> class DynamicEntryString;
42  template <typename ElfType_> class DynamicEntryFlag;
43 
44  template <typename ElfType_>
45  class DynamicEntry :
46  public virtual DeclareAbstractAcceptMethods<DynamicEntry<ElfType_>, typename MakeTypeList<
47  DynamicEntryUnknown<ElfType_>,
48  DynamicEntryValue<ElfType_>,
49  DynamicEntryPointer<ElfType_>,
50  DynamicEntryString<ElfType_>,
51  DynamicEntryFlag<ElfType_>
52  >::Type>,
53  public virtual Cloneable<DynamicEntry<ElfType_> >
54  {
55  private:
56  std::string _tag_name;
57  typename ElfType_::Word _index;
58 
59  public:
60  DynamicEntry(const std::string &);
61  ~DynamicEntry();
62  virtual void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry & entry);
63 
64  std::string tag_name() const
65  {
66  return _tag_name;
67  }
68 
69  std::string description() const;
70  };
71 
72  template <typename ElfType_>
73  class DynamicEntryUnknown :
74  public virtual DynamicEntry<ElfType_>,
75  public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryUnknown<ElfType_> >,
76  public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryUnknown<ElfType_> >
77  {
78  public:
79  DynamicEntryUnknown();
80  virtual ~DynamicEntryUnknown();
81  };
82 
83  template <typename ElfType_>
84  class DynamicEntryFlag :
85  public virtual DynamicEntry<ElfType_>,
86  public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryFlag<ElfType_> >,
87  public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryFlag<ElfType_> >
88  {
89  public:
90  DynamicEntryFlag(const std::string &);
91  ~DynamicEntryFlag();
92  };
93 
94  template <typename ElfType_>
95  class DynamicEntryValue :
96  public virtual DynamicEntry<ElfType_>,
97  public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryValue<ElfType_> >,
98  public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryValue<ElfType_> >
99  {
100  private:
101  typename ElfType_::DynamicValue _value;
102 
103  public:
104  DynamicEntryValue(const std::string &);
105  virtual ~DynamicEntryValue();
106  virtual void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry & entry);
107 
108  typename ElfType_::DynamicValue operator() () const
109  {
110  return _value;
111  }
112  };
113 
114  template <typename ElfType_>
115  class DynamicEntryPointer :
116  public virtual DynamicEntry<ElfType_>,
117  public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryPointer<ElfType_> >,
118  public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryPointer<ElfType_> >
119  {
120  private:
121  typename ElfType_::DynamicPointer _pointer;
122 
123  public:
124  DynamicEntryPointer(const std::string &);
125  virtual ~DynamicEntryPointer();
126  virtual void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry &);
127 
128  typename ElfType_::DynamicPointer operator() () const
129  {
130  return _pointer;
131  }
132  };
133 
134  namespace littlelf_internals
135  {
136  template <typename ElfType_> class DynEntriesStringResolvingVisitor;
137  }
138 
139  template <typename ElfType_>
140  class DynamicEntryString :
141  public virtual DynamicEntry<ElfType_>,
142  public ImplementAcceptMethods<DynamicEntry<ElfType_>, DynamicEntryString<ElfType_> >,
143  public CloneUsingThis<DynamicEntry<ElfType_>, DynamicEntryString<ElfType_> >
144  {
146 
147  private:
148  typename ElfType_::DynamicValue _value;
149  std::string _str;
150 
151  public:
152  DynamicEntryString(const std::string &);
153  virtual ~DynamicEntryString();
154  virtual void initialize(typename ElfType_::Word, const typename ElfType_::DynamicEntry &);
155 
156  std::string operator() () const
157  {
158  return _str;
159  }
160 
161  private:
162  void resolve_string(std::string str)
163  {
164  _str = str;
165  }
166 
167  typename ElfType_::DynamicValue get_string_index() const
168  {
169  return _value;
170  }
171  };
172 
173  template <typename ElfType_>
175  public Singleton<DynamicEntries<ElfType_> >
176  {
177  friend class Singleton<DynamicEntries>;
178 
179  private:
181 
182  public:
183  void register_type(typename ElfType_::DynamicTag, std::shared_ptr<DynamicEntry<ElfType_> >);
184 
185  std::shared_ptr<DynamicEntry<ElfType_> > get_entry(typename ElfType_::DynamicTag) const;
186  bool has_entry(typename ElfType_::DynamicTag) const;
187 
188  private:
189  DynamicEntries();
190  ~DynamicEntries();
191  };
192 
193  template <typename ElfType_>
195 
196  template <typename ElfType_>
198  public Section<ElfType_>,
199  public ImplementAcceptMethods<Section<ElfType_>, DynamicSection<ElfType_> >
200  {
201  private:
203 
204  public:
205  DynamicSection(typename ElfType_::Word, const typename ElfType_::SectionHeader &, std::istream &, bool);
206  virtual ~DynamicSection();
207 
208  virtual std::string get_type() const;
209 
210  void resolve_entry_names(Section<ElfType_> &);
211 
214  EntryIterator entry_begin() const;
215  EntryIterator entry_end() const;
216  };
217 }
218 
219 #endif
Definition: pimp.hh:51
Definition: elf_dynamic_section.hh:197
Definition: elf_dynamic_section.hh:41
Definition: visitor-fwd.hh:52
Definition: elf_dynamic_section.hh:40
Definition: elf_sections.hh:32
Definition: elf_dynamic_section.hh:194
Definition: elf_dynamic_section.hh:37
Definition: elf_dynamic_section.hh:38
Definition: wrapped_forward_iterator-fwd.hh:26
Definition: singleton.hh:44
Definition: elf_dynamic_section.hh:39
Definition: clone.hh:46
Definition: elf_dynamic_section.hh:42
Definition: elf_dynamic_section.hh:174
Definition: clone.hh:75
Definition: visitor-fwd.hh:49
#define PALUDIS_VISIBLE
Definition: attributes.hh:71