Home | History | Annotate | Download | only in ADT
      1 //===- StringEntry.tcc -----------------------------------------------------===//
      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 
     10 //===----------------------------------------------------------------------===//
     11 // StringEntry
     12 template<typename DataType>
     13 StringEntry<DataType>::StringEntry()
     14   : m_KeyLen(0) {
     15 }
     16 
     17 template<typename DataType>
     18 StringEntry<DataType>::StringEntry(const StringEntry::key_type& pKey)
     19   : m_KeyLen(pKey.size()) {
     20 }
     21 
     22 template<typename DataType>
     23 StringEntry<DataType>::StringEntry(const StringEntry<DataType>& pCopy)
     24   : m_KeyLen(pCopy.m_KeyLen), m_Value(pCopy.m_Value) {
     25   assert("Copy constructor of StringEntry should not be called!");
     26 }
     27 
     28 template<typename DataType>
     29 StringEntry<DataType>::~StringEntry()
     30 {
     31 }
     32 
     33 //===----------------------------------------------------------------------===//
     34 // StringEntryFactory
     35 template<typename DataType>
     36 StringEntryFactory<DataType>::StringEntryFactory()
     37 {
     38 }
     39 
     40 template<typename DataType>
     41 StringEntryFactory<DataType>::~StringEntryFactory()
     42 {
     43 }
     44 
     45 template<typename DataType>
     46 StringEntry<DataType>*
     47 StringEntryFactory<DataType>::produce(const typename StringEntryFactory<DataType>::key_type& pKey)
     48 {
     49   StringEntry<DataType>* result = static_cast<StringEntry<DataType>*>(
     50                            malloc(sizeof(StringEntry<DataType>) + pKey.size() + 1));
     51 
     52   if (NULL == result)
     53     return NULL;
     54 
     55   size_t len = pKey.size();
     56   new (result) StringEntry<DataType>();
     57   std::memcpy(result->m_Key, pKey.data(), len);
     58   result->m_Key[len] = '\0';
     59   result->m_KeyLen = len;
     60   return result;
     61 }
     62 
     63 template<typename DataType>
     64 void StringEntryFactory<DataType>::destroy(StringEntry<DataType>* pEntry)
     65 {
     66   if (NULL != pEntry) {
     67     pEntry->~StringEntry<DataType>();
     68     free(pEntry);
     69   }
     70 }
     71 
     72