1 //===- llvm/Support/StringSaver.h -------------------------------*- 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 #ifndef LLVM_SUPPORT_STRINGSAVER_H 11 #define LLVM_SUPPORT_STRINGSAVER_H 12 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/ADT/Twine.h" 15 #include "llvm/Support/Allocator.h" 16 17 namespace llvm { 18 19 /// \brief Saves strings in the inheritor's stable storage and returns a stable 20 /// raw character pointer. 21 class StringSaver final { 22 BumpPtrAllocator &Alloc; 23 24 public: 25 StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {} 26 const char *save(const char *S) { return save(StringRef(S)); } 27 const char *save(StringRef S); 28 const char *save(const Twine &S) { return save(StringRef(S.str())); } 29 const char *save(std::string &S) { return save(StringRef(S)); } 30 }; 31 } 32 #endif 33