1 //===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // The strings allocated from a managed string pool are owned by the string 11 // pool and will be deleted together with the managed string pool. 12 // 13 //===----------------------------------------------------------------------===// 14 15 16 #ifndef LLVM_SUPPORT_MANAGED_STRING_H 17 #define LLVM_SUPPORT_MANAGED_STRING_H 18 19 #include "llvm/ADT/SmallVector.h" 20 #include <string> 21 22 namespace llvm { 23 24 /// ManagedStringPool - The strings allocated from a managed string pool are 25 /// owned by the string pool and will be deleted together with the managed 26 /// string pool. 27 class ManagedStringPool { 28 SmallVector<std::string *, 8> Pool; 29 30 public: 31 ManagedStringPool() {} 32 ~ManagedStringPool() { 33 SmallVector<std::string *, 8>::iterator Current = Pool.begin(); 34 while (Current != Pool.end()) { 35 delete *Current; 36 Current++; 37 } 38 } 39 40 std::string *getManagedString(const char *S) { 41 std::string *Str = new std::string(S); 42 Pool.push_back(Str); 43 return Str; 44 } 45 }; 46 47 } 48 49 #endif 50