blob: a2d670f8d39d282392cbae25db6df1df7d608a0a [file] [log] [blame]
Justin Holewinskiae556d32012-05-04 20:18:50 +00001//===-- 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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000015#ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
16#define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
Justin Holewinskiae556d32012-05-04 20:18:50 +000017
18#include "llvm/ADT/SmallVector.h"
19#include <string>
20
21namespace llvm {
22
23/// ManagedStringPool - The strings allocated from a managed string pool are
24/// owned by the string pool and will be deleted together with the managed
25/// string pool.
26class ManagedStringPool {
27 SmallVector<std::string *, 8> Pool;
28
29public:
30 ManagedStringPool() {}
31 ~ManagedStringPool() {
Craig Topperaf0dea12013-07-04 01:31:24 +000032 SmallVectorImpl<std::string *>::iterator Current = Pool.begin();
Justin Holewinskiae556d32012-05-04 20:18:50 +000033 while (Current != Pool.end()) {
34 delete *Current;
35 Current++;
36 }
37 }
38
39 std::string *getManagedString(const char *S) {
40 std::string *Str = new std::string(S);
41 Pool.push_back(Str);
42 return Str;
43 }
44};
45
Alexander Kornienkof00654e2015-06-23 09:49:53 +000046}
Justin Holewinskiae556d32012-05-04 20:18:50 +000047
48#endif