Skip to content

Commit ba92000

Browse files
authored
Merge pull request #23 from fmichonneau/fix-ncl-cpp20
2 parents 73dbb1e + af67a37 commit ba92000

2 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/ncl/nxscharactersblock.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <sstream>
2424
#include <cfloat>
2525
#include <climits>
26+
#include <memory>
2627

2728
#include "ncl/nxsdefs.h"
2829
#include "ncl/nxsdiscretedatum.h"
@@ -480,7 +481,7 @@ class NxsCharactersBlock
480481
typedef std::vector<std::string> VecString;
481482
typedef std::map<unsigned, std::string> IndexToLabelMap;
482483
typedef std::map<std::string, unsigned> LabelToIndexMap;
483-
typedef std::pair<NxsDiscreteDatatypeMapper, NxsUnsignedSet> DatatypeMapperAndIndexSet;
484+
typedef std::pair<std::shared_ptr<NxsDiscreteDatatypeMapper>, NxsUnsignedSet> DatatypeMapperAndIndexSet;
484485
typedef std::vector<DatatypeMapperAndIndexSet> VecDatatypeMapperAndIndexSet;
485486

486487

@@ -1535,7 +1536,7 @@ inline void NxsCharactersBlock::SetGapSymbol(char g)
15351536
{
15361537
gap = g;
15371538
if (datatypeMapperVec.size() == 1)
1538-
datatypeMapperVec[0].first.SetGapSymbol(g);
1539+
datatypeMapperVec[0].first->SetGapSymbol(g);
15391540
}
15401541

15411542

@@ -1551,7 +1552,7 @@ inline NxsCharactersBlock::DataTypesEnum NxsCharactersBlock::GetDataType() const
15511552
return datatype;
15521553
if (datatypeMapperVec.size() > 1)
15531554
return mixed;
1554-
return datatypeMapperVec[0].first.GetDatatype();
1555+
return datatypeMapperVec[0].first->GetDatatype();
15551556
}
15561557

15571558
inline NxsCharactersBlock::DataTypesEnum NxsCharactersBlock::GetOriginalDataType() const
@@ -1937,12 +1938,12 @@ inline const NxsCharactersBlock::ContinuousCharRow & NxsCharactersBlock::GetCont
19371938
inline NxsDiscreteDatatypeMapper * NxsCharactersBlock::GetMutableDatatypeMapperForChar(unsigned int charIndex)
19381939
{
19391940
if (datatypeMapperVec.size() == 1)
1940-
return &(datatypeMapperVec[0].first);
1941+
return datatypeMapperVec[0].first.get();
19411942
for (VecDatatypeMapperAndIndexSet::iterator dmvIt = datatypeMapperVec.begin(); dmvIt != datatypeMapperVec.end(); ++dmvIt)
19421943
{
19431944
const NxsUnsignedSet & currCS = dmvIt->second;
19441945
if (currCS.count(charIndex) > 0)
1945-
return &(dmvIt->first);
1946+
return dmvIt->first.get();
19461947
}
19471948
return NULL;
19481949
}
@@ -1951,7 +1952,7 @@ inline std::vector<const NxsDiscreteDatatypeMapper *> NxsCharactersBlock::GetAll
19511952
{
19521953
std::vector<const NxsDiscreteDatatypeMapper *> v;
19531954
for (VecDatatypeMapperAndIndexSet::const_iterator dmvIt = datatypeMapperVec.begin(); dmvIt != datatypeMapperVec.end(); ++dmvIt)
1954-
v.push_back(&(dmvIt->first));
1955+
v.push_back(dmvIt->first.get());
19551956
return v;
19561957
}
19571958

