Commit abaa8834 authored by Benedikt Hegner's avatar Benedikt Hegner
Browse files

Prefer std::make_unique over explicit call to new (mr !530)

parents 23f219fe 2f949c7e
Pipeline #268637 passed with stages
in 19 minutes and 21 seconds
......@@ -53,13 +53,9 @@ namespace Tuples
// find the item by name
auto ifound = m_map.find( key );
// existing item?
if ( m_map.end() != ifound ) {
return ifound->second.get();
} // RETURN
if ( m_map.end() != ifound ) return ifound->second.get(); // RETURN
// check the tuple for booking:
if ( !tuple ) {
return nullptr;
}
if ( !tuple ) return nullptr;
// check the existence of the name
if ( !tuple->goodItem( key ) ) {
tuple->Error( "ItemStore::getItem('" + key + "') item name is not unique" ).ignore();
......@@ -73,7 +69,7 @@ namespace Tuples
}
// create new item:
// add the newly created item into the store:
auto stored = m_map.emplace( key, std::unique_ptr<NTuple::Item<VALUE>>{new NTuple::Item<VALUE>()} );
auto stored = m_map.emplace( key, std::make_unique<NTuple::Item<VALUE>>() );
if ( !stored.second ) {
tuple->Warning( "ItemStore::getItem('" + key + "') item already exists, new one not inserted!" ).ignore();
return nullptr;
......@@ -96,7 +92,6 @@ namespace Tuples
return item.get(); // RETURN
}
private:
// delete copy constructor and assignment
ItemStore( const ItemStore& ) = delete;
ItemStore& operator=( const ItemStore& ) = delete;
......
......@@ -190,7 +190,7 @@ DataObject* HistogramSvc::createPath( const string& newPath )
//------------------------------------------------------------------------------
DataObject* HistogramSvc::createDirectory( const string& parentDir, const string& subDir )
{
std::unique_ptr<DataObject> directory{new DataObject()};
auto directory = std::make_unique<DataObject>();
if ( directory ) {
DataObject* pnode;
StatusCode status = DataSvc::retrieveObject( parentDir, pnode );
......@@ -272,21 +272,19 @@ StatusCode HistogramSvc::initialize()
StatusCode status = DataSvc::initialize();
// Set root object
if ( status.isSuccess() ) {
std::unique_ptr<DataObject> rootObj{new DataObject()};
status = setRoot( "/stat", rootObj.get() );
if ( status.isSuccess() ) {
rootObj.release();
} else {
auto rootObj = std::make_unique<DataObject>();
status = setRoot( "/stat", rootObj.get() );
if ( status.isFailure() ) {
error() << "Unable to set hstogram data store root." << endmsg;
return status;
}
rootObj.release();
auto svc = service<IConversionSvc>( "HistogramPersistencySvc", true );
if ( svc ) {
setDataLoader( svc.get() ).ignore();
} else {
if ( !svc ) {
error() << "Could not find HistogramPersistencySvc." << endmsg;
return StatusCode::FAILURE;
}
setDataLoader( svc.get() ).ignore();
// Connect all input streams (if any)
for ( auto& j : m_input ) {
status = connectInput( j );
......@@ -318,7 +316,7 @@ IHistogram1D* HistogramSvc::sliceX( const string& name, const IHistogram2D& h, i
throw GaudiException( "Cannot cast 2D histogram to H2D to create sliceX `" + name + "'!", "HistogramSvc",
StatusCode::FAILURE );
}
if ( o.first && registerObject( name, (IBaseHistogram*)o.second ).isSuccess() ) {
if ( o.first && registerObject( name, o.second ).isSuccess() ) {
return o.second;
}
delete o.first;
......
......@@ -221,8 +221,8 @@ StatusCode EventCollectionSelector::finalize()
/// Create a new event loop context
StatusCode EventCollectionSelector::createContext( Context*& refpCtxt ) const
{
refpCtxt = nullptr;
std::unique_ptr<MyContextType> ctxt( new MyContextType() );
refpCtxt = nullptr;
auto ctxt = std::make_unique<MyContextType>();
StatusCode status = connectCollection( ctxt.get() );
if ( !status.isSuccess() ) {
error() << "Unable to connect Collection file \"" << m_database << "\"" << endmsg;
......
......@@ -99,7 +99,7 @@ void IncidentSvc::addListener( IIncidentListener* lis, const std::string& type,
auto itMap = m_listenerMap.find( ltype );
if ( itMap == m_listenerMap.end() ) {
// if not found, create and insert now a list of listeners
auto p = m_listenerMap.insert( {ltype, std::unique_ptr<ListenerList>( new ListenerList() )} );
auto p = m_listenerMap.insert( {ltype, std::make_unique<ListenerList>()} );
if ( !p.second ) { /* OOPS */
}
itMap = p.first;
......
......@@ -51,17 +51,15 @@ static bool UnitsNode( gp::Node* node, const std::string& search_path, gp::Inclu
static std::unique_ptr<gp::PropertyName> GetPropertyName( const gp::Node* node )
{
if ( node->children.size() == 1 ) {
return std::unique_ptr<gp::PropertyName>( new gp::PropertyName( node->children[0].value, node->position ) );
} else {
std::string delim;
std::string client;
for ( unsigned int i = 0; i < ( node->children.size() - 1 ); ++i ) {
client += delim + node->children[i].value;
delim = '.';
}
return std::unique_ptr<gp::PropertyName>(
new gp::PropertyName( client, node->children[node->children.size() - 1].value, node->position ) );
return std::make_unique<gp::PropertyName>( node->children[0].value, node->position );
}
std::string delim;
std::string client;
for ( unsigned int i = 0; i < ( node->children.size() - 1 ); ++i ) {
client += delim + node->children[i].value;
delim = '.';
}
return std::make_unique<gp::PropertyName>( client, node->children[node->children.size() - 1].value, node->position );
}
// ============================================================================
static std::unique_ptr<gp::PropertyValue> GetPropertyValue( const gp::Node* node, gp::Catalog* catalog,
......@@ -83,25 +81,25 @@ static std::unique_ptr<gp::PropertyValue> GetPropertyValue( const gp::Node* node
if ( units->Find( unit_name, unit_value ) ) {
// We have found a unit
double val = std::stod( node->value );
value.reset( new gp::PropertyValue( std::to_string( val * unit_value ) ) );
value = std::make_unique<gp::PropertyValue>( std::to_string( val * unit_value ) );
} else {
// Unit not found
throw gp::PositionalPropertyValueException::CouldNotFindUnit( node->children[0].position, unit_name );
}
} else {
value.reset( new gp::PropertyValue( node->value ) );
value = std::make_unique<gp::PropertyValue>( node->value );
}
break;
}
// ------------------------------------------------------------------------
case gp::Node::kString: {
// TODO,C++14: use std::quoted
value.reset( new gp::PropertyValue( '"' + node->value + '"' ) );
value = std::make_unique<gp::PropertyValue>( '"' + node->value + '"' );
break;
}
// ------------------------------------------------------------------------
case gp::Node::kBool: {
value.reset( new gp::PropertyValue( node->value ) );
value = std::make_unique<gp::PropertyValue>( node->value );
break;
}
// ------------------------------------------------------------------------
......@@ -110,7 +108,7 @@ static std::unique_ptr<gp::PropertyValue> GetPropertyValue( const gp::Node* node
result.reserve( node->children.size() );
std::transform( std::begin( node->children ), std::end( node->children ), std::back_inserter( result ),
[&]( const gp::Node& child ) { return GetPropertyValue( &child, catalog, units )->ToString(); } );
value.reset( new gp::PropertyValue( std::move( result ) ) );
value = std::make_unique<gp::PropertyValue>( std::move( result ) );
break;
}
// ------------------------------------------------------------------------
......@@ -121,7 +119,7 @@ static std::unique_ptr<gp::PropertyValue> GetPropertyValue( const gp::Node* node
auto vvalue = GetPropertyValue( &child.children[1], catalog, units );
result.emplace( kvalue->ToString(), vvalue->ToString() );
}
value.reset( new gp::PropertyValue( std::move( result ) ) );
value = std::make_unique<gp::PropertyValue>( std::move( result ) );
break;
}
// ------------------------------------------------------------------------
......@@ -129,7 +127,7 @@ static std::unique_ptr<gp::PropertyValue> GetPropertyValue( const gp::Node* node
auto property = GetPropertyName( node );
gp::Property* exists = catalog->Find( property->client(), property->property() );
if ( exists ) {
value.reset( new gp::PropertyValue( exists->property_value() ) );
value = std::make_unique<gp::PropertyValue>( exists->property_value() );
} else {
throw gp::PositionalPropertyValueException::CouldNotFindProperty( node->position, property->ToString() );
}
......@@ -142,7 +140,7 @@ static std::unique_ptr<gp::PropertyValue> GetPropertyValue( const gp::Node* node
reference.push_back( property->client() );
reference.push_back( property->property() );
value.reset( new gp::PropertyValue( std::move( reference ), property->position(), true ) );
value = std::make_unique<gp::PropertyValue>( std::move( reference ), property->position(), true );
break;
}
// ------------------------------------------------------------------------
......
......@@ -49,7 +49,7 @@ StatusCode JobOptionsSvc::initialize()
StatusCode JobOptionsSvc::addPropertyToCatalogue( const std::string& client,
const Gaudi::Details::PropertyBase& property )
{
std::unique_ptr<Gaudi::Details::PropertyBase> p{new Gaudi::Property<std::string>( property.name(), "" )};
auto p = std::make_unique<Gaudi::Property<std::string>>( property.name(), "" );
return property.load( *p ) ? m_svc_catalog.addProperty( client, p.release() ) : StatusCode::FAILURE;
}
// ============================================================================
......
......@@ -16,15 +16,8 @@ DECLARE_SERVICE_FACTORY( ThreadPoolSvc )
//=============================================================================
ThreadPoolSvc::ThreadPoolSvc( const std::string& name, ISvcLocator* svcLoc )
: base_class( name, svcLoc )
, m_threadInitTools( this )
, m_init( false )
, m_threadPoolSize( 0 )
, m_tbbSchedInit( nullptr )
, m_barrier( nullptr )
ThreadPoolSvc::ThreadPoolSvc( const std::string& name, ISvcLocator* svcLoc ) : extends( name, svcLoc )
{
declareProperty( "ThreadInitTools", m_threadInitTools, "ToolHandleArray of IThreadInitTools" );
}
......@@ -44,12 +37,11 @@ StatusCode ThreadPoolSvc::initialize()
error() << "Unable to retrieve ThreadInitTools Array" << endmsg;
return StatusCode::FAILURE;
}
if ( m_threadInitTools.size() != 0 ) {
info() << "retrieved " << m_threadInitTools.size() << " thread init tools" << endmsg;
} else {
if ( m_threadInitTools.size() != 0 ) {
info() << "retrieved " << m_threadInitTools.size() << " thread init tools" << endmsg;
} else {
info() << "no thread init tools attached" << endmsg;
}
info() << "no thread init tools attached" << endmsg;
}
return StatusCode::SUCCESS;
......@@ -98,7 +90,7 @@ StatusCode ThreadPoolSvc::initPool( const int& poolSize )
if ( thePoolSize != -1 ) thePoolSize += 1;
// Create the TBB task scheduler
m_tbbSchedInit = std::unique_ptr<tbb::task_scheduler_init>( new tbb::task_scheduler_init( thePoolSize ) );
m_tbbSchedInit = std::make_unique<tbb::task_scheduler_init>( thePoolSize );
// Create the barrier for task synchronization
if ( m_threadPoolSize <= -1 ) thePoolSize = m_tbbSchedInit->default_num_threads();
if ( msgLevel( MSG::DEBUG ) ) {
......@@ -106,7 +98,7 @@ StatusCode ThreadPoolSvc::initPool( const int& poolSize )
}
Gaudi::Concurrency::ConcurrencyFlags::setNumThreads( thePoolSize );
m_barrier = std::unique_ptr<boost::barrier>( new boost::barrier( thePoolSize ) );
m_barrier = std::make_unique<boost::barrier>( thePoolSize );
} else {
Gaudi::Concurrency::ConcurrencyFlags::setNumThreads( 1 );
......
......@@ -30,18 +30,18 @@ public:
ThreadPoolSvc( const std::string& name, ISvcLocator* svc );
/// Initialise
virtual StatusCode initialize() override final;
StatusCode initialize() override final;
/// Finalise
virtual StatusCode finalize() override final;
StatusCode finalize() override final;
/// Initialize the thread pool and launch the ThreadInitTasks.
virtual StatusCode initPool( const int& poolSize ) override final;
StatusCode initPool( const int& poolSize ) override final;
/// Terminate the thread pool and launch thread termination tasks.
virtual StatusCode terminatePool() override final;
StatusCode terminatePool() override final;
virtual int poolSize() const override final { return m_threadPoolSize; }
int poolSize() const override final { return m_threadPoolSize; }
virtual bool isInit() const { return m_init; }
......@@ -50,13 +50,13 @@ private:
StatusCode launchTasks( bool finalize = false );
/// Handle array of thread init tools
ToolHandleArray<IThreadInitTool> m_threadInitTools;
ToolHandleArray<IThreadInitTool> m_threadInitTools = {this};
/// Was the thread pool initialized?
bool m_init;
bool m_init = false;
/// Size of the thread pool allocated
int m_threadPoolSize;
int m_threadPoolSize = 0;
/// Mutex used to protect the initPool and terminatePool methods.
tbb::spin_mutex m_initMutex;
......
......@@ -25,15 +25,6 @@ namespace ba = boost::algorithm;
// ============================================================================
#include "ParticlePropertySvc.h"
// ============================================================================
namespace
{
//@FIXME/@TODO remove once we can assume C++14...
template <typename T, class... Args>
std::unique_ptr<T> make_unique_( Args&&... args )
{
return std::unique_ptr<T>( new T( std::forward<Args>( args )... ) );
}
}
namespace Gaudi
{
/** Instantiation of a static factory class used by clients to create
......@@ -142,8 +133,8 @@ namespace Gaudi
double maxWidth )
{
//
auto i = m_owned.insert( make_unique_<ParticleProperty>( particle, geantId, jetsetId, charge, mass, tlife, evtName,
pythiaId, maxWidth ) );
auto i = m_owned.insert( std::make_unique<ParticleProperty>( particle, geantId, jetsetId, charge, mass, tlife,
evtName, pythiaId, maxWidth ) );
//
return i.second ? push_back( i.first->get() ) : StatusCode::FAILURE;
}
......
......@@ -335,7 +335,7 @@ namespace Gaudi
}
}
static std::unique_ptr<Logger> s_logger( new Logger );
static auto s_logger = std::make_unique<Logger>();
Logger& logger() { return *s_logger; }
void setLogger( Logger* logger ) { s_logger.reset( logger ); }
......
......@@ -3,12 +3,6 @@
DECLARE_COMPONENT( FileReadTool )
FileReadTool::FileReadTool( const std::string& type, const std::string& name, const IInterface* parent )
: base_class( type, name, parent )
{
// declareInterface<IFileAccess>(this);
}
std::unique_ptr<std::istream> FileReadTool::open( const std::string& url )
{
// remove the optional "file://" from the beginning of the url
......@@ -18,7 +12,7 @@ std::unique_ptr<std::istream> FileReadTool::open( const std::string& url )
} else {
path = url;
}
return std::unique_ptr<std::istream>( new std::ifstream{path} );
return std::make_unique<std::ifstream>( path );
}
const std::vector<std::string>& FileReadTool::protocols() const
......
......@@ -13,12 +13,9 @@
* @author Marco Clemencic
* @date 2008-01-18
*/
class FileReadTool : public extends<AlgTool, IFileAccess>
{
public:
struct FileReadTool : extends<AlgTool, IFileAccess> {
/// Standard constructor
FileReadTool( const std::string& type, const std::string& name, const IInterface* parent );
using extends::extends;
std::unique_ptr<std::istream> open( const std::string& url ) override;
......
......@@ -209,12 +209,12 @@ void XMLFileCatalog::init()
{
string xmlFile = getfile( false );
try {
m_parser.reset( new XercesDOMParser );
m_parser = std::make_unique<XercesDOMParser>();
m_parser->setValidationScheme( XercesDOMParser::Val_Auto );
m_parser->setDoNamespaces( false );
DTDRedirect dtdinmem;
m_parser->setEntityResolver( &dtdinmem );
if ( !m_errHdlr ) m_errHdlr.reset( new ErrHandler( m_msgSvc ) );
if ( !m_errHdlr ) m_errHdlr = std::make_unique<ErrHandler>( m_msgSvc );
m_parser->setErrorHandler( m_errHdlr.get() );
if ( !xmlFile.empty() ) {
m_parser->parse( xmlFile.c_str() );
......@@ -451,7 +451,7 @@ void XMLFileCatalog::commit()
string xmlfile = getfile( true );
XMLStr ii( "LS" );
DOMImplementation* imp = DOMImplementationRegistry::getDOMImplementation( ii );
std::unique_ptr<XMLFormatTarget> tar{new LocalFileFormatTarget( xmlfile.c_str() )};
auto tar = std::make_unique<LocalFileFormatTarget>( xmlfile.c_str() );
#if _XERCES_VERSION <= 30000
DOMWriter* wr = imp->createDOMWriter();
wr->setFeature( XMLUni::fgDOMWRTFormatPrettyPrint, true );
......
......@@ -215,8 +215,8 @@ StatusCode RootCnvSvc::connectDatabase( CSTR dataset, int mode, RootDataConnecti
bool fire_incident = false;
*con = nullptr;
if ( !c ) {
std::unique_ptr<RootDataConnection> connection( new RootDataConnection( this, dataset, m_setup ) );
StatusCode sc = ( mode != IDataConnection::READ )
auto connection = std::make_unique<RootDataConnection>( this, dataset, m_setup );
StatusCode sc = ( mode != IDataConnection::READ )
? m_ioMgr->connectWrite( connection.get(), IDataConnection::IoType( mode ), "ROOT" )
: m_ioMgr->connectRead( false, connection.get() );
c = sc.isSuccess() ? m_ioMgr->connection( dataset ) : nullptr;
......
......@@ -46,8 +46,8 @@ namespace RootHistCnv
if ( r && h ) {
// Need to flip representation .... clumsy for the time being, because
// THXY constructor has no "generic" copy constructor
std::unique_ptr<T> p( new T() );
S* s = dynamic_cast<S*>( r->tObj() );
auto p = std::make_unique<T>();
S* s = dynamic_cast<S*>( r->tObj() );
if ( s && p.get() ) {
TTH<S>* casted = (TTH<S>*)s;
TArray* a = dynamic_cast<TArray*>( s );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment