]> granicus.if.org Git - clang/blob - tools/libclang/CXString.h
libclang: itroduce cxstring::createEmpty()
[clang] / tools / libclang / CXString.h
1 //===- CXString.h - Routines for manipulating CXStrings -------------------===//
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 // This file defines routines for manipulating CXStrings.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_CXSTRING_H
15 #define LLVM_CLANG_CXSTRING_H
16
17 #include "clang-c/Index.h"
18 #include "clang/Basic/LLVM.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/StringRef.h"
21 #include <vector>
22
23 namespace clang {
24 namespace cxstring {
25
26 struct CXStringBuf;
27
28 /// \brief Create a CXString object for an empty "" string.
29 CXString createEmpty();
30
31 /// \brief Create a CXString object for an NULL string.
32 CXString createNull();
33
34 /// \brief Create a CXString object from a C string.
35 CXString createCXString(const char *String, bool DupString = false);
36
37 /// \brief Create a CXString object from a StringRef.
38 CXString createCXString(StringRef String, bool DupString = true);
39
40 /// \brief Create a CXString object that is backed by a string buffer.
41 CXString createCXString(CXStringBuf *buf);
42
43 /// \brief A string pool used for fast allocation/deallocation of strings.
44 class CXStringPool {
45 public:
46   ~CXStringPool();
47
48   CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
49
50 private:
51   std::vector<CXStringBuf *> Pool;
52
53   friend struct CXStringBuf;
54 };
55
56 struct CXStringBuf {
57   SmallString<128> Data;
58   CXTranslationUnit TU;
59
60   CXStringBuf(CXTranslationUnit TU) : TU(TU) {}
61
62   /// \brief Return this buffer to the pool.
63   void dispose();
64 };
65
66 CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
67
68 /// \brief Returns true if the CXString data is managed by a pool.
69 bool isManagedByPool(CXString str);
70
71 }
72 }
73
74 #endif
75