xref: /netbsd-src/external/apache2/llvm/dist/llvm/lib/Target/NVPTX/ManagedStringPool.h (revision 82d56013d7b633d116a93943de88e08335357a7c)
17330f729Sjoerg //===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===//
27330f729Sjoerg //
37330f729Sjoerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
47330f729Sjoerg // See https://llvm.org/LICENSE.txt for license information.
57330f729Sjoerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67330f729Sjoerg //
77330f729Sjoerg //===----------------------------------------------------------------------===//
87330f729Sjoerg //
97330f729Sjoerg // The strings allocated from a managed string pool are owned by the string
107330f729Sjoerg // pool and will be deleted together with the managed string pool.
117330f729Sjoerg //
127330f729Sjoerg //===----------------------------------------------------------------------===//
137330f729Sjoerg 
147330f729Sjoerg #ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
157330f729Sjoerg #define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
167330f729Sjoerg 
177330f729Sjoerg #include "llvm/ADT/SmallVector.h"
187330f729Sjoerg #include <string>
197330f729Sjoerg 
207330f729Sjoerg namespace llvm {
217330f729Sjoerg 
227330f729Sjoerg /// ManagedStringPool - The strings allocated from a managed string pool are
237330f729Sjoerg /// owned by the string pool and will be deleted together with the managed
247330f729Sjoerg /// string pool.
257330f729Sjoerg class ManagedStringPool {
267330f729Sjoerg   SmallVector<std::string *, 8> Pool;
277330f729Sjoerg 
287330f729Sjoerg public:
297330f729Sjoerg   ManagedStringPool() = default;
307330f729Sjoerg 
~ManagedStringPool()317330f729Sjoerg   ~ManagedStringPool() {
327330f729Sjoerg     SmallVectorImpl<std::string *>::iterator Current = Pool.begin();
337330f729Sjoerg     while (Current != Pool.end()) {
347330f729Sjoerg       delete *Current;
35*82d56013Sjoerg       ++Current;
367330f729Sjoerg     }
377330f729Sjoerg   }
387330f729Sjoerg 
getManagedString(const char * S)397330f729Sjoerg   std::string *getManagedString(const char *S) {
407330f729Sjoerg     std::string *Str = new std::string(S);
417330f729Sjoerg     Pool.push_back(Str);
427330f729Sjoerg     return Str;
437330f729Sjoerg   }
447330f729Sjoerg };
457330f729Sjoerg 
467330f729Sjoerg } // end namespace llvm
477330f729Sjoerg 
487330f729Sjoerg #endif // LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
49