2014-01-13 14:08:43 -05:00
|
|
|
// Copyright (C) 2013 Google Inc.
|
2013-05-25 14:43:14 -04:00
|
|
|
//
|
|
|
|
// This file is part of YouCompleteMe.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// YouCompleteMe is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with YouCompleteMe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef IDENTIFIERDATABASE_H_ZESX3CVR
|
|
|
|
#define IDENTIFIERDATABASE_H_ZESX3CVR
|
|
|
|
|
|
|
|
#include <boost/utility.hpp>
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
#include <boost/thread/mutex.hpp>
|
|
|
|
#include <boost/shared_ptr.hpp>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2013-05-26 16:28:00 -04:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2013-05-25 14:43:14 -04:00
|
|
|
|
|
|
|
namespace YouCompleteMe {
|
|
|
|
|
|
|
|
class Candidate;
|
|
|
|
class Result;
|
|
|
|
class CandidateRepository;
|
|
|
|
|
|
|
|
|
2013-05-26 16:28:00 -04:00
|
|
|
// filepath -> identifiers
|
|
|
|
typedef std::map< std::string, std::vector< std::string > >
|
2013-05-30 01:23:19 -04:00
|
|
|
FilepathToIdentifiers;
|
2013-05-26 16:28:00 -04:00
|
|
|
|
|
|
|
// filetype -> (filepath -> identifiers)
|
|
|
|
typedef std::map< std::string, FilepathToIdentifiers >
|
2013-05-30 01:23:19 -04:00
|
|
|
FiletypeIdentifierMap;
|
2013-05-26 16:28:00 -04:00
|
|
|
|
|
|
|
|
2013-05-25 14:43:14 -04:00
|
|
|
// This class stores the database of identifiers the identifier completer has
|
|
|
|
// seen. It stores them in a data structure that makes it easy to tell which
|
|
|
|
// identifier came from which file and what files have which filetypes.
|
|
|
|
//
|
|
|
|
// The main point of this class is to isolate the parts of the code that need
|
|
|
|
// access to this internal data structure so that it's easier to confirm that
|
|
|
|
// mutexes are used correctly to protect concurrent access.
|
|
|
|
//
|
|
|
|
// This class is thread-safe.
|
|
|
|
class IdentifierDatabase : boost::noncopyable {
|
|
|
|
public:
|
|
|
|
IdentifierDatabase();
|
|
|
|
|
2013-05-26 16:28:00 -04:00
|
|
|
void AddIdentifiers( const FiletypeIdentifierMap &filetype_identifier_map );
|
|
|
|
|
|
|
|
void AddIdentifiers(
|
2013-05-25 14:43:14 -04:00
|
|
|
const std::vector< std::string > &new_candidates,
|
|
|
|
const std::string &filetype,
|
|
|
|
const std::string &filepath );
|
|
|
|
|
|
|
|
void ClearCandidatesStoredForFile( const std::string &filetype,
|
|
|
|
const std::string &filepath );
|
|
|
|
|
|
|
|
void ResultsForQueryAndType( const std::string &query,
|
|
|
|
const std::string &filetype,
|
|
|
|
std::vector< Result > &results ) const;
|
|
|
|
|
|
|
|
private:
|
2013-05-26 16:28:00 -04:00
|
|
|
std::set< const Candidate * > &GetCandidateSet(
|
2013-05-25 14:43:14 -04:00
|
|
|
const std::string &filetype,
|
|
|
|
const std::string &filepath );
|
|
|
|
|
2013-05-26 16:28:00 -04:00
|
|
|
void AddIdentifiersNoLock(
|
|
|
|
const std::vector< std::string > &new_candidates,
|
|
|
|
const std::string &filetype,
|
|
|
|
const std::string &filepath );
|
|
|
|
|
|
|
|
|
2013-05-25 14:43:14 -04:00
|
|
|
// filepath -> *( *candidate )
|
|
|
|
typedef boost::unordered_map < std::string,
|
2013-05-26 16:28:00 -04:00
|
|
|
boost::shared_ptr< std::set< const Candidate * > > >
|
2013-05-25 14:43:14 -04:00
|
|
|
FilepathToCandidates;
|
|
|
|
|
|
|
|
// filetype -> *( filepath -> *( *candidate ) )
|
|
|
|
typedef boost::unordered_map < std::string,
|
2013-05-26 16:28:00 -04:00
|
|
|
boost::shared_ptr< FilepathToCandidates > > FiletypeCandidateMap;
|
2013-05-25 14:43:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
CandidateRepository &candidate_repository_;
|
|
|
|
|
2013-05-26 16:28:00 -04:00
|
|
|
FiletypeCandidateMap filetype_candidate_map_;
|
|
|
|
mutable boost::mutex filetype_candidate_map_mutex_;
|
2013-05-25 14:43:14 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace YouCompleteMe
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* end of include guard: IDENTIFIERDATABASE_H_ZESX3CVR */
|
|
|
|
|