LLVM  3.7.0
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 stable
20 /// raw character pointer.
21 class StringSaver {
22 protected:
24  virtual const char *saveImpl(StringRef S);
25 
26 public:
27  StringSaver(BumpPtrAllocator &Alloc) : Alloc(Alloc) {}
28  const char *save(const char *S) { return save(StringRef(S)); }
29  const char *save(StringRef S) { return saveImpl(S); }
30  const char *save(const Twine &S) { return save(StringRef(S.str())); }
31  const char *save(std::string &S) { return save(StringRef(S)); }
32 
33 private:
34  BumpPtrAllocator &Alloc;
35 };
36 
37 class BumpPtrStringSaver final : public StringSaver {
38 public:
40 };
41 }
42 #endif
const char * save(StringRef S)
Definition: StringSaver.h:29
const char * save(const Twine &S)
Definition: StringSaver.h:30
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:16
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
StringSaver(BumpPtrAllocator &Alloc)
Definition: StringSaver.h:27
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:135
const char * save(const char *S)
Definition: StringSaver.h:28
BumpPtrStringSaver(BumpPtrAllocator &Alloc)
Definition: StringSaver.h:39
Saves strings in the inheritor's stable storage and returns a stable raw character pointer...
Definition: StringSaver.h:21
const char * save(std::string &S)
Definition: StringSaver.h:31
virtual const char * saveImpl(StringRef S)
Definition: StringSaver.cpp:14
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40