comparison Framework/Common/DatabaseManager.cpp @ 157:275e14f57f1e

replacing deprecated std::auto_ptr by std::unique_ptr
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 06 Jul 2020 12:45:58 +0200
parents 063aa53b5917
children 3236894320d6
comparison
equal deleted inserted replaced
156:710537acb488 157:275e14f57f1e
21 21
22 #include "DatabaseManager.h" 22 #include "DatabaseManager.h"
23 23
24 #include "../../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" 24 #include "../../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h"
25 25
26 #include <Compatibility.h> // For std::unique_ptr<>
26 #include <Logging.h> 27 #include <Logging.h>
27 #include <OrthancException.h> 28 #include <OrthancException.h>
28 29
29 #include <boost/thread.hpp> 30 #include <boost/thread.hpp>
30 31
139 IPrecompiledStatement& DatabaseManager::CacheStatement(const StatementLocation& location, 140 IPrecompiledStatement& DatabaseManager::CacheStatement(const StatementLocation& location,
140 const Query& query) 141 const Query& query)
141 { 142 {
142 LOG(TRACE) << "Caching statement from " << location.GetFile() << ":" << location.GetLine(); 143 LOG(TRACE) << "Caching statement from " << location.GetFile() << ":" << location.GetLine();
143 144
144 std::auto_ptr<IPrecompiledStatement> statement(GetDatabase().Compile(query)); 145 std::unique_ptr<IPrecompiledStatement> statement(GetDatabase().Compile(query));
145 146
146 IPrecompiledStatement* tmp = statement.get(); 147 IPrecompiledStatement* tmp = statement.get();
147 if (tmp == NULL) 148 if (tmp == NULL)
148 { 149 {
149 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); 150 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
336 } 337 }
337 338
338 339
339 void DatabaseManager::StatementBase::SetQuery(Query* query) 340 void DatabaseManager::StatementBase::SetQuery(Query* query)
340 { 341 {
341 std::auto_ptr<Query> protection(query); 342 std::unique_ptr<Query> protection(query);
342 343
343 if (query_.get() != NULL) 344 if (query_.get() != NULL)
344 { 345 {
345 LOG(ERROR) << "Cannot set twice a query"; 346 LOG(ERROR) << "Cannot set twice a query";
346 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 347 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
355 } 356 }
356 357
357 358
358 void DatabaseManager::StatementBase::SetResult(IResult* result) 359 void DatabaseManager::StatementBase::SetResult(IResult* result)
359 { 360 {
360 std::auto_ptr<IResult> protection(result); 361 std::unique_ptr<IResult> protection(result);
361 362
362 if (result_.get() != NULL) 363 if (result_.get() != NULL)
363 { 364 {
364 LOG(ERROR) << "Cannot execute twice a statement"; 365 LOG(ERROR) << "Cannot execute twice a statement";
365 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 366 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
502 503
503 void DatabaseManager::CachedStatement::Execute(const Dictionary& parameters) 504 void DatabaseManager::CachedStatement::Execute(const Dictionary& parameters)
504 { 505 {
505 try 506 try
506 { 507 {
507 std::auto_ptr<Query> query(ReleaseQuery()); 508 std::unique_ptr<Query> query(ReleaseQuery());
508 509
509 if (query.get() != NULL) 510 if (query.get() != NULL)
510 { 511 {
511 // Register the newly-created statement 512 // Register the newly-created statement
512 assert(statement_ == NULL); 513 assert(statement_ == NULL);
554 555
555 void DatabaseManager::StandaloneStatement::Execute(const Dictionary& parameters) 556 void DatabaseManager::StandaloneStatement::Execute(const Dictionary& parameters)
556 { 557 {
557 try 558 try
558 { 559 {
559 std::auto_ptr<Query> query(ReleaseQuery()); 560 std::unique_ptr<Query> query(ReleaseQuery());
560 assert(query.get() != NULL); 561 assert(query.get() != NULL);
561 562
562 // The "statement_" object must be kept as long as the "IResult" 563 // The "statement_" object must be kept as long as the "IResult"
563 // is not destroyed, as the "IResult" can make calls to the 564 // is not destroyed, as the "IResult" can make calls to the
564 // statement (this is the case for SQLite and MySQL) - (*) 565 // statement (this is the case for SQLite and MySQL) - (*)