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