template<typename ValueTy>
class StringMapEntry;
-/// StringMapEntryInitializer - This datatype can be partially specialized for
-/// various datatypes in a stringmap to allow them to be initialized when an
-/// entry is default constructed for the map.
-template<typename ValueTy>
-class StringMapEntryInitializer {
-public:
- template <typename InitTy>
- static void Initialize(StringMapEntry<ValueTy> &T, InitTy InitVal) {
- T.second = InitVal;
- }
-};
-
-
/// StringMapEntryBase - Shared base class of StringMapEntry instances.
class StringMapEntryBase {
unsigned StrLen;
/// and data.
template<typename ValueTy>
class StringMapEntry : public StringMapEntryBase {
+ StringMapEntry(StringMapEntry &E) LLVM_DELETED_FUNCTION;
public:
ValueTy second;
InitType InitVal) {
unsigned KeyLength = static_cast<unsigned>(KeyEnd-KeyStart);
- // Okay, the item doesn't already exist, and 'Bucket' is the bucket to fill
- // in. Allocate a new item with space for the string at the end and a null
+ // Allocate a new item with space for the string at the end and a null
// terminator.
-
unsigned AllocSize = static_cast<unsigned>(sizeof(StringMapEntry))+
KeyLength+1;
unsigned Alignment = alignOf<StringMapEntry>();
static_cast<StringMapEntry*>(Allocator.Allocate(AllocSize,Alignment));
// Default construct the value.
- new (NewItem) StringMapEntry(KeyLength);
+ new (NewItem) StringMapEntry(KeyLength, InitVal);
// Copy the string information.
char *StrBuffer = const_cast<char*>(NewItem->getKeyData());
memcpy(StrBuffer, KeyStart, KeyLength);
StrBuffer[KeyLength] = 0; // Null terminate for convenience of clients.
-
- // Initialize the value if the client wants to.
- StringMapEntryInitializer<ValueTy>::Initialize(*NewItem, InitVal);
return NewItem;
}
return GetOrCreateValue(Key).getValue();
}
+ /// count - Return 1 if the element is in the map, 0 otherwise.
size_type count(StringRef Key) const {
return find(Key) == end() ? 0 : 1;
}