Skip to content

Commit c4c1d0c

Browse files
committed
more auto and const usage cleanup
1 parent 6218ee3 commit c4c1d0c

32 files changed

Lines changed: 439 additions & 438 deletions

core/chromosome.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ void Chromosome::InitializeDraws(void)
454454
{
455455
last_position_ = 0;
456456

457-
for (GenomicElement *genomic_element : genomic_elements_)
457+
for (const GenomicElement *genomic_element : genomic_elements_)
458458
{
459459
if (genomic_element->end_position_ > last_position_)
460460
last_position_ = genomic_element->end_position_;
@@ -1915,7 +1915,7 @@ void Chromosome::DrawBreakpoints(Individual *p_parent, Haplosome *p_haplosome1,
19151915
#endif
19161916
}
19171917

1918-
size_t Chromosome::MemoryUsageForMutationMaps(void)
1918+
size_t Chromosome::MemoryUsageForMutationMaps(void) const
19191919
{
19201920
size_t usage = 0;
19211921

@@ -1937,7 +1937,7 @@ size_t Chromosome::MemoryUsageForMutationMaps(void)
19371937
return usage;
19381938
}
19391939

1940-
size_t Chromosome::MemoryUsageForRecombinationMaps(void)
1940+
size_t Chromosome::MemoryUsageForRecombinationMaps(void) const
19411941
{
19421942
size_t usage = 0;
19431943

@@ -1956,7 +1956,7 @@ size_t Chromosome::MemoryUsageForRecombinationMaps(void)
19561956
return usage;
19571957
}
19581958

1959-
size_t Chromosome::MemoryUsageForAncestralSequence(void)
1959+
size_t Chromosome::MemoryUsageForAncestralSequence(void) const
19601960
{
19611961
size_t usage = 0;
19621962

@@ -2172,15 +2172,15 @@ void Chromosome::CheckMutationRegistry(bool p_check_haplosomes)
21722172

21732173
for (const std::pair<const slim_objectid_t,Subpopulation*> &subpop_pair : species_.population_.subpops_)
21742174
{
2175-
Subpopulation *subpop = subpop_pair.second;
2175+
const Subpopulation *subpop = subpop_pair.second;
21762176

2177-
for (Individual *ind : subpop->parent_individuals_)
2177+
for (const Individual *ind : subpop->parent_individuals_)
21782178
{
2179-
Haplosome **haplosomes = ind->haplosomes_;
2179+
const Haplosome * const *haplosomes = ind->haplosomes_;
21802180

21812181
for (int haplosome_index = 0; haplosome_index < haplosome_count_per_individual; haplosome_index++)
21822182
{
2183-
Haplosome *haplosome = haplosomes[haplosome_index];
2183+
const Haplosome *haplosome = haplosomes[haplosome_index];
21842184

21852185
int mutrun_count = haplosome->mutrun_count_;
21862186

core/chromosome.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class Chromosome : public EidosDictionaryRetained
319319
~Chromosome(void);
320320

321321
// mutation registry
322-
inline const MutationIndex *MutationRegistry(int *registry_count)
322+
inline const MutationIndex *MutationRegistry(int *registry_count) const
323323
{
324324
*registry_count = mutation_registry_.size();
325325
return mutation_registry_.begin_pointer_const();
@@ -332,7 +332,7 @@ class Chromosome : public EidosDictionaryRetained
332332

333333
void CheckMutationRegistry(bool p_check_haplosomes); // check the registry for any bad entries (i.e. zombies, mutations with an incorrect state_)
334334
inline void SetMutationRegistryNeedsCheck(void) { registry_needs_consistency_check_ = true; }
335-
inline bool MutationRegistryNeedsCheck(void) { return registry_needs_consistency_check_; }
335+
inline bool MutationRegistryNeedsCheck(void) const { return registry_needs_consistency_check_; }
336336

337337
// accessors
338338
inline __attribute__((always_inline)) int64_t ID(void) const { return id_; }
@@ -404,9 +404,9 @@ class Chromosome : public EidosDictionaryRetained
404404
void RecombinationMapConfigError(void) const __attribute__((__noreturn__)) __attribute__((cold)) __attribute__((analyzer_noreturn));
405405

406406
// Memory usage tallying, for outputUsage()
407-
size_t MemoryUsageForMutationMaps(void);
408-
size_t MemoryUsageForRecombinationMaps(void);
409-
size_t MemoryUsageForAncestralSequence(void);
407+
size_t MemoryUsageForMutationMaps(void) const;
408+
size_t MemoryUsageForRecombinationMaps(void) const;
409+
size_t MemoryUsageForAncestralSequence(void) const;
410410

411411
// Make a null haplosome, which is associated with an individual, but has no associated chromosome, or
412412
// make a non-null haplosome, which is associated with an individual and has an associated chromosome
@@ -422,7 +422,7 @@ class Chromosome : public EidosDictionaryRetained
422422
void SetUpMutationRunContexts(void);
423423

424424
#ifndef _OPENMP
425-
inline int ChromosomeMutationRunContextCount(void) { return 1; }
425+
inline int ChromosomeMutationRunContextCount(void) const { return 1; }
426426
inline __attribute__((always_inline)) MutationRunContext &ChromosomeMutationRunContextForThread(__attribute__((unused)) int p_thread_num)
427427
{
428428
#if DEBUG
@@ -440,7 +440,7 @@ class Chromosome : public EidosDictionaryRetained
440440
return mutation_run_context_SINGLE_;
441441
}
442442
#else
443-
inline int ChromosomeMutationRunContextCount(void) { return mutation_run_context_COUNT_; }
443+
inline int ChromosomeMutationRunContextCount(void) const { return mutation_run_context_COUNT_; }
444444
inline __attribute__((always_inline)) MutationRunContext &ChromosomeMutationRunContextForThread(int p_thread_num)
445445
{
446446
#if DEBUG

core/community.cpp

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void Community::InitializeFromFile(std::istream &p_infile)
204204
std::vector<std::string> explicit_species_decl_names; // names from "species <name> initialize()" declarations
205205
int implied_species_decl_count = 0; // number of "initialize()" seen without "species <name>"
206206

207-
for (EidosASTNode *script_block_node : root_node->children_)
207+
for (const EidosASTNode *script_block_node : root_node->children_)
208208
{
209209
if (script_block_node->token_->token_type_ == EidosTokenType::kTokenIdentifier)
210210
{
@@ -326,7 +326,7 @@ void Community::InitializeFromFile(std::istream &p_infile)
326326
bool last_spec_is_ticks_all = false; // "ticks all" is a special syntax; there is no species named "all" so it must be tracked with a separate flag
327327
bool last_spec_is_species_all = false; // "species all" is a special syntax; there is no species named "all" so it must be tracked with a separate flag
328328

329-
for (EidosASTNode *script_block_node : root_node->children_)
329+
for (const EidosASTNode *script_block_node : root_node->children_)
330330
{
331331
if ((script_block_node->token_->token_type_ == EidosTokenType::kTokenIdentifier) && (script_block_node->children_.size() == 1))
332332
{
@@ -493,7 +493,7 @@ void Community::ValidateScriptBlockCaches(void)
493493

494494
#if DEBUG_BLOCK_REG_DEREG
495495
std::cout << " ValidateScriptBlockCaches() recaching, AllScriptBlocks() is:" << std::endl;
496-
for (SLiMEidosBlock *script_block : script_blocks)
496+
for (const SLiMEidosBlock *script_block : script_blocks)
497497
{
498498
std::cout << " ";
499499
script_block->Print(std::cout);
@@ -547,7 +547,7 @@ void Community::ValidateScriptBlockCaches(void)
547547

548548
#if DEBUG_BLOCK_REG_DEREG
549549
std::cout << " ValidateScriptBlockCaches() recached, late() events cached are:" << std::endl;
550-
for (SLiMEidosBlock *script_block : cached_late_events_)
550+
for (const SLiMEidosBlock *script_block : cached_late_events_)
551551
{
552552
std::cout << " ";
553553
script_block->Print(std::cout);
@@ -1095,7 +1095,7 @@ void Community::AddScriptBlock(SLiMEidosBlock *p_script_block, EidosInterpreter
10951095

10961096
#if DEBUG_BLOCK_REG_DEREG
10971097
std::cout << "Tick " << tick_ << ": AddScriptBlock() just added a block, script_blocks_ is:" << std::endl;
1098-
for (SLiMEidosBlock *script_block : script_blocks_)
1098+
for (const SLiMEidosBlock *script_block : script_blocks_)
10991099
{
11001100
std::cout << " ";
11011101
script_block->Print(std::cout);
@@ -1124,7 +1124,7 @@ void Community::DeregisterScheduledScriptBlocks(void)
11241124
if (scheduled_deregistrations_.size())
11251125
{
11261126
std::cout << "Tick " << tick_ << ": DeregisterScheduledScriptBlocks() planning to remove:" << std::endl;
1127-
for (SLiMEidosBlock *script_block : scheduled_deregistrations_)
1127+
for (const SLiMEidosBlock *script_block : scheduled_deregistrations_)
11281128
{
11291129
std::cout << " ";
11301130
script_block->Print(std::cout);
@@ -1167,7 +1167,7 @@ void Community::DeregisterScheduledScriptBlocks(void)
11671167
if (scheduled_deregistrations_.size())
11681168
{
11691169
std::cout << "Tick " << tick_ << ": DeregisterScheduledScriptBlocks() after removal:" << std::endl;
1170-
for (SLiMEidosBlock *script_block : script_blocks_)
1170+
for (const SLiMEidosBlock *script_block : script_blocks_)
11711171
{
11721172
std::cout << " ";
11731173
script_block->Print(std::cout);
@@ -1186,7 +1186,7 @@ void Community::DeregisterScheduledInteractionBlocks(void)
11861186
if (scheduled_interaction_deregs_.size())
11871187
{
11881188
std::cout << "Tick " << tick_ << ": DeregisterScheduledInteractionBlocks() planning to remove:" << std::endl;
1189-
for (SLiMEidosBlock *script_block : scheduled_interaction_deregs_)
1189+
for (const SLiMEidosBlock *script_block : scheduled_interaction_deregs_)
11901190
{
11911191
std::cout << " ";
11921192
script_block->Print(std::cout);
@@ -1229,7 +1229,7 @@ void Community::DeregisterScheduledInteractionBlocks(void)
12291229
if (scheduled_interaction_deregs_.size())
12301230
{
12311231
std::cout << "Tick " << tick_ << ": DeregisterScheduledInteractionBlocks() after removal:" << std::endl;
1232-
for (SLiMEidosBlock *script_block : script_blocks_)
1232+
for (const SLiMEidosBlock *script_block : script_blocks_)
12331233
{
12341234
std::cout << " ";
12351235
script_block->Print(std::cout);
@@ -1269,12 +1269,12 @@ bool Community::SubpopulationIDInUse(slim_objectid_t p_subpop_id)
12691269
// been used, or is reserved for use in some way by, by any SLiM species or by any tree sequence.
12701270

12711271
// First check our own data structures; we now do not allow reuse of subpop ids, even disjoint in time
1272-
for (Species *species : all_species_)
1272+
for (const Species *species : all_species_)
12731273
if (species->used_subpop_ids_.find(p_subpop_id) != species->used_subpop_ids_.end())
12741274
return true;
12751275

12761276
// Then have each species check for a conflict with its tree-sequence population table
1277-
for (Species *species : all_species_)
1277+
for (const Species *species : all_species_)
12781278
if (species->_SubpopulationIDInUse(p_subpop_id))
12791279
return true;
12801280

@@ -1287,7 +1287,7 @@ bool Community::SubpopulationNameInUse(const std::string &p_subpop_name)
12871287
// been used, or is reserved for use in some way by, by any SLiM species or by any tree sequence.
12881288

12891289
// First check our own data structures; we now do not allow reuse of subpop names, even disjoint in time
1290-
for (Species *species : all_species_)
1290+
for (const Species *species : all_species_)
12911291
if (species->used_subpop_names_.count(p_subpop_name))
12921292
return true;
12931293

@@ -1298,7 +1298,7 @@ bool Community::SubpopulationNameInUse(const std::string &p_subpop_name)
12981298

12991299
Subpopulation *Community::SubpopulationWithID(slim_objectid_t p_subpop_id)
13001300
{
1301-
for (Species *species : all_species_)
1301+
for (const Species *species : all_species_)
13021302
{
13031303
Subpopulation *found_subpop = species->SubpopulationWithID(p_subpop_id);
13041304

@@ -1311,7 +1311,7 @@ Subpopulation *Community::SubpopulationWithID(slim_objectid_t p_subpop_id)
13111311

13121312
Subpopulation *Community::SubpopulationWithName(const std::string &p_subpop_name)
13131313
{
1314-
for (Species *species : all_species_)
1314+
for (const Species *species : all_species_)
13151315
{
13161316
Subpopulation *found_subpop = species->SubpopulationWithName(p_subpop_name);
13171317

@@ -1324,7 +1324,7 @@ Subpopulation *Community::SubpopulationWithName(const std::string &p_subpop_name
13241324

13251325
MutationType *Community::MutationTypeWithID(slim_objectid_t p_muttype_id)
13261326
{
1327-
for (Species *species : all_species_)
1327+
for (const Species *species : all_species_)
13281328
{
13291329
MutationType *found_muttype = species->MutationTypeWithID(p_muttype_id);
13301330

@@ -1337,7 +1337,7 @@ MutationType *Community::MutationTypeWithID(slim_objectid_t p_muttype_id)
13371337

13381338
GenomicElementType *Community::GenomicElementTypeWithID(slim_objectid_t p_getype_id)
13391339
{
1340-
for (Species *species : all_species_)
1340+
for (const Species *species : all_species_)
13411341
{
13421342
GenomicElementType *found_getype = species->GenomicElementTypeWithID(p_getype_id);
13431343

@@ -2043,7 +2043,7 @@ void Community::FlagUnevaluatedScriptBlockTickRanges()
20432043

20442044
std::vector<SLiMEidosBlock*> &script_blocks = AllScriptBlocks();
20452045

2046-
for (SLiMEidosBlock *script_block : script_blocks)
2046+
for (const SLiMEidosBlock *script_block : script_blocks)
20472047
{
20482048
if ((script_block->type_ != SLiMEidosBlockType::SLiMEidosInitializeCallback) &&
20492049
!script_block->tick_range_evaluated_)
@@ -2063,7 +2063,7 @@ slim_tick_t Community::FirstTick(void)
20632063

20642064
// Figure out our first tick; it is the earliest tick in which an Eidos event is set up to run,
20652065
// since an Eidos event that adds a subpopulation is necessary to get things started
2066-
for (SLiMEidosBlock *script_block : script_blocks)
2066+
for (const SLiMEidosBlock *script_block : script_blocks)
20672067
{
20682068
if ((script_block->type_ == SLiMEidosBlockType::SLiMEidosEventFirst) ||
20692069
(script_block->type_ == SLiMEidosBlockType::SLiMEidosEventEarly) ||
@@ -2105,7 +2105,7 @@ slim_tick_t Community::EstimatedLastTick(void)
21052105
// The estimate is derived from the last tick in which an Eidos block is registered.
21062106
// Any block type works, since the simulation could plausibly be stopped within a callback.
21072107
// However, blocks that do not specify an end tick don't count.
2108-
for (SLiMEidosBlock *script_block : script_blocks)
2108+
for (const SLiMEidosBlock *script_block : script_blocks)
21092109
{
21102110
if (script_block->tick_range_is_sequence_)
21112111
{
@@ -2235,7 +2235,7 @@ bool Community::_RunOneTick(void)
22352235
gSLiMScheduling << "# tick " << tick_ << ": ";
22362236
bool first_species = true;
22372237

2238-
for (Species *species : all_species_)
2238+
for (const Species *species : all_species_)
22392239
{
22402240
if (!first_species)
22412241
gSLiMScheduling << ", ";
@@ -2360,7 +2360,7 @@ void Community::AllSpecies_RunInitializeCallbacks(void)
23602360
DeregisterScheduledScriptBlocks();
23612361

23622362
// compile results from initialization into our overall state
2363-
for (Species *species : all_species_)
2363+
for (const Species *species : all_species_)
23642364
{
23652365
const std::map<slim_objectid_t,MutationType*> &muttypes = species->MutationTypes();
23662366
const std::map<slim_objectid_t,GenomicElementType*> &getypes = species->GenomicElementTypes();
@@ -2548,15 +2548,15 @@ void Community::AllSpecies_CheckIntegrity(void)
25482548
{
25492549
#if DEBUG
25502550
// Check the integrity of all the information in the individuals and haplosomes of the parental population
2551-
for (Species *species : all_species_)
2551+
for (const Species *species : all_species_)
25522552
species->Species_CheckIntegrity();
25532553
#endif
25542554

25552555
#if DEBUG
25562556
// Check for species consistency across all of the objects in each species
25572557
for (size_t species_index = 0; species_index < all_species_.size(); ++species_index)
25582558
{
2559-
Species *species = all_species_[species_index];
2559+
const Species *species = all_species_[species_index];
25602560

25612561
if (&species->community_ != this)
25622562
EIDOS_TERMINATION << "ERROR (Community::AllSpecies_CheckIntegrity): (internal error) species->community_ mismatch." << EidosTerminate();
@@ -2567,7 +2567,7 @@ void Community::AllSpecies_CheckIntegrity(void)
25672567
if (species->species_id_ != (int)species_index)
25682568
EIDOS_TERMINATION << "ERROR (Community::AllSpecies_CheckIntegrity): (internal error) species->species_id_ mismatch." << EidosTerminate();
25692569

2570-
for (Chromosome *chromosome : species->Chromosomes())
2570+
for (const Chromosome *chromosome : species->Chromosomes())
25712571
{
25722572
if (&chromosome->species_ != species)
25732573
EIDOS_TERMINATION << "ERROR (Community::AllSpecies_CheckIntegrity): (internal error) chromosome->species_ mismatch." << EidosTerminate();
@@ -2576,7 +2576,7 @@ void Community::AllSpecies_CheckIntegrity(void)
25762576
EIDOS_TERMINATION << "ERROR (Community::AllSpecies_CheckIntegrity): (internal error) chromosome->community_ mismatch." << EidosTerminate();
25772577
}
25782578

2579-
Population &population = species->population_;
2579+
const Population &population = species->population_;
25802580
const std::map<slim_objectid_t,MutationType*> &muttypes = species->MutationTypes();
25812581
const std::map<slim_objectid_t,GenomicElementType*> &getypes = species->GenomicElementTypes();
25822582

@@ -2604,9 +2604,9 @@ void Community::AllSpecies_CheckIntegrity(void)
26042604
return;
26052605
#endif
26062606

2607-
for (Species *species : all_species_)
2607+
for (const Species *species : all_species_)
26082608
{
2609-
for (Chromosome *chromosome : species->Chromosomes())
2609+
for (const Chromosome *chromosome : species->Chromosomes())
26102610
{
26112611
// Check the integrity of the mutation registry; all MutationIndex values should be in range
26122612
int registry_size;
@@ -2945,7 +2945,7 @@ bool Community::_RunOneTickWF(void)
29452945
#if DEBUG
29462946
// now that fitness calculations are done, do a crosscheck of all trait values
29472947
// this is disabled by a global flag while we are running some self-tests
2948-
for (Species *species : all_species_)
2948+
for (const Species *species : all_species_)
29492949
species->CrosscheckAllTraitValues();
29502950
#endif
29512951

@@ -3255,7 +3255,7 @@ bool Community::_RunOneTickNonWF(void)
32553255

32563256
#if DEBUG
32573257
// now that fitness calculations are done, do a crosscheck of all trait values
3258-
for (Species *species : all_species_)
3258+
for (const Species *species : all_species_)
32593259
species->CrosscheckAllTraitValues();
32603260
#endif
32613261

@@ -3502,7 +3502,7 @@ void Community::TabulateSLiMMemoryUsage_Community(SLiMMemoryUsage_Community *p_u
35023502
p_usage->mutationPerTraitBuffer = 0.0;
35033503
p_usage->mutationUnusedPoolSpace = 0.0;
35043504

3505-
for (Species *species : all_species_)
3505+
for (const Species *species : all_species_)
35063506
{
35073507
if (species->HasGenetics())
35083508
{

0 commit comments

Comments
 (0)