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 // StringEntryFactory 34 template <typename DataType> 35 StringEntryFactory<DataType>::StringEntryFactory() { 36 } 37 38 template <typename DataType> 39 StringEntryFactory<DataType>::~StringEntryFactory() { 40 } 41 42 template <typename DataType> 43 StringEntry<DataType>* StringEntryFactory<DataType>::produce( 44 const typename StringEntryFactory<DataType>::key_type& pKey) { 45 StringEntry<DataType>* result = static_cast<StringEntry<DataType>*>( 46 malloc(sizeof(StringEntry<DataType>) + pKey.size() + 1)); 47 48 if (result == NULL) 49 return NULL; 50 51 size_t len = pKey.size(); 52 new (result) StringEntry<DataType>(); 53 std::memcpy(result->m_Key, pKey.data(), len); 54 result->m_Key[len] = '\0'; 55 result->m_KeyLen = len; 56 return result; 57 } 58 59 template <typename DataType> 60 void StringEntryFactory<DataType>::destroy(StringEntry<DataType>* pEntry) { 61 if (pEntry != NULL) { 62 pEntry->~StringEntry<DataType>(); 63 free(pEntry); 64 } 65 } 66