From 0c445719493006994f5e82e34758567232b19bdd Mon Sep 17 00:00:00 2001 From: David Roberts Date: Fri, 4 Oct 2019 13:45:18 +0100 Subject: [PATCH] [ML] Replace std::auto_ptr with std::unique_ptr 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. --- include/core/CContainerPrinter.h | 6 +++--- include/model/CAnomalyDetectorModel.h | 4 ++-- include/model/CCountingModel.h | 2 +- include/model/CEventRateModel.h | 2 +- include/model/CEventRatePopulationModel.h | 2 +- include/model/CMetricModel.h | 2 +- include/model/CMetricPopulationModel.h | 2 +- lib/core/unittest/CContainerPrinterTest.cc | 6 +++--- lib/model/CAnomalyDetector.cc | 8 ++++---- lib/model/CCountingModel.cc | 4 ++-- lib/model/CEventRateModel.cc | 4 ++-- lib/model/CEventRatePopulationModel.cc | 4 ++-- lib/model/CMetricModel.cc | 4 ++-- lib/model/CMetricPopulationModel.cc | 4 ++-- lib/model/unittest/CEventRateModelTest.cc | 4 ++-- lib/model/unittest/CMetricModelTest.cc | 4 ++-- lib/model/unittest/CMetricPopulationModelTest.cc | 4 ++-- lib/model/unittest/Mocks.cc | 4 ++-- lib/model/unittest/Mocks.h | 2 +- 19 files changed, 36 insertions(+), 36 deletions(-) diff --git a/include/core/CContainerPrinter.h b/include/core/CContainerPrinter.h index 5fb1fe8cf1..6030ac07ca 100644 --- a/include/core/CContainerPrinter.h +++ b/include/core/CContainerPrinter.h @@ -255,10 +255,10 @@ class CORE_EXPORT CContainerPrinter : private CNonInstantiatable { return result.str(); } - //! Print a std::auto_ptr. + //! Print a std::unique_ptr. template - static std::string printElement(const std::auto_ptr& value) { - if (value.get() == nullptr) { + static std::string printElement(const std::unique_ptr& value) { + if (value == nullptr) { return "\"null\""; } std::ostringstream result; diff --git a/include/model/CAnomalyDetectorModel.h b/include/model/CAnomalyDetectorModel.h index 19269df7c3..7d881d3894 100644 --- a/include/model/CAnomalyDetectorModel.h +++ b/include/model/CAnomalyDetectorModel.h @@ -162,7 +162,7 @@ class MODEL_EXPORT CAnomalyDetectorModel { using TFeatureCorrelationsPtrPr = std::pair; using TFeatureCorrelationsPtrPrVec = std::vector; using TDataGathererPtr = std::shared_ptr; - using CModelDetailsViewPtr = std::auto_ptr; + using TModelDetailsViewUPtr = std::unique_ptr; using TModelPtr = std::unique_ptr; public: @@ -471,7 +471,7 @@ class MODEL_EXPORT CAnomalyDetectorModel { core_t::TTime bucketLength() const; //! Get a view of the internals of the model for visualization. - virtual CModelDetailsViewPtr details() const = 0; + virtual TModelDetailsViewUPtr details() const = 0; //! Get the frequency of the person identified by \p pid. double personFrequency(std::size_t pid) const; diff --git a/include/model/CCountingModel.h b/include/model/CCountingModel.h index aadc9a3b00..46dede26bd 100644 --- a/include/model/CCountingModel.h +++ b/include/model/CCountingModel.h @@ -212,7 +212,7 @@ class MODEL_EXPORT CCountingModel : public CAnomalyDetectorModel { std::size_t staticSize() const override; //! Returns null. - CModelDetailsViewPtr details() const override; + TModelDetailsViewUPtr details() const override; //! Get the descriptions of any occurring scheduled event descriptions for the bucket time const TStr1Vec& scheduledEventDescriptions(core_t::TTime time) const override; diff --git a/include/model/CEventRateModel.h b/include/model/CEventRateModel.h index 7a72ccffb9..7592ea58fc 100644 --- a/include/model/CEventRateModel.h +++ b/include/model/CEventRateModel.h @@ -263,7 +263,7 @@ class MODEL_EXPORT CEventRateModel : public CIndividualModel { std::size_t computeMemoryUsage() const override; //! Get a view of the internals of the model for visualization. - CModelDetailsViewPtr details() const override; + TModelDetailsViewUPtr details() const override; //! Get the value of the \p feature of the person identified //! by \p pid for the bucketing interval containing \p time. diff --git a/include/model/CEventRatePopulationModel.h b/include/model/CEventRatePopulationModel.h index 78c6a408f2..6de0fd1c08 100644 --- a/include/model/CEventRatePopulationModel.h +++ b/include/model/CEventRatePopulationModel.h @@ -302,7 +302,7 @@ class MODEL_EXPORT CEventRatePopulationModel : public CPopulationModel { std::size_t computeMemoryUsage() const override; //! Get a view of the internals of the model for visualization. - CModelDetailsViewPtr details() const override; + TModelDetailsViewUPtr details() const override; //! Get the feature data corresponding to \p feature at \p time. const TSizeSizePrFeatureDataPrVec& featureData(model_t::EFeature feature, diff --git a/include/model/CMetricModel.h b/include/model/CMetricModel.h index 22c7410098..d8e44444cc 100644 --- a/include/model/CMetricModel.h +++ b/include/model/CMetricModel.h @@ -258,7 +258,7 @@ class MODEL_EXPORT CMetricModel : public CIndividualModel { std::size_t computeMemoryUsage() const override; //! Get a view of the internals of the model for visualization. - CModelDetailsViewPtr details() const override; + TModelDetailsViewUPtr details() const override; //! Get the value of the \p feature of the person identified //! by \p pid for the bucketing interval containing \p time. diff --git a/include/model/CMetricPopulationModel.h b/include/model/CMetricPopulationModel.h index ef17fd8f13..883c300f8b 100644 --- a/include/model/CMetricPopulationModel.h +++ b/include/model/CMetricPopulationModel.h @@ -266,7 +266,7 @@ class MODEL_EXPORT CMetricPopulationModel : public CPopulationModel { uint64_t checksum(bool includeCurrentBucketStats = true) const override; //! Get a view of the internals of the model for visualization. - CModelDetailsViewPtr details() const override; + TModelDetailsViewUPtr details() const override; //! Get the feature data corresponding to \p feature at \p time. const TSizeSizePrFeatureDataPrVec& featureData(model_t::EFeature feature, diff --git a/lib/core/unittest/CContainerPrinterTest.cc b/lib/core/unittest/CContainerPrinterTest.cc index c47c182634..1d2faf6e69 100644 --- a/lib/core/unittest/CContainerPrinterTest.cc +++ b/lib/core/unittest/CContainerPrinterTest.cc @@ -54,9 +54,9 @@ void CContainerPrinterTest::testAll() { CPPUNIT_ASSERT_EQUAL(std::string("[(1, \"null\"), (1.1, 3), (3.3, 5.1)]"), CContainerPrinter::print(map)); - std::auto_ptr pints[] = {std::auto_ptr(new int(2)), - std::auto_ptr(new int(3)), - std::auto_ptr(new int(2))}; + std::unique_ptr pints[] = {std::unique_ptr(new int(2)), + std::unique_ptr(new int(3)), + std::unique_ptr(new int(2))}; LOG_DEBUG(<< "pints = " << CContainerPrinter::print(std::begin(pints), std::end(pints))); CPPUNIT_ASSERT_EQUAL(std::string("[2, 3, 2]"), diff --git a/lib/model/CAnomalyDetector.cc b/lib/model/CAnomalyDetector.cc index 1400f554e6..5b8f9bffb5 100644 --- a/lib/model/CAnomalyDetector.cc +++ b/lib/model/CAnomalyDetector.cc @@ -36,7 +36,7 @@ namespace model { // We use short field names to reduce the state size namespace { -using TModelDetailsViewPtr = CAnomalyDetectorModel::CModelDetailsViewPtr; +using TModelDetailsViewUPtr = CAnomalyDetectorModel::TModelDetailsViewUPtr; // tag 'a' was previously used for persisting first time; // DO NOT USE; unless it is decided to break model state BWC @@ -439,7 +439,7 @@ void CAnomalyDetector::generateModelPlot(core_t::TTime bucketStartTime, if (terms.empty() || m_DataGatherer->partitionFieldValue().empty() || terms.find(m_DataGatherer->partitionFieldValue()) != terms.end()) { const CSearchKey& key = m_DataGatherer->searchKey(); - TModelDetailsViewPtr view = m_Model.get()->details(); + TModelDetailsViewUPtr view = m_Model.get()->details(); if (view.get()) { core_t::TTime bucketLength = m_ModelConfig.bucketLength(); for (core_t::TTime time = bucketStartTime; time < bucketEndTime; @@ -458,7 +458,7 @@ CForecastDataSink::SForecastModelPrerequisites CAnomalyDetector::getForecastPrerequisites() const { CForecastDataSink::SForecastModelPrerequisites prerequisites{0, 0, 0, true, false}; - TModelDetailsViewPtr view = m_Model->details(); + TModelDetailsViewUPtr view = m_Model->details(); // The view can be empty, e.g. for the counting model. if (view.get() == nullptr) { @@ -508,7 +508,7 @@ CAnomalyDetector::getForecastModels(bool persistOnDisk, return series; } - TModelDetailsViewPtr view = m_Model.get()->details(); + TModelDetailsViewUPtr view = m_Model.get()->details(); // The view can be empty, e.g. for the counting model. if (view.get() == nullptr) { diff --git a/lib/model/CCountingModel.cc b/lib/model/CCountingModel.cc index 342d8f7561..e07c94f0f5 100644 --- a/lib/model/CCountingModel.cc +++ b/lib/model/CCountingModel.cc @@ -329,8 +329,8 @@ std::size_t CCountingModel::staticSize() const { return sizeof(*this); } -CCountingModel::CModelDetailsViewPtr CCountingModel::details() const { - return CModelDetailsViewPtr(); +CCountingModel::TModelDetailsViewUPtr CCountingModel::details() const { + return TModelDetailsViewUPtr(); } core_t::TTime CCountingModel::currentBucketStartTime() const { diff --git a/lib/model/CEventRateModel.cc b/lib/model/CEventRateModel.cc index 22de3ae2cd..45548abc13 100644 --- a/lib/model/CEventRateModel.cc +++ b/lib/model/CEventRateModel.cc @@ -502,8 +502,8 @@ std::size_t CEventRateModel::computeMemoryUsage() const { return mem; } -CEventRateModel::CModelDetailsViewPtr CEventRateModel::details() const { - return CModelDetailsViewPtr(new CEventRateModelDetailsView(*this)); +CEventRateModel::TModelDetailsViewUPtr CEventRateModel::details() const { + return TModelDetailsViewUPtr(new CEventRateModelDetailsView(*this)); } const CEventRateModel::TFeatureData* diff --git a/lib/model/CEventRatePopulationModel.cc b/lib/model/CEventRatePopulationModel.cc index 14d6a83ff1..0fee5ee5e0 100644 --- a/lib/model/CEventRatePopulationModel.cc +++ b/lib/model/CEventRatePopulationModel.cc @@ -852,8 +852,8 @@ std::size_t CEventRatePopulationModel::staticSize() const { return sizeof(*this); } -CEventRatePopulationModel::CModelDetailsViewPtr CEventRatePopulationModel::details() const { - return CModelDetailsViewPtr(new CEventRatePopulationModelDetailsView(*this)); +CEventRatePopulationModel::TModelDetailsViewUPtr CEventRatePopulationModel::details() const { + return TModelDetailsViewUPtr(new CEventRatePopulationModelDetailsView(*this)); } const CEventRatePopulationModel::TSizeSizePrFeatureDataPrVec& diff --git a/lib/model/CMetricModel.cc b/lib/model/CMetricModel.cc index 523b9f1411..6671f32ebb 100644 --- a/lib/model/CMetricModel.cc +++ b/lib/model/CMetricModel.cc @@ -466,8 +466,8 @@ std::size_t CMetricModel::staticSize() const { return sizeof(*this); } -CMetricModel::CModelDetailsViewPtr CMetricModel::details() const { - return CModelDetailsViewPtr(new CMetricModelDetailsView(*this)); +CMetricModel::TModelDetailsViewUPtr CMetricModel::details() const { + return TModelDetailsViewUPtr(new CMetricModelDetailsView(*this)); } const CMetricModel::TFeatureData* diff --git a/lib/model/CMetricPopulationModel.cc b/lib/model/CMetricPopulationModel.cc index fe2d5265ab..df66e5662a 100644 --- a/lib/model/CMetricPopulationModel.cc +++ b/lib/model/CMetricPopulationModel.cc @@ -761,8 +761,8 @@ std::size_t CMetricPopulationModel::staticSize() const { return sizeof(*this); } -CMetricPopulationModel::CModelDetailsViewPtr CMetricPopulationModel::details() const { - return CModelDetailsViewPtr(new CMetricPopulationModelDetailsView(*this)); +CMetricPopulationModel::TModelDetailsViewUPtr CMetricPopulationModel::details() const { + return TModelDetailsViewUPtr(new CMetricPopulationModelDetailsView(*this)); } const TSizeSizePrFeatureDataPrVec& diff --git a/lib/model/unittest/CEventRateModelTest.cc b/lib/model/unittest/CEventRateModelTest.cc index dee8e7893a..c4f0f33e74 100644 --- a/lib/model/unittest/CEventRateModelTest.cc +++ b/lib/model/unittest/CEventRateModelTest.cc @@ -2895,9 +2895,9 @@ void CEventRateModelTest::testIgnoreSamplingGivenDetectionRules() { CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum()); // but the underlying models should be the same - CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView = + CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView = modelWithSkip->details(); - CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details(); + CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details(); uint64_t withSkipChecksum = static_cast( diff --git a/lib/model/unittest/CMetricModelTest.cc b/lib/model/unittest/CMetricModelTest.cc index 2471bd57a5..1f61241af8 100644 --- a/lib/model/unittest/CMetricModelTest.cc +++ b/lib/model/unittest/CMetricModelTest.cc @@ -2478,9 +2478,9 @@ void CMetricModelTest::testIgnoreSamplingGivenDetectionRules() { CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum()); // but the underlying models should be the same - CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView = + CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView = modelWithSkip->details(); - CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details(); + CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details(); // TODO this test fails due a different checksums for the decay rate and prior // uint64_t withSkipChecksum = modelWithSkipView->model(model_t::E_IndividualMeanByPerson, 0)->checksum(); diff --git a/lib/model/unittest/CMetricPopulationModelTest.cc b/lib/model/unittest/CMetricPopulationModelTest.cc index 5ce1983d33..b382a7e158 100644 --- a/lib/model/unittest/CMetricPopulationModelTest.cc +++ b/lib/model/unittest/CMetricPopulationModelTest.cc @@ -1499,9 +1499,9 @@ void CMetricPopulationModelTest::testIgnoreSamplingGivenDetectionRules() { // Checksums will be different because a 3rd model is created for attribute c3 CPPUNIT_ASSERT(modelWithSkip->checksum() != modelNoSkip->checksum()); - CAnomalyDetectorModel::CModelDetailsViewPtr modelWithSkipView = + CAnomalyDetectorModel::TModelDetailsViewUPtr modelWithSkipView = modelWithSkip->details(); - CAnomalyDetectorModel::CModelDetailsViewPtr modelNoSkipView = modelNoSkip->details(); + CAnomalyDetectorModel::TModelDetailsViewUPtr modelNoSkipView = modelNoSkip->details(); // but the underlying models for people p1 and p2 are the same uint64_t withSkipChecksum = modelWithSkipView diff --git a/lib/model/unittest/Mocks.cc b/lib/model/unittest/Mocks.cc index 7d1416fc8f..035fb20193 100644 --- a/lib/model/unittest/Mocks.cc +++ b/lib/model/unittest/Mocks.cc @@ -132,8 +132,8 @@ std::size_t CMockModel::staticSize() const { return 0; } -CMockModel::CModelDetailsViewPtr CMockModel::details() const { - CModelDetailsViewPtr result{new CMockModelDetailsView(*this)}; +CMockModel::TModelDetailsViewUPtr CMockModel::details() const { + TModelDetailsViewUPtr result{new CMockModelDetailsView(*this)}; return result; } diff --git a/lib/model/unittest/Mocks.h b/lib/model/unittest/Mocks.h index 9946268fda..a1a9cfcefc 100644 --- a/lib/model/unittest/Mocks.h +++ b/lib/model/unittest/Mocks.h @@ -94,7 +94,7 @@ class CMockModel : public CAnomalyDetectorModel { std::size_t staticSize() const override; - CModelDetailsViewPtr details() const override; + TModelDetailsViewUPtr details() const override; double attributeFrequency(std::size_t cid) const override;