Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 1 | //===-- 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 Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 15 | #ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H |
| 16 | #define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 17 | |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include <string> |
| 20 | |
| 21 | namespace 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. |
| 26 | class ManagedStringPool { |
| 27 | SmallVector<std::string *, 8> Pool; |
| 28 | |
| 29 | public: |
Eugene Zelenko | c9f1f6b | 2017-01-09 22:16:51 +0000 | [diff] [blame] | 30 | ManagedStringPool() = default; |
| 31 | |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 32 | ~ManagedStringPool() { |
Craig Topper | af0dea1 | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 33 | SmallVectorImpl<std::string *>::iterator Current = Pool.begin(); |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 34 | while (Current != Pool.end()) { |
| 35 | delete *Current; |
| 36 | Current++; |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | std::string *getManagedString(const char *S) { |
| 41 | std::string *Str = new std::string(S); |
| 42 | Pool.push_back(Str); |
| 43 | return Str; |
| 44 | } |
| 45 | }; |
| 46 | |
Eugene Zelenko | c9f1f6b | 2017-01-09 22:16:51 +0000 | [diff] [blame] | 47 | } // end namespace llvm |
Justin Holewinski | ae556d3 | 2012-05-04 20:18:50 +0000 | [diff] [blame] | 48 | |
Eugene Zelenko | c9f1f6b | 2017-01-09 22:16:51 +0000 | [diff] [blame] | 49 | #endif // LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H |