blob: bbcbb459804047ddd25bf6a11da60a1ccc4a5a24 [file] [log] [blame]
Justin Holewinskiae556d32012-05-04 20:18:50 +00001//===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Justin Holewinskiae556d32012-05-04 20:18:50 +00006//
7//===----------------------------------------------------------------------===//
8//
9// The strings allocated from a managed string pool are owned by the string
10// pool and will be deleted together with the managed string pool.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
15#define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
Justin Holewinskiae556d32012-05-04 20:18:50 +000016
17#include "llvm/ADT/SmallVector.h"
18#include <string>
19
20namespace llvm {
21
22/// ManagedStringPool - The strings allocated from a managed string pool are
23/// owned by the string pool and will be deleted together with the managed
24/// string pool.
25class ManagedStringPool {
26 SmallVector<std::string *, 8> Pool;
27
28public:
Eugene Zelenkoc9f1f6b2017-01-09 22:16:51 +000029 ManagedStringPool() = default;
30
Justin Holewinskiae556d32012-05-04 20:18:50 +000031 ~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
Eugene Zelenkoc9f1f6b2017-01-09 22:16:51 +000046} // end namespace llvm
Justin Holewinskiae556d32012-05-04 20:18:50 +000047
Eugene Zelenkoc9f1f6b2017-01-09 22:16:51 +000048#endif // LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H