src/nxscharactersblock.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,8 +1542,8 @@ void NxsCharactersBlock::CreateDatatypeMapperObjects(const NxsPartition & dtPart
15421542
mixedTypeMapping.clear();
15431543
if (datatype != mixed)
15441544
{
1545-
NxsDiscreteDatatypeMapper d(datatype, symbols, missing, gap, matchchar, respectingCase, userEquates);
1546-
datatype = d.GetDatatype();
1545+
auto d = std::make_shared<NxsDiscreteDatatypeMapper>(datatype, symbols, missing, gap, matchchar, respectingCase, userEquates);
1546+
datatype = d->GetDatatype();
15471547
DatatypeMapperAndIndexSet das(d, NxsUnsignedSet());
15481548
datatypeMapperVec.clear();
15491549
datatypeMapperVec.push_back(das);
@@ -1560,7 +1560,7 @@ void NxsCharactersBlock::CreateDatatypeMapperObjects(const NxsPartition & dtPart
15601560
std::string mt;
15611561
if (*cIt == standard)
15621562
mt.assign("0123456789"); /*mrbayes is the only program to support MIXED and it uses a default (not extendable) symbols list of 0123456789 rather than 01*/
1563-
NxsDiscreteDatatypeMapper d(*cIt, mt, missing, gap, matchchar, respectingCase, userEquates);
1563+
auto d = std::make_shared<NxsDiscreteDatatypeMapper>(*cIt, mt, missing, gap, matchchar, respectingCase, userEquates);
15641564
const NxsUnsignedSet & indexSet = pIt->second;
15651565
DatatypeMapperAndIndexSet das(d, pIt->second);
15661566
NxsUnsignedSet & mappedInds = mixedTypeMapping[*cIt];
@@ -1669,27 +1669,27 @@ bool NxsCharactersBlock::AugmentedSymbolsToMixed()
16691669

16701670
/* copy the incoming matrix and mapper */
16711671
VecDatatypeMapperAndIndexSet mdm = datatypeMapperVec;
1672-
const NxsDiscreteDatatypeMapper & oldMapper = mdm[0].first;
1672+
const NxsDiscreteDatatypeMapper & oldMapper = *mdm[0].first;
16731673
if (oldMapper.GetUserDefinedEquatesBeforeConversion())
16741674
return false; /* dealing with equates correctly is not implemented below, so we'll bale out */
16751675

16761676
/* add the new mappers */
16771677
std::map<char, NxsString> noEquates;
16781678
datatypeMapperVec.clear();
1679-
NxsDiscreteDatatypeMapper o(odt, origSymb, missing, gap, matchchar, respectingCase, noEquates);
1679+
auto o = std::make_shared<NxsDiscreteDatatypeMapper>(odt, origSymb, missing, gap, matchchar, respectingCase, noEquates);
16801680
datatypeMapperVec.push_back(DatatypeMapperAndIndexSet(o, origTypeChars));
1681-
NxsDiscreteDatatypeMapper s(NxsCharactersBlock::standard, augmentSymbols, missing, gap, matchchar, respectingCase, noEquates);
1681+
auto s = std::make_shared<NxsDiscreteDatatypeMapper>(NxsCharactersBlock::standard, augmentSymbols, missing, gap, matchchar, respectingCase, noEquates);
16821682
datatypeMapperVec.push_back(DatatypeMapperAndIndexSet(s, stdTypeChars));
16831683

16841684

1685-
NxsDiscreteDatatypeMapper & newOrigTMapper = datatypeMapperVec[0].first;
1686-
NxsDiscreteDatatypeMapper & newStdTMapper = datatypeMapperVec[1].first;
1685+
NxsDiscreteDatatypeMapper & newOrigTMapper = *datatypeMapperVec[0].first;
1686+
NxsDiscreteDatatypeMapper & newStdTMapper = *datatypeMapperVec[1].first;
16871687

16881688
/* now we recode discrete matrix with new state codes */
16891689
const NxsDiscreteStateCell nOrigStates = (NxsDiscreteStateCell) origSymb.size();
16901690
std::map<NxsDiscreteStateCell, NxsDiscreteStateCell> oldToNewStateCode;
16911691
NxsDiscreteStateMatrix::iterator rowIt = discreteMatrix.begin();
1692-
for (unsigned colIndex = 0; rowIt != discreteMatrix.end(); ++colIndex, ++rowIt)
1692+
for (; rowIt != discreteMatrix.end(); ++rowIt)
16931693
{
16941694
NxsDiscreteStateRow & row = *rowIt;
16951695
unsigned column = 0;
@@ -2298,7 +2298,7 @@ void NxsCharactersBlock::HandleFormat(
22982298
if (*b)
22992299
{
23002300
DatatypeMapperAndIndexSet &mapper = datatypeMapperVec.at(mapInd);
2301-
mapper.first.SetWasRestrictionDataype(true);
2301+
mapper.first->SetWasRestrictionDataype(true);
23022302
}
23032303
}
23042304
}
@@ -3352,7 +3352,6 @@ NxsDiscreteStateCell NxsCharactersBlock::HandleTokenState(
33523352
*/
33533353
NxsStringVector::const_iterator ci_begin = bagIter->second.begin();
33543354
NxsStringVector::const_iterator ci_end = bagIter->second.end();
3355-
NxsStringVector::const_iterator cit;
33563355
NxsDiscreteStateCell k = 0;
33573356
for (; ci_begin != ci_end; ++ci_begin, ++k)
33583357
{
@@ -4943,7 +4942,7 @@ void NxsCharactersBlock::WriteFormatCommand(std::ostream &out) const
49434942
first = false;
49444943
else
49454944
out << ", ";
4946-
out << GetNameOfDatatype(mIt->first.GetDatatype()) << ':';
4945+
out << GetNameOfDatatype(mIt->first->GetDatatype()) << ':';
49474946
NxsSetReader::WriteSetAsNexusValue(mIt->second, out);
49484947
}
49494948
out << ')';

0 commit comments

Comments
 (0)