ManagedStringPool.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===-- ManagedStringPool.h - Managed String Pool ---------------*- C++ -*-===//
  2. //
  3. // 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
  6. //
  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. #ifndef LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
  14. #define LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H
  15. #include "llvm/ADT/SmallVector.h"
  16. #include <string>
  17. namespace llvm {
  18. /// ManagedStringPool - The strings allocated from a managed string pool are
  19. /// owned by the string pool and will be deleted together with the managed
  20. /// string pool.
  21. class ManagedStringPool {
  22. SmallVector<std::string *, 8> Pool;
  23. public:
  24. ManagedStringPool() = default;
  25. ~ManagedStringPool() {
  26. SmallVectorImpl<std::string *>::iterator Current = Pool.begin();
  27. while (Current != Pool.end()) {
  28. delete *Current;
  29. ++Current;
  30. }
  31. }
  32. std::string *getManagedString(const char *S) {
  33. std::string *Str = new std::string(S);
  34. Pool.push_back(Str);
  35. return Str;
  36. }
  37. };
  38. } // end namespace llvm
  39. #endif // LLVM_LIB_TARGET_NVPTX_MANAGEDSTRINGPOOL_H