15460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===- AttributeFactory.h -------------------------------------------------===//
25460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
35460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//                     The MCLinker Project
45460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
55460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// This file is distributed under the University of Illinois Open Source
65460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao// License. See LICENSE.TXT for details.
75460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//
85460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao//===----------------------------------------------------------------------===//
95460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifndef MCLD_ATTRIBUTE_FACTORY_H
105460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#define MCLD_ATTRIBUTE_FACTORY_H
115460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#ifdef ENABLE_UNITTEST
125460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#include <gtest.h>
135460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif
14affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <mcld/ADT/Uncopyable.h>
15affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <mcld/MC/MCLDAttribute.h>
165460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
175460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaonamespace mcld
185460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
195460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
205460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao/** \class AttributeFactory
215460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  \brief AttributeFactory contructs the AttributeProxys.
225460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *
235460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  Since the number of AttributeProxys is usually small, sequential search
245460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao *  on a small vector is enough.
255460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao */
265460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoclass AttributeFactory : private Uncopyable
275460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao{
285460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate:
295460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  typedef std::vector<Attribute*> AttrSet;
305460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
315460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
325460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  typedef AttrSet::iterator iterator;
335460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  typedef AttrSet::const_iterator const_iterator;
345460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
355460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaopublic:
365460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  AttributeFactory();
375460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  explicit AttributeFactory(size_t pNum);
385460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  ~AttributeFactory();
395460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
405460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // reserve - reserve the memory space for attributes
415460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // @param pNum the number of reserved attributes
425460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void reserve(size_t pNum);
435460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
445460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // predefined - return the predefined attribute
455460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  Attribute& predefined();
465460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const Attribute& predefined() const;
475460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
485460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // constraint - return the constraint of attributes
495460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  AttrConstraint& constraint()
505460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_Constraint; }
515460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
525460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const AttrConstraint& constraint() const
535460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_Constraint; }
545460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
555460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // produce - produce a attribute, but do not record it yet.
565460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // the produced attribute is identical to the pre-defined attribute.
575460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  AttributeProxy* produce();
585460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
595460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // last - the last touched attribute.
605460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  AttributeProxy& last();
615460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const AttributeProxy& last() const;
625460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
635460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // exists- return the recorded attribute whose content is identical to the
645460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // input attribute.
655460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  Attribute *exists(const Attribute& pAttr) const;
665460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
675460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // record - record the attribute no mater if it has been recorded.
685460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  void record(Attribute& pAttr);
695460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
705460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // -----  observers  ----- //
715460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  size_t size() const
725460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_AttrSet.size(); }
735460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
745460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  bool empty() const
755460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_AttrSet.empty(); }
765460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
775460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  // -----  iterators  ----- //
785460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  iterator begin()
795460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_AttrSet.begin(); }
805460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
815460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  iterator end()
825460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_AttrSet.end(); }
835460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
845460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const_iterator begin() const
855460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_AttrSet.begin(); }
865460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
875460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  const_iterator end() const
885460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  { return m_AttrSet.end(); }
895460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
905460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liaoprivate:
915460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  AttrSet m_AttrSet;
925460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  AttrConstraint m_Constraint;
935460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao  AttributeProxy *m_pLast;
945460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao};
955460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
965460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao} // namespace of mcld
975460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
985460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao#endif
995460a1f25d9ddecb5c70667267d66d51af177a99Shih-wei Liao
100