Home | History | Annotate | Download | only in Target
      1 //===- ELFAttributeValue.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_TARGET_ELFATTRIBUTEVALUE_H
     10 #define MCLD_TARGET_ELFATTRIBUTEVALUE_H
     11 
     12 #include <string>
     13 
     14 namespace mcld
     15 {
     16 
     17 /** \class ELFAttributeValue
     18  *  \brief ELFAttributeValue stroes the value of an attribute tag. The attribtue
     19  *  tag itself is not stored in this object.
     20  */
     21 class ELFAttributeValue
     22 {
     23 public:
     24   // Type of value that an attribute tag holds.
     25   enum Type {
     26     // The value contains no data and has unknown type.
     27     Uninitialized = 0,
     28 
     29     // The value contains integer data.
     30     Int           = 1L << 0,
     31 
     32     // The value contains string data.
     33     String        = 1L << 1,
     34 
     35     // This is for attribute in which "default value" (0 for int type and empty
     36     // string for string type) has special meaning for them. That is, the
     37     // default value is "disabled" and meaningful for those attribute.
     38     NoDefault     = 1L << 2,
     39   };
     40 
     41 public:
     42   ELFAttributeValue()
     43     : m_Type(Uninitialized), m_IntValue(0), m_StringValue() { }
     44 
     45   ~ELFAttributeValue() { }
     46 
     47 public:
     48   unsigned int type() const
     49   { return m_Type; }
     50 
     51   void setType(unsigned int pType)
     52   { m_Type = pType; }
     53 
     54   unsigned int getIntValue() const
     55   { return m_IntValue; }
     56 
     57   void setIntValue(unsigned int pIntValue)
     58   { m_IntValue = pIntValue; }
     59 
     60   const std::string &getStringValue() const
     61   { return m_StringValue; }
     62 
     63   void setStringValue(const std::string &pStringValue)
     64   { m_StringValue = pStringValue; }
     65 
     66   void setStringValue(const char *pStringValue, size_t pSize)
     67   { m_StringValue.assign(pStringValue, pSize); }
     68 
     69   void setStringValue(const char *pStringValue)
     70   { m_StringValue.assign(pStringValue); }
     71 
     72   size_t getSize() const;
     73 
     74   inline bool isUninitialized() const
     75   { return (m_Type == Uninitialized); }
     76 
     77   inline bool isInitialized() const
     78   { return !isUninitialized(); }
     79 
     80   inline bool isIntValue() const
     81   { return (m_Type & Int); }
     82 
     83   inline bool isStringValue() const
     84   { return (m_Type & String); }
     85 
     86   inline bool hasNoDefault() const
     87   { return (m_Type & NoDefault); }
     88 
     89   bool isDefaultValue() const;
     90 
     91   // Returns true if this attribute value should be emitted to the output.
     92   inline bool shouldEmit() const {
     93     // Attribute with non-default value should be emitted.
     94     return !isDefaultValue();
     95   }
     96 
     97   bool equals(const ELFAttributeValue& pValue) const;
     98 
     99   bool operator==(const ELFAttributeValue& pValue) const
    100   { return equals(pValue); }
    101   bool operator!=(const ELFAttributeValue& pValue) const
    102   { return !equals(pValue); }
    103 
    104   /// reset - reset this value to the uninitialized state
    105   void reset()
    106   {
    107     m_Type = Uninitialized;
    108     m_IntValue = 0;
    109     m_StringValue.clear();
    110     return;
    111   }
    112 
    113 private:
    114   unsigned int m_Type;
    115 
    116   unsigned int m_IntValue;
    117   std::string m_StringValue;
    118 };
    119 
    120 } // namespace of mcld
    121 
    122 #endif
    123