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