LLVM  6.0.0svn
StringSaver.h
Go to the documentation of this file.
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
20 /// StringRef with a stable character pointer.
21 class StringSaver final {
22  BumpPtrAllocator &Alloc;
23 
24 public:
25  StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
26  StringRef save(const char *S) { return save(StringRef(S)); }
28  StringRef save(const Twine &S) { return save(StringRef(S.str())); }
29  StringRef save(const std::string &S) { return save(StringRef(S)); }
30 };
31 }
32 #endif
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
StringSaver(BumpPtrAllocator &Alloc)
Definition: StringSaver.h:25
StringRef save(const Twine &S)
Definition: StringSaver.h:28
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:138
StringRef save(const char *S)
Definition: StringSaver.h:26
Saves strings in the inheritor's stable storage and returns a StringRef with a stable character point...
Definition: StringSaver.h:21
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
StringRef save(const std::string &S)
Definition: StringSaver.h:29