CXString.h revision 15a2aa0954bcf38411c14cf67c65e336022a7a1b
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
23namespace clang {
24namespace cxstring {
25
26struct CXStringBuf;
27
28/// \brief Create a CXString object for an empty "" string.
29CXString createEmpty();
30
31/// \brief Create a CXString object for an NULL string.
32///
33/// A NULL string should be used as an "invalid" value in case of errors.
34CXString createNull();
35
36/// \brief Create a CXString object from a C string.
37CXString createCXString(const char *String, bool DupString = false);
38
39/// \brief Create a CXString object from a StringRef.
40CXString createCXString(StringRef String, bool DupString = true);
41
42/// \brief Create a CXString object that is backed by a string buffer.
43CXString createCXString(CXStringBuf *buf);
44
45/// \brief A string pool used for fast allocation/deallocation of strings.
46class CXStringPool {
47public:
48  ~CXStringPool();
49
50  CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
51
52private:
53  std::vector<CXStringBuf *> Pool;
54
55  friend struct CXStringBuf;
56};
57
58struct CXStringBuf {
59  SmallString<128> Data;
60  CXTranslationUnit TU;
61
62  CXStringBuf(CXTranslationUnit TU) : TU(TU) {}
63
64  /// \brief Return this buffer to the pool.
65  void dispose();
66};
67
68CXStringBuf *getCXStringBuf(CXTranslationUnit TU);
69
70/// \brief Returns true if the CXString data is managed by a pool.
71bool isManagedByPool(CXString str);
72
73}
74}
75
76#endif
77
78