LLVM API Documentation
00001 //===--- StringSet.h - The LLVM Compiler Driver -----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open 00006 // Source License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // StringSet - A set-like wrapper for the StringMap. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ADT_STRINGSET_H 00015 #define LLVM_ADT_STRINGSET_H 00016 00017 #include "llvm/ADT/StringMap.h" 00018 00019 namespace llvm { 00020 00021 /// StringSet - A wrapper for StringMap that provides set-like functionality. 00022 template <class AllocatorTy = llvm::MallocAllocator> 00023 class StringSet : public llvm::StringMap<char, AllocatorTy> { 00024 typedef llvm::StringMap<char, AllocatorTy> base; 00025 public: 00026 00027 /// insert - Insert the specified key into the set. If the key already 00028 /// exists in the set, return false and ignore the request, otherwise insert 00029 /// it and return true. 00030 bool insert(StringRef Key) { 00031 // Get or create the map entry for the key; if it doesn't exist the value 00032 // type will be default constructed which we use to detect insert. 00033 // 00034 // We use '+' as the sentinel value in the map. 00035 assert(!Key.empty()); 00036 StringMapEntry<char> &Entry = this->GetOrCreateValue(Key); 00037 if (Entry.getValue() == '+') 00038 return false; 00039 Entry.setValue('+'); 00040 return true; 00041 } 00042 }; 00043 } 00044 00045 #endif // LLVM_ADT_STRINGSET_H