clang-tags
C/C++ source code indexing tool based on libclang
 All Classes Functions Variables Typedefs Groups Pages
unsavedFiles.hxx
1 #pragma once
2 
3 #include <sstream>
4 #include <fstream>
5 #include <vector>
6 
7 namespace LibClang {
8 
13  class UnsavedFiles {
14  public:
24  void add (const std::string sourcePath, const std::string bufferPath)
25  {
26  const int bufsize = 4096;
27  char *buf = new char[bufsize];
28 
29  std::ostringstream contents;
30  std::ifstream buffer (bufferPath);
31  do {
32  buffer.get (buf, bufsize, 0);
33  contents << buf;
34  } while (! buffer.eof());
35 
36  delete[] buf;
37 
38  sourcePath_.push_back (sourcePath);
39  contents_.push_back (contents.str());
40  unsavedFile_.resize (sourcePath_.size());
41 
42  CXUnsavedFile & unsavedFile = unsavedFile_.back();
43  unsavedFile.Filename = sourcePath_.back().c_str();
44  unsavedFile.Contents = contents_.back().c_str();
45  unsavedFile.Length = contents_.back().size();
46  }
47 
52  unsigned int size () const {
53  return sourcePath_.size();
54  }
55 
60  CXUnsavedFile * begin () {
61  return &(unsavedFile_[0]);
62  }
63 
64  private:
65  std::vector<std::string> sourcePath_;
66  std::vector<std::string> contents_;
67  std::vector<CXUnsavedFile> unsavedFile_;
68  };
69 }