mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-09 13:33:17 +00:00
Make StringMap to be more STL'ish. Patch by Mikhail Glushenkov!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46612 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
75fb496fc6
commit
f429a519c8
@ -126,23 +126,26 @@ public:
|
|||||||
/// and data.
|
/// and data.
|
||||||
template<typename ValueTy>
|
template<typename ValueTy>
|
||||||
class StringMapEntry : public StringMapEntryBase {
|
class StringMapEntry : public StringMapEntryBase {
|
||||||
ValueTy Val;
|
|
||||||
public:
|
public:
|
||||||
|
ValueTy second;
|
||||||
|
|
||||||
explicit StringMapEntry(unsigned StrLen)
|
explicit StringMapEntry(unsigned StrLen)
|
||||||
: StringMapEntryBase(StrLen), Val() {}
|
: StringMapEntryBase(StrLen), second() {}
|
||||||
StringMapEntry(unsigned StrLen, const ValueTy &V)
|
StringMapEntry(unsigned StrLen, const ValueTy &V)
|
||||||
: StringMapEntryBase(StrLen), Val(V) {}
|
: StringMapEntryBase(StrLen), second(V) {}
|
||||||
|
|
||||||
const ValueTy &getValue() const { return Val; }
|
const ValueTy &getValue() const { return second; }
|
||||||
ValueTy &getValue() { return Val; }
|
ValueTy &getValue() { return second; }
|
||||||
|
|
||||||
void setValue(const ValueTy &V) { Val = V; }
|
void setValue(const ValueTy &V) { second = V; }
|
||||||
|
|
||||||
/// getKeyData - Return the start of the string data that is the key for this
|
/// getKeyData - Return the start of the string data that is the key for this
|
||||||
/// value. The string data is always stored immediately after the
|
/// value. The string data is always stored immediately after the
|
||||||
/// StringMapEntry object.
|
/// StringMapEntry object.
|
||||||
const char *getKeyData() const {return reinterpret_cast<const char*>(this+1);}
|
const char *getKeyData() const {return reinterpret_cast<const char*>(this+1);}
|
||||||
|
|
||||||
|
const char *first() const { return getKeyData(); }
|
||||||
|
|
||||||
/// Create - Create a StringMapEntry for the specified key and default
|
/// Create - Create a StringMapEntry for the specified key and default
|
||||||
/// construct the value.
|
/// construct the value.
|
||||||
template<typename AllocatorTy, typename InitType>
|
template<typename AllocatorTy, typename InitType>
|
||||||
@ -239,6 +242,11 @@ public:
|
|||||||
AllocatorTy &getAllocator() { return Allocator; }
|
AllocatorTy &getAllocator() { return Allocator; }
|
||||||
const AllocatorTy &getAllocator() const { return Allocator; }
|
const AllocatorTy &getAllocator() const { return Allocator; }
|
||||||
|
|
||||||
|
typedef const char* key_type;
|
||||||
|
typedef ValueTy mapped_type;
|
||||||
|
typedef StringMapEntry<ValueTy> value_type;
|
||||||
|
typedef size_t size_type;
|
||||||
|
|
||||||
typedef StringMapConstIterator<ValueTy> const_iterator;
|
typedef StringMapConstIterator<ValueTy> const_iterator;
|
||||||
typedef StringMapIterator<ValueTy> iterator;
|
typedef StringMapIterator<ValueTy> iterator;
|
||||||
|
|
||||||
@ -267,6 +275,25 @@ public:
|
|||||||
return const_iterator(TheTable+Bucket);
|
return const_iterator(TheTable+Bucket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iterator find(const char *Key) {
|
||||||
|
return find(Key, Key + strlen(Key));
|
||||||
|
}
|
||||||
|
const_iterator find(const char *Key) const {
|
||||||
|
return find(Key, Key + strlen(Key));
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueTy& operator[](const char *Key) {
|
||||||
|
value_type& entry = GetOrCreateValue(Key, Key + strlen(Key));
|
||||||
|
return entry.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_type count(const char *KeyStart, const char *KeyEnd) const {
|
||||||
|
return find(KeyStart, KeyEnd) == end() ? 0 : 1;
|
||||||
|
}
|
||||||
|
size_type count(const char *Key) const {
|
||||||
|
return count(Key, Key + strlen(Key));
|
||||||
|
}
|
||||||
|
|
||||||
/// insert - Insert the specified key/value pair into the map. If the key
|
/// insert - Insert the specified key/value pair into the map. If the key
|
||||||
/// already exists in the map, return false and ignore the request, otherwise
|
/// already exists in the map, return false and ignore the request, otherwise
|
||||||
/// insert it and return true.
|
/// insert it and return true.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user