AttributeFactory.h revision affc150dc44fab1911775a49636d0ce85333b634
146b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown//===- AttributeFactory.h -------------------------------------------------===//
246b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown//
346b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown//                     The MCLinker Project
446b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown//
546b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown// This file is distributed under the University of Illinois Open Source
646b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown// License. See LICENSE.TXT for details.
746b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown//
846b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown//===----------------------------------------------------------------------===//
946b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown#ifndef MCLD_ATTRIBUTE_FACTORY_H
1046b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown#define MCLD_ATTRIBUTE_FACTORY_H
1146b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown#ifdef ENABLE_UNITTEST
1246b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown#include <gtest.h>
1346b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown#endif
1446b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown#include <mcld/ADT/Uncopyable.h>
1546b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown#include <mcld/MC/MCLDAttribute.h>
1646b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown
1746b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownnamespace mcld
1846b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown{
1946b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown
2046b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown/** \class AttributeFactory
211f2451007c660091b7b090c1ea332f9044515d2dJeff Brown *  \brief AttributeFactory contructs the AttributeProxys.
221f2451007c660091b7b090c1ea332f9044515d2dJeff Brown *
2346b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown *  Since the number of AttributeProxys is usually small, sequential search
2446b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown *  on a small vector is enough.
2546b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown */
2646b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownclass AttributeFactory : private Uncopyable
2746b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown{
281f2451007c660091b7b090c1ea332f9044515d2dJeff Brownprivate:
291f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  typedef std::vector<Attribute*> AttrSet;
3046b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown
3146b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownpublic:
321f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  typedef AttrSet::iterator iterator;
331f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  typedef AttrSet::const_iterator const_iterator;
341f2451007c660091b7b090c1ea332f9044515d2dJeff Brown
3546b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brownpublic:
3646b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown  AttributeFactory();
371f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  explicit AttributeFactory(size_t pNum);
381f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  ~AttributeFactory();
391f2451007c660091b7b090c1ea332f9044515d2dJeff Brown
401f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  // reserve - reserve the memory space for attributes
411f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  // @param pNum the number of reserved attributes
421f2451007c660091b7b090c1ea332f9044515d2dJeff Brown  void reserve(size_t pNum);
4346b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown
4446b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown  // predefined - return the predefined attribute
4546b9ac0ae2162309774a7478cd9d4e578747bfc2Jeff Brown  Attribute& predefined();
46  const Attribute& predefined() const;
47
48  // constraint - return the constraint of attributes
49  AttrConstraint& constraint()
50  { return m_Constraint; }
51
52  const AttrConstraint& constraint() const
53  { return m_Constraint; }
54
55  // produce - produce a attribute, but do not record it yet.
56  // the produced attribute is identical to the pre-defined attribute.
57  AttributeProxy* produce();
58
59  // last - the last touched attribute.
60  AttributeProxy& last();
61  const AttributeProxy& last() const;
62
63  // exists- return the recorded attribute whose content is identical to the
64  // input attribute.
65  Attribute *exists(const Attribute& pAttr) const;
66
67  // record - record the attribute no mater if it has been recorded.
68  void record(Attribute& pAttr);
69
70  // -----  observers  ----- //
71  size_t size() const
72  { return m_AttrSet.size(); }
73
74  bool empty() const
75  { return m_AttrSet.empty(); }
76
77  // -----  iterators  ----- //
78  iterator begin()
79  { return m_AttrSet.begin(); }
80
81  iterator end()
82  { return m_AttrSet.end(); }
83
84  const_iterator begin() const
85  { return m_AttrSet.begin(); }
86
87  const_iterator end() const
88  { return m_AttrSet.end(); }
89
90private:
91  AttrSet m_AttrSet;
92  AttrConstraint m_Constraint;
93  AttributeProxy *m_pLast;
94};
95
96} // namespace of mcld
97
98#endif
99
100