LLVM API Documentation

ManagedStringPool.h
Go to the documentation of this file.
00001 //===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // The strings allocated from a managed string pool are owned by the string
00011 // pool and will be deleted together with the managed string pool.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
00016 #define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
00017 
00018 #include "llvm/ADT/SmallVector.h"
00019 #include <string>
00020 
00021 namespace llvm {
00022 
00023 /// ManagedStringPool - The strings allocated from a managed string pool are
00024 /// owned by the string pool and will be deleted together with the managed
00025 /// string pool.
00026 class ManagedStringPool {
00027   SmallVector<std::string *, 8> Pool;
00028 
00029 public:
00030   ManagedStringPool() {}
00031   ~ManagedStringPool() {
00032     SmallVectorImpl<std::string *>::iterator Current = Pool.begin();
00033     while (Current != Pool.end()) {
00034       delete *Current;
00035       Current++;
00036     }
00037   }
00038 
00039   std::string *getManagedString(const char *S) {
00040     std::string *Str = new std::string(S);
00041     Pool.push_back(Str);
00042     return Str;
00043   }
00044 };
00045 
00046 }
00047 
00048 #endif