Skip to content

Commit

Permalink
* more C++17 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chambm committed Feb 26, 2025
1 parent 5468234 commit a18375b
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 72 deletions.
3 changes: 1 addition & 2 deletions pwiz_tools/BiblioSpec/src/original-RefFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include <fstream>
#include <string>
#include <vector>
using std::binary_function;

struct refData{
string file;
Expand Down Expand Up @@ -75,7 +74,7 @@ class RefFile
};

//sort by both ms2 file name and scan number
struct compRefData : public binary_function<refData, refData, bool>
struct compRefData
{
bool operator()(refData r1, refData r2) {
if( r1.file == r2.file ) {
Expand Down
9 changes: 4 additions & 5 deletions pwiz_tools/BiblioSpec/src/original-RefSpectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
#include "pwiz/utility/misc/Stream.hpp"
#include "pwiz/utility/misc/Container.hpp"

using std::binary_function;

enum MODS { Meth, Cl };

class RefSpectrum : public Spectrum
Expand Down Expand Up @@ -95,7 +93,7 @@ class RefSpectrum : public Spectrum
};

//sort by both charge and sequence
struct compRefSpecIon : public binary_function<RefSpectrum, RefSpectrum, bool>
struct compRefSpecIon
{
bool operator()(RefSpectrum s1, RefSpectrum s2) {
if( s1.getCharge() == s2.getCharge() ) {
Expand All @@ -107,7 +105,8 @@ struct compRefSpecIon : public binary_function<RefSpectrum, RefSpectrum, bool>
};

//sort by both charge and sequence
struct compRefSpecPtrIon : public binary_function<RefSpectrum*, RefSpectrum*, bool>{
struct compRefSpecPtrIon
{
bool operator()(RefSpectrum* s1, RefSpectrum* s2) {
if( s1->getCharge() == s2->getCharge() ) {
if (s1->getSeq() == s2->getSeq()) {
Expand All @@ -121,7 +120,7 @@ struct compRefSpecPtrIon : public binary_function<RefSpectrum*, RefSpectrum*, bo
}
};

struct compRefSpecPtrId : public binary_function<RefSpectrum*, RefSpectrum*, bool>
struct compRefSpecPtrId
{
bool operator()(RefSpectrum* s1, RefSpectrum* s2) {return s1->getID() < s2->getID();}
};
Expand Down
15 changes: 7 additions & 8 deletions pwiz_tools/BiblioSpec/src/original-Spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@
#include <ctime>
#include <vector>

using std::binary_function;


struct PEAK_T
{
float mass;
float intensity;
};

struct compPeakInt : public binary_function<PEAK_T, PEAK_T, bool>
struct compPeakInt
{
bool operator()(PEAK_T p1, PEAK_T p2) {return p1.intensity > p2.intensity;}
};

struct compPeakMz : public binary_function<PEAK_T, PEAK_T, bool>
struct compPeakMz
{
bool operator()(PEAK_T p1, PEAK_T p2) {return p1.mass < p2.mass;}
};
Expand Down Expand Up @@ -126,21 +124,22 @@ class Spectrum
void tryMe(const Spectrum& otherSpec);
};

struct compSpecMz : public binary_function<Spectrum, Spectrum, bool>
struct compSpecMz
{
bool operator()(Spectrum s1, Spectrum s2) {return s1.getMz() < s2.getMz();}
};

struct compSpecPtrMz : public binary_function<Spectrum*, Spectrum*, bool>{
struct compSpecPtrMz
{
bool operator()(Spectrum* s1, Spectrum* s2) { return s1->getMz() < s2->getMz();}
};

struct compSpecScanNum : public binary_function<Spectrum, Spectrum, bool>
struct compSpecScanNum
{
bool operator()(Spectrum s1, Spectrum s2) {return s1.getScanNum() < s2.getScanNum();}
};

struct compSpecPtrScanNum : public binary_function<Spectrum*, Spectrum*, bool>
struct compSpecPtrScanNum
{
bool operator()(Spectrum* s1, Spectrum* s2) {return s1->getScanNum() < s2->getScanNum();}
};
Expand Down
3 changes: 2 additions & 1 deletion pwiz_tools/Bumbershoot/freicore/BaseSpectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ namespace freicore
{
vector<SpectrumType*> v( this->begin(), this->end() );
this->clear(false);
std::random_shuffle( v.begin(), v.end() );
std::mt19937 rng(0);
std::shuffle(v.begin(), v.end(), rng);
for( typename vector<SpectrumType*>::const_iterator itr = v.begin(); itr != v.end(); ++itr )
this->push_back( *itr );
}
Expand Down
3 changes: 2 additions & 1 deletion pwiz_tools/Bumbershoot/freicore/proteinStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ namespace freicore

void proteinStore::random_shuffle()
{
std::random_shuffle( storeIndex.begin(), storeIndex.end() );
std::mt19937 rng(0);
std::shuffle(storeIndex.begin(), storeIndex.end(), rng);
}

size_t proteinStore::size() const {return storeIndex.size();}
Expand Down
1 change: 1 addition & 0 deletions pwiz_tools/Bumbershoot/freicore/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
#include <cmath>
#include <ctime>
#include <bitset>
#include <random>

//#include <boost/lexical_cast.hpp>
#include "pwiz/utility/misc/optimized_lexical_cast.hpp"
Expand Down
4 changes: 3 additions & 1 deletion pwiz_tools/Bumbershoot/idpicker/Qonverter/Merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "boost/make_shared.hpp"
#include <deque>
#include <algorithm>
#include <random>


using namespace pwiz::util;
Expand Down Expand Up @@ -1007,7 +1008,8 @@ void Merger::merge(const string& mergeTargetFilepath, const std::vector<string>&
vector<size_t> randomSources;
for (size_t i = 0; i < mergeSourceFilepaths.size(); ++i)
randomSources.push_back(i);
std::random_shuffle(randomSources.begin(), randomSources.end());
std::mt19937 rng(0);
std::shuffle(randomSources.begin(), randomSources.end(), rng);

std::deque<shared_ptr<MergeTask> > sourceQueue;
for(int randomSource : randomSources)
Expand Down
29 changes: 16 additions & 13 deletions pwiz_tools/Bumbershoot/idpicker/Qonverter/Parser.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// $Id$
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// The Original Code is the IDPicker project.
Expand Down Expand Up @@ -44,7 +44,8 @@
#include "boost/atomic.hpp"
#include "boost/exception/all.hpp"
#include "boost/range/algorithm/set_algorithm.hpp"
#include "Logger.hpp"
#include "Logger.hpp"
#include <random>


using namespace pwiz::identdata;
Expand Down Expand Up @@ -959,7 +960,8 @@ vector<ProteinDatabaseTaskGroup> createTasksPerProteinDatabase(const vector<stri
taskGroups.back().proteomeDataPtr = proteinDatabaseByFilepath[proteinDatabaseFilepath];

// shuffled so that large and small input files get mixed
random_shuffle(inputFilepaths.begin(), inputFilepaths.end());
std::mt19937 rng(0);
std::shuffle(inputFilepaths.begin(), inputFilepaths.end(), rng);

int processorsUsed = 0;
for(const string& inputFilepath : inputFilepaths)
Expand Down Expand Up @@ -1281,7 +1283,8 @@ void executePeptideFinderTask(PeptideFinderTaskPtr peptideFinderTask, ThreadStat
peptides.push_back(peptide);

// distinctPeptideIdBySequence is sorted on peptide length, which is bad for the trie
random_shuffle(peptides.begin(), peptides.end());
std::mt19937 rng(0);
std::shuffle(peptides.begin(), peptides.end(), rng);

// maps proteins indexes to protein ids (in the database)
map<size_t, sqlite3_int64> proteinIdByIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <random>
#include "crawutils.h"

//note that I do not yet have the cephes library for MSVC++
Expand Down Expand Up @@ -1201,8 +1202,9 @@ return drand48();
std::vector< TwoGroupsType > v = permute_two_groups ( g1, g2 );
if ( N < (int)v.size() ) {
throw("invalid");
}
std::random_shuffle( v.begin(), v.end() );
}
std::mt19937 rng(0);
std::shuffle(v.begin(), v.end(), rng);
v.resize(N);
return v;
}
Expand Down
6 changes: 4 additions & 2 deletions pwiz_tools/Bumbershoot/pepitome/LibraryBabelFish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ namespace freicore
while(numAttempts < 100 && !foundDecoy)
{
stringstream shuffledPeptide;
std::random_shuffle(movableAAs.begin(),movableAAs.end());
std::mt19937 rng(0);
std::shuffle(movableAAs.begin(), movableAAs.end(), rng);
size_t repeat = 0;
size_t nonRepeat = 0;
size_t randomAAIndex = 0;
Expand Down Expand Up @@ -376,7 +377,8 @@ namespace freicore
{
vector<string> aminoAcids = boost::assign::list_of("A")("R")("N")("D")("C")("E")("Q")("G")("H")("I")("L")("K")("M")("F")("P")("S")("T")("U")("W")("Y")("V");
//{"A","R","N","D","E","Q","G","H","I","L","M","F","P","S","T","U","W","Y","V"};
std::random_shuffle(aminoAcids.begin(),aminoAcids.end());
std::mt19937 rng(0);
std::shuffle(aminoAcids.begin(), aminoAcids.end(), rng);
vector<string> saltedPeptide;
saltedPeptide.push_back(peptide[0]);
saltedPeptide.push_back(aminoAcids[0]);
Expand Down
6 changes: 4 additions & 2 deletions pwiz_tools/Bumbershoot/pepitome/spectraStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

#include <ctype.h>
#include <sstream>
#include <random>

using namespace boost::assign;
using namespace boost::algorithm;
Expand Down Expand Up @@ -929,7 +930,8 @@ namespace pepitome

void random_shuffle()
{
std::random_shuffle( begin(), end() );
std::mt19937 rng(0);
std::shuffle(begin(), end(), rng);
}

void loadLibrary(const string& libName)
Expand Down Expand Up @@ -1046,7 +1048,7 @@ namespace pepitome
{
bal::split(tokens, buf, bal::is_any_of(":"));
string peakInput = tokens[1];
peakInput.erase(peakInput.begin(), std::find_if(peakInput.begin(), peakInput.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
bal::trim(peakInput);
numPeaks = lexical_cast<size_t>(peakInput);
}
else if(bal::starts_with(buf, "PrecursorMZ"))
Expand Down
72 changes: 37 additions & 35 deletions pwiz_tools/Bumbershoot/quameter/crawdad/msmat/crawutils.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
/*
* Original author: Greg Finney <gfinney .at. u.washington.edu>,
* MacCoss Lab, Department of Genome Sciences, UW
*
* Copyright 2009 University of Washington - Seattle, WA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Original author: Greg Finney <gfinney .at. u.washington.edu>,
* MacCoss Lab, Department of Genome Sciences, UW
*
* Copyright 2009 University of Washington - Seattle, WA
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <algorithm>
#include <vector>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <random>
#include "crawutils.h"

//note that I do not yet have the cephes library for MSVC++
Expand Down Expand Up @@ -1092,22 +1093,22 @@ uint rand_in_range( uint low, uint high) {
return idx;
}

void init_rand() {
#ifdef _MSC_VER
srand((uint)time(NULL));
#else
srand48(time(NULL));
#endif

}

double get_rand() {
#ifdef _MSC_VER
return rand() / (double)RAND_MAX;
#else
return drand48();
#endif
}
void init_rand() {
#ifdef _MSC_VER
srand((uint)time(NULL));
#else
srand48(time(NULL));
#endif

}

double get_rand() {
#ifdef _MSC_VER
return rand() / (double)RAND_MAX;
#else
return drand48();
#endif
}



Expand Down Expand Up @@ -1184,7 +1185,8 @@ return drand48();
if ( N < (int)v.size() ) {
throw("invalid");
}
std::random_shuffle( v.begin(), v.end() );
std::mt19937 rng(0);
std::shuffle(v.begin(), v.end(), rng);
v.resize(N);
return v;
}
Expand Down

0 comments on commit a18375b

Please sign in to comment.