Skip to content

Commit

Permalink
Adding const in a few more places
Browse files Browse the repository at this point in the history
  • Loading branch information
Valloric committed May 8, 2012
1 parent 0110611 commit d421c43
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 7 additions & 7 deletions cpp/Completer.cpp
Expand Up @@ -110,7 +110,7 @@ void Completer::AddCandidatesToDatabase(
const std::string &filetype,
const std::string &filepath )
{
std::vector< Candidate *> &candidates =
std::vector< const Candidate *> &candidates =
GetCandidateVector( filetype, filepath );

int num_candidates = new_candidates.size();
Expand All @@ -120,8 +120,8 @@ void Completer::AddCandidatesToDatabase(
for (int i = 0; i < num_candidates; ++i)
{
const std::string &candidate_text = new_candidates[ i ];
Candidate *&candidate = GetValueElseInsert( candidate_repository_,
candidate_text, NULL );
const Candidate *&candidate = GetValueElseInsert( candidate_repository_,
candidate_text, NULL );
if ( !candidate )
candidate = new Candidate( candidate_text );

Expand Down Expand Up @@ -199,7 +199,7 @@ void Completer::ResultsForQueryAndType( const std::string &query,
foreach ( const FilepathToCandidates::value_type &path_and_candidates,
*it->second )
{
foreach ( Candidate* candidate, *path_and_candidates.second )
foreach ( const Candidate* candidate, *path_and_candidates.second )
{
if ( !candidate->MatchesQueryBitset( query_bitset ) )
continue;
Expand All @@ -214,7 +214,7 @@ void Completer::ResultsForQueryAndType( const std::string &query,
}


std::vector< Candidate* >& Completer::GetCandidateVector(
std::vector< const Candidate* >& Completer::GetCandidateVector(
const std::string &filetype,
const std::string &filepath )
{
Expand All @@ -224,11 +224,11 @@ std::vector< Candidate* >& Completer::GetCandidateVector(
if ( !path_to_candidates )
path_to_candidates.reset( new FilepathToCandidates() );

boost::shared_ptr< std::vector< Candidate* > > &candidates =
boost::shared_ptr< std::vector< const Candidate* > > &candidates =
(*path_to_candidates)[ filepath ];

if ( !candidates )
candidates.reset( new std::vector< Candidate* >() );
candidates.reset( new std::vector< const Candidate* >() );

return *candidates;
}
Expand Down
8 changes: 5 additions & 3 deletions cpp/Completer.h
Expand Up @@ -37,11 +37,13 @@ namespace YouCompleteMe
typedef boost::python::list Pylist;

// candidate text string -> candidate objects
typedef boost::unordered_map< std::string, Candidate* > CandidateRepository;
typedef boost::unordered_map< std::string, const Candidate* >
CandidateRepository;

// filepath -> *( *candidate )
typedef boost::unordered_map< std::string,
boost::shared_ptr< std::vector< Candidate* > > > FilepathToCandidates;
boost::shared_ptr< std::vector< const Candidate* > > >
FilepathToCandidates;

// filetype -> *( filepath -> *( *candidate ) )
typedef boost::unordered_map< std::string,
Expand Down Expand Up @@ -93,7 +95,7 @@ class Completer : boost::noncopyable
const std::string &filetype,
std::vector< Result > &results ) const;

std::vector< Candidate* >& GetCandidateVector(
std::vector< const Candidate* >& GetCandidateVector(
const std::string &filetype,
const std::string &filepath );

Expand Down

0 comments on commit d421c43

Please sign in to comment.