1
0

CandidateRepository.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright (C) 2011, 2012 Google Inc.
  2. //
  3. // This file is part of YouCompleteMe.
  4. //
  5. // YouCompleteMe is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // YouCompleteMe is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
  17. #ifndef CANDIDATEREPOSITORY_H_K9OVCMHG
  18. #define CANDIDATEREPOSITORY_H_K9OVCMHG
  19. #include <boost/utility.hpp>
  20. #include <boost/unordered_map.hpp>
  21. #include <boost/thread/mutex.hpp>
  22. #include <vector>
  23. #include <string>
  24. namespace YouCompleteMe {
  25. class Candidate;
  26. struct CompletionData;
  27. typedef boost::unordered_map< std::string, const Candidate * >
  28. CandidateHolder;
  29. // This singleton stores already built Candidate objects for candidate strings
  30. // that were already seen. If Candidates are requested for previously unseen
  31. // strings, new Candidate objects are built.
  32. //
  33. // This is shared by the identifier completer and the clang completer so that
  34. // work is not repeated.
  35. //
  36. // This class is thread-safe.
  37. class CandidateRepository : boost::noncopyable {
  38. public:
  39. static CandidateRepository &Instance();
  40. int NumStoredCandidates();
  41. std::vector< const Candidate * > GetCandidatesForStrings(
  42. const std::vector< std::string > &strings );
  43. #ifdef USE_CLANG_COMPLETER
  44. std::vector< const Candidate * > GetCandidatesForStrings(
  45. const std::vector< CompletionData > &datas );
  46. #endif // USE_CLANG_COMPLETER
  47. private:
  48. CandidateRepository() {};
  49. ~CandidateRepository();
  50. boost::mutex holder_mutex_;
  51. static boost::mutex singleton_mutex_;
  52. static CandidateRepository *instance_;
  53. const std::string empty_;
  54. // This data structure owns all the Candidate pointers
  55. CandidateHolder candidate_holder_;
  56. };
  57. } // namespace YouCompleteMe
  58. #endif /* end of include guard: CANDIDATEREPOSITORY_H_K9OVCMHG */