Home | History | Annotate | Download | only in MC
      1 //===- AttributeFactory.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_ATTRIBUTE_FACTORY_H
     10 #define MCLD_ATTRIBUTE_FACTORY_H
     11 #ifdef ENABLE_UNITTEST
     12 #include <gtest.h>
     13 #endif
     14 #include "mcld/ADT/Uncopyable.h"
     15 #include "mcld/MC/MCLDAttribute.h"
     16 
     17 namespace mcld
     18 {
     19 
     20 /** \class AttributeFactory
     21  *  \brief AttributeFactory contructs the AttributeProxys.
     22  *
     23  *  Since the number of AttributeProxys is usually small, sequential search
     24  *  on a small vector is enough.
     25  */
     26 class AttributeFactory : private Uncopyable
     27 {
     28 private:
     29   typedef std::vector<Attribute*> AttrSet;
     30 
     31 public:
     32   typedef AttrSet::iterator iterator;
     33   typedef AttrSet::const_iterator const_iterator;
     34 
     35 public:
     36   AttributeFactory();
     37   explicit AttributeFactory(size_t pNum);
     38   ~AttributeFactory();
     39 
     40   // reserve - reserve the memory space for attributes
     41   // @param pNum the number of reserved attributes
     42   void reserve(size_t pNum);
     43 
     44   // predefined - return the predefined attribute
     45   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 
     90 private:
     91   AttrSet m_AttrSet;
     92   AttrConstraint m_Constraint;
     93   AttributeProxy *m_pLast;
     94 };
     95 
     96 } // namespace of mcld
     97 
     98 #endif
     99 
    100