1239310Sdim//===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===//
2239310Sdim//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6239310Sdim//
7239310Sdim//===----------------------------------------------------------------------===//
8239310Sdim//
9239310Sdim// The strings allocated from a managed string pool are owned by the string
10239310Sdim// pool and will be deleted together with the managed string pool.
11239310Sdim//
12239310Sdim//===----------------------------------------------------------------------===//
13239310Sdim
14280031Sdim#ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
15280031Sdim#define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
16239310Sdim
17239310Sdim#include "llvm/ADT/SmallVector.h"
18239310Sdim#include <string>
19239310Sdim
20239310Sdimnamespace llvm {
21239310Sdim
22239310Sdim/// ManagedStringPool - The strings allocated from a managed string pool are
23239310Sdim/// owned by the string pool and will be deleted together with the managed
24239310Sdim/// string pool.
25239310Sdimclass ManagedStringPool {
26239310Sdim  SmallVector<std::string *, 8> Pool;
27239310Sdim
28239310Sdimpublic:
29314564Sdim  ManagedStringPool() = default;
30314564Sdim
31239310Sdim  ~ManagedStringPool() {
32261991Sdim    SmallVectorImpl<std::string *>::iterator Current = Pool.begin();
33239310Sdim    while (Current != Pool.end()) {
34239310Sdim      delete *Current;
35360784Sdim      ++Current;
36239310Sdim    }
37239310Sdim  }
38239310Sdim
39239310Sdim  std::string *getManagedString(const char *S) {
40239310Sdim    std::string *Str = new std::string(S);
41239310Sdim    Pool.push_back(Str);
42239310Sdim    return Str;
43239310Sdim  }
44239310Sdim};
45239310Sdim
46314564Sdim} // end namespace llvm
47239310Sdim
48314564Sdim#endif // LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
49