Skip to content

Commit a0291ac

Browse files
authored
[7.x][ML] Replace std::auto_ptr with std::unique_ptr (elastic#718)
std::auto_ptr has been removed from C++17, so we need to stop using it before we can upgrade to C++17. Also corrected the type name of a typedef of a std::auto_ptr. Backport of elastic#717
1 parent c19526a commit a0291ac

19 files changed

+36
-36
lines changed

include/core/CContainerPrinter.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,10 @@ class CORE_EXPORT CContainerPrinter : private CNonInstantiatable {
255255
return result.str();
256256
}
257257

258-
//! Print a std::auto_ptr.
258+
//! Print a std::unique_ptr.
259259
template<typename T>
260-
static std::string printElement(const std::auto_ptr<T>& value) {
261-
if (value.get() == nullptr) {
260+
static std::string printElement(const std::unique_ptr<T>& value) {
261+
if (value == nullptr) {
262262
return "\"null\"";
263263
}
264264
std::ostringstream result;

include/model/CAnomalyDetectorModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class MODEL_EXPORT CAnomalyDetectorModel {
162162
using TFeatureCorrelationsPtrPr = std::pair<model_t::EFeature, TCorrelationsPtr>;
163163
using TFeatureCorrelationsPtrPrVec = std::vector<TFeatureCorrelationsPtrPr>;
164164
using TDataGathererPtr = std::shared_ptr<CDataGatherer>;
165-
using CModelDetailsViewPtr = std::auto_ptr<CModelDetailsView>;
165+
using TModelDetailsViewUPtr = std::unique_ptr<CModelDetailsView>;
166166
using TModelPtr = std::unique_ptr<CAnomalyDetectorModel>;
167167

168168
public:
@@ -471,7 +471,7 @@ class MODEL_EXPORT CAnomalyDetectorModel {
471471
core_t::TTime bucketLength() const;
472472

473473
//! Get a view of the internals of the model for visualization.
474-
virtual CModelDetailsViewPtr details() const = 0;
474+
virtual TModelDetailsViewUPtr details() const = 0;
475475

476476
//! Get the frequency of the person identified by \p pid.
477477
double personFrequency(std::size_t pid) const;

include/model/CCountingModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class MODEL_EXPORT CCountingModel : public CAnomalyDetectorModel {
212212
std::size_t staticSize() const override;
213213

214214
//! Returns null.
215-
CModelDetailsViewPtr details() const override;
215+
TModelDetailsViewUPtr details() const override;
216216

217217
//! Get the descriptions of any occurring scheduled event descriptions for the bucket time
218218
const TStr1Vec& scheduledEventDescriptions(core_t::TTime time) const override;

include/model/CEventRateModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class MODEL_EXPORT CEventRateModel : public CIndividualModel {
263263
std::size_t computeMemoryUsage() const override;
264264

265265
//! Get a view of the internals of the model for visualization.
266-
CModelDetailsViewPtr details() const override;
266+
TModelDetailsViewUPtr details() const override;
267267

268268
//! Get the value of the \p feature of the person identified
269269
//! by \p pid for the bucketing interval containing \p time.

include/model/CEventRatePopulationModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class MODEL_EXPORT CEventRatePopulationModel : public CPopulationModel {
302302
std::size_t computeMemoryUsage() const override;
303303

304304
//! Get a view of the internals of the model for visualization.
305-
CModelDetailsViewPtr details() const override;
305+
TModelDetailsViewUPtr details() const override;
306306

307307
//! Get the feature data corresponding to \p feature at \p time.
308308
const TSizeSizePrFeatureDataPrVec& featureData(model_t::EFeature feature,

include/model/CMetricModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class MODEL_EXPORT CMetricModel : public CIndividualModel {
258258
std::size_t computeMemoryUsage() const override;
259259

260260
//! Get a view of the internals of the model for visualization.
261-
CModelDetailsViewPtr details() const override;
261+
TModelDetailsViewUPtr details() const override;
262262

263263
//! Get the value of the \p feature of the person identified
264264
//! by \p pid for the bucketing interval containing \p time.

include/model/CMetricPopulationModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class MODEL_EXPORT CMetricPopulationModel : public CPopulationModel {
266266
uint64_t checksum(bool includeCurrentBucketStats = true) const override;
267267

268268
//! Get a view of the internals of the model for visualization.
269-
CModelDetailsViewPtr details() const override;
269+
TModelDetailsViewUPtr details() const override;
270270

271271
//! Get the feature data corresponding to \p feature at \p time.
272272
const TSizeSizePrFeatureDataPrVec& featureData(model_t::EFeature feature,

lib/core/unittest/CContainerPrinterTest.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ void CContainerPrinterTest::testAll() {
5454
CPPUNIT_ASSERT_EQUAL(std::string("[(1, \"null\"), (1.1, 3), (3.3, 5.1)]"),
5555
CContainerPrinter::print(map));
5656

57-
std::auto_ptr<int> pints[] = {std::auto_ptr<int>(new int(2)),
58-
std::auto_ptr<int>(new int(3)),
59-
std::auto_ptr<int>(new int(2))};
57+
std::unique_ptr<int> pints[] = {std::unique_ptr<int>(new int(2)),
58+
std::unique_ptr<int>(new int(3)),
59+
std::unique_ptr<int>(new int(2))};
6060
LOG_DEBUG(<< "pints = "
6161
<< CContainerPrinter::print(std::begin(pints), std::end(pints)));
6262
CPPUNIT_ASSERT_EQUAL(std::string("[2, 3, 2]"),

lib/model/CAnomalyDetector.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace model {
3636
// We use short field names to reduce the state size
3737
namespace {
3838

39-
using TModelDetailsViewPtr = CAnomalyDetectorModel::CModelDetailsViewPtr;
39+
using TModelDetailsViewUPtr = CAnomalyDetectorModel::TModelDetailsViewUPtr;
4040

4141
// tag 'a' was previously used for persisting first time;
4242
// DO NOT USE; unless it is decided to break model state BWC
@@ -439,7 +439,7 @@ void CAnomalyDetector::generateModelPlot(core_t::TTime bucketStartTime,
439439
if (terms.empty() || m_DataGatherer->partitionFieldValue().empty() ||
440440
terms.find(m_DataGatherer->partitionFieldValue()) != terms.end()) {
441441
const CSearchKey& key = m_DataGatherer->searchKey();
442-
TModelDetailsViewPtr view = m_Model.get()->details();
442+
TModelDetailsViewUPtr view = m_Model.get()->details();
443443
if (view.get()) {
444444
core_t::TTime bucketLength = m_ModelConfig.bucketLength();
445445
for (core_t::TTime time = bucketStartTime; time < bucketEndTime;
@@ -458,7 +458,7 @@ CForecastDataSink::SForecastModelPrerequisites
458458
CAnomalyDetector::getForecastPrerequisites() const {
459459
CForecastDataSink::SForecastModelPrerequisites prerequisites{0, 0, 0, true, false};
460460

461-
TModelDetailsViewPtr view = m_Model->details();
461+
TModelDetailsViewUPtr view = m_Model->details();
462462

463463
// The view can be empty, e.g. for the counting model.
464464
if (view.get() == nullptr) {
@@ -508,7 +508,7 @@ CAnomalyDetector::getForecastModels(bool persistOnDisk,
508508
return series;
509509
}
510510

511-
TModelDetailsViewPtr view = m_Model.get()->details();
511+
TModelDetailsViewUPtr view = m_Model.get()->details();
512512

513513
// The view can be empty, e.g. for the counting model.
514514
if (view.get() == nullptr) {

lib/model/CCountingModel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,8 @@ std::size_t CCountingModel::staticSize() const {
329329
return sizeof(*this);
330330
}
331331

332-
CCountingModel::CModelDetailsViewPtr CCountingModel::details() const {
333-
return CModelDetailsViewPtr();
332+
CCountingModel::TModelDetailsViewUPtr CCountingModel::details() const {
333+
return TModelDetailsViewUPtr();
334334
}
335335

336336
core_t::TTime CCountingModel::currentBucketStartTime() const {

lib/model/CEventRateModel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,8 @@ std::size_t CEventRateModel::computeMemoryUsage() const {
502502
return mem;
503503
}
504504

505-
CEventRateModel::CModelDetailsViewPtr CEventRateModel::details() const {
506-
return CModelDetailsViewPtr(new CEventRateModelDetailsView(*this));
505+
CEventRateModel::TModelDetailsViewUPtr CEventRateModel::details() const {
506+
return TModelDetailsViewUPtr(new CEventRateModelDetailsView(*this));
507507
}
508508

509509
const CEventRateModel::TFeatureData*

lib/model/CEventRatePopulationModel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -852,8 +852,8 @@ std::size_t CEventRatePopulationModel::staticSize() const {
852852
return sizeof(*this);
853853
}
854854

855-
CEventRatePopulationModel::CModelDetailsViewPtr CEventRatePopulationModel::details() const {
856-
return CModelDetailsViewPtr(new CEventRatePopulationModelDetailsView(*this));
855+
CEventRatePopulationModel::TModelDetailsViewUPtr CEventRatePopulationModel::details() const {
856+
return TModelDetailsViewUPtr(new CEventRatePopulationModelDetailsView(*this));
857857
}
858858

859859
const CEventRatePopulationModel::TSizeSizePrFeatureDataPrVec&

lib/model/CMetricModel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ std::size_t CMetricModel::staticSize() const {
466466
return sizeof(*this);
467467
}
468468

469-
CMetricModel::CModelDetailsViewPtr CMetricModel::details() const {
470-
return CModelDetailsViewPtr(new CMetricModelDetailsView(*this));
469+
CMetricModel::TModelDetailsViewUPtr CMetricModel::details() const {
470+
return TModelDetailsViewUPtr(new CMetricModelDetailsView(*this));
471471
}
472472

473473
const CMetricModel::TFeatureData*

lib/model/CMetricPopulationModel.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,8 @@ std::size_t CMetricPopulationModel::staticSize() const {
761761
return sizeof(*this);
762762
}
763763

764-
CMetricPopulationModel::CModelDetailsViewPtr CMetricPopulationModel::details() const {
765-
return CModelDetailsViewPtr(new CMetricPopulationModelDetailsView(*this));
764+
CMetricPopulationModel::TModelDetailsViewUPtr CMetricPopulationModel::details() const {
765+
return TModelDetailsViewUPtr(new CMetricPopulationModelDetailsView(*this));
766766
}
767767

768768
const TSizeSizePrFeatureDataPrVec&

lib/model/unittest/CEventRateModelTest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2895,9 +2895,9 @@ void CEventRateModelTest::testIgnoreSamplingGivenDetectionRules() {
28952895
CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum());
28962896

28972897
// but the underlying models should be the same
2898-
CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView =
2898+
CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView =
28992899
modelWithSkip->details();
2900-
CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details();
2900+
CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details();
29012901

29022902
uint64_t withSkipChecksum =
29032903
static_cast<const maths::CUnivariateTimeSeriesModel*>(

lib/model/unittest/CMetricModelTest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,9 +2478,9 @@ void CMetricModelTest::testIgnoreSamplingGivenDetectionRules() {
24782478
CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum());
24792479

24802480
// but the underlying models should be the same
2481-
CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView =
2481+
CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView =
24822482
modelWithSkip->details();
2483-
CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details();
2483+
CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details();
24842484

24852485
// TODO this test fails due a different checksums for the decay rate and prior
24862486
// uint64_t withSkipChecksum = modelWithSkipView->model(model_t::E_IndividualMeanByPerson, 0)->checksum();

lib/model/unittest/CMetricPopulationModelTest.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,9 +1499,9 @@ void CMetricPopulationModelTest::testIgnoreSamplingGivenDetectionRules() {
14991499
// Checksums will be different because a 3rd model is created for attribute c3
15001500
CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum());
15011501

1502-
CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView =
1502+
CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView =
15031503
modelWithSkip->details();
1504-
CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details();
1504+
CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details();
15051505

15061506
// but the underlying models for people p1 and p2 are the same
15071507
uint64_t withSkipChecksum = modelWithSkipView

lib/model/unittest/Mocks.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ std::size_t CMockModel::staticSize() const {
132132
return 0;
133133
}
134134

135-
CMockModel::CModelDetailsViewPtr CMockModel::details() const {
136-
CModelDetailsViewPtr result{new CMockModelDetailsView(*this)};
135+
CMockModel::TModelDetailsViewUPtr CMockModel::details() const {
136+
TModelDetailsViewUPtr result{new CMockModelDetailsView(*this)};
137137
return result;
138138
}
139139

lib/model/unittest/Mocks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class CMockModel : public CAnomalyDetectorModel {
9494

9595
std::size_t staticSize() const override;
9696

97-
CModelDetailsViewPtr details() const override;
97+
TModelDetailsViewUPtr details() const override;
9898

9999
double attributeFrequency(std::size_t cid) const override;
100100

0 commit comments

Comments
 (0)