Skip to content

Commit

Permalink
Merge pull request #24263 from ianna/dd-core-use-unique-ptrs
Browse files Browse the repository at this point in the history
DD Core: Use unique pointers in Store
  • Loading branch information
cmsbuild committed Aug 22, 2018
2 parents ab2e23a + 07b8839 commit eb3f27d
Show file tree
Hide file tree
Showing 68 changed files with 660 additions and 689 deletions.
8 changes: 5 additions & 3 deletions DetectorDescription/Core/interface/DDBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ template <class N, class C>
static auto end() { return StoreT::instance().end(); }
static auto begin() { return StoreT::instance().begin(); }

DDBase() : prep_(nullptr) { }
DDBase()
: prep_( nullptr ) { }
virtual ~DDBase() { /*never do this here: if (prep_) delete prep_;*/ }

const N & name() const { return prep_->name(); }
Expand Down Expand Up @@ -118,14 +119,15 @@ template <class N, class C>
: false;
}
void create( const N& name, C vals ) {
prep_ = StoreT::instance().create( name, vals );
prep_ = StoreT::instance().create( name, std::move( vals ) );
}
void create( const N& name ) {
prep_ = StoreT::instance().create( name );
}

private:
DDI::rep_type<N, C>* prep_;

DDI::rep_type<N, C>* prep_;
};

#endif
14 changes: 6 additions & 8 deletions DetectorDescription/Core/interface/DDCompactView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utility>
#include <vector>

#include "DetectorDescription/Core/interface/DDCompactViewImpl.h"
#include "DetectorDescription/Core/interface/DDRotationMatrix.h"
#include "DetectorDescription/Core/interface/DDTranslation.h"
#include "DetectorDescription/Core/interface/Store.h"
Expand All @@ -16,7 +17,6 @@
#include "DataFormats/Math/interface/Graph.h"
#include "DataFormats/Math/interface/GraphWalker.h"

class DDCompactViewImpl;
class DDDivision;
class DDName;
struct DDPosData;
Expand Down Expand Up @@ -92,8 +92,6 @@ class DDCompactView
//! \b EXPERIMENTAL! Creates a compact-view using a different root of the geometrical hierarchy
explicit DDCompactView(const DDLogicalPart & rootnodedata);

~DDCompactView();

//! Provides read-only access to the data structure of the compact-view.
const Graph & graph() const;
GraphWalker walker() const;
Expand Down Expand Up @@ -136,11 +134,11 @@ class DDCompactView
std::unique_ptr<DDCompactViewImpl> rep_;
std::unique_ptr<DDPosData> worldpos_ ;

DDI::Store<DDName, DDI::Material*> matStore_;
DDI::Store<DDName, DDI::Solid*> solidStore_;
DDI::Store<DDName, DDI::LogicalPart*> lpStore_;
DDI::Store<DDName, DDI::Specific*> specStore_;
DDI::Store<DDName, DDRotationMatrix*> rotStore_;
DDI::Store<DDName, std::unique_ptr<DDI::Material>> matStore_;
DDI::Store<DDName, std::unique_ptr<DDI::Solid>> solidStore_;
DDI::Store<DDName, std::unique_ptr<DDI::LogicalPart>> lpStore_;
DDI::Store<DDName, std::unique_ptr<DDI::Specific>> specStore_;
DDI::Store<DDName, std::unique_ptr<DDRotationMatrix>> rotStore_;
};

#endif
7 changes: 4 additions & 3 deletions DetectorDescription/Core/interface/DDConstant.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iostream>
#include <vector>
#include <memory>

#include "DetectorDescription/Core/interface/DDBase.h"
#include "DetectorDescription/Core/interface/DDName.h"
Expand All @@ -14,7 +15,7 @@ class ClhepEvaluator;
std::ostream & operator<<(std::ostream & o, const DDConstant & cons);

//! a named constant corresponding to the DDL-XML tag <Constant> and <ConstantsVector>
class DDConstant : public DDBase<DDName, double * >
class DDConstant : public DDBase<DDName, std::unique_ptr<double> >
{
public:
//! an uninitialized constant; one can assign an initialized constant to make it valid
Expand All @@ -24,7 +25,7 @@ class DDConstant : public DDBase<DDName, double * >
DDConstant(const DDName & name);

//! creation of a new named constant; if it already existed with the given name, it's overwritten with new values
DDConstant(const DDName & name, double* value);
DDConstant(const DDName & name, std::unique_ptr<double> value);

//! creates all DDConstants from the variables of the ClhepEvaluator
static void createConstantsFromEvaluator(ClhepEvaluator&);
Expand All @@ -37,6 +38,6 @@ class DDConstant : public DDBase<DDName, double * >
};

//! std::maps the XML naming convention, i.e. <Numeric name='foo' value='4711'/> -> DDNumeric
typedef DDConstant DDNumeric;
using DDNumeric = DDConstant;

#endif
3 changes: 2 additions & 1 deletion DetectorDescription/Core/interface/DDDivision.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#include <iosfwd>
#include <map>
#include <memory>
#include <string>
#include <vector>

Expand All @@ -75,7 +76,7 @@ namespace DDI {

std::ostream & operator<<( std::ostream &, const DDDivision &);

class DDDivision : public DDBase<DDName, DDI::Division*>
class DDDivision : public DDBase<DDName, std::unique_ptr<DDI::Division> >
{
public:

Expand Down
5 changes: 3 additions & 2 deletions DetectorDescription/Core/interface/DDLogicalPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iosfwd>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -89,11 +90,11 @@ std::ostream & operator<<( std::ostream &, const DDLogicalPart &);
}
\endcode
*/
class DDLogicalPart : public DDBase<DDName,DDI::LogicalPart*>
class DDLogicalPart : public DDBase<DDName,std::unique_ptr<DDI::LogicalPart> >
{
public:
//! The default constructor provides an uninitialzed reference object.
DDLogicalPart( void ) : DDBase<DDName,DDI::LogicalPart*>(){ }
DDLogicalPart( void ) : DDBase<DDName,std::unique_ptr<DDI::LogicalPart> >(){ }

//! Creates a reference object referring to the appropriate XML specification.
DDLogicalPart( const DDName & name );
Expand Down
11 changes: 6 additions & 5 deletions DetectorDescription/Core/interface/DDMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iostream>
#include <map>
#include <memory>
#include <string>

#include "DetectorDescription/Core/interface/DDReadMapType.h"
Expand All @@ -15,17 +16,17 @@ class DDMap;
std::ostream & operator<<(std::ostream & o, const DDMap & cons);

//! simply a std::map<std::string,double> supporting an addional operator[] const
typedef ReadMapType<double> dd_map_type;
using dd_map_type = ReadMapType<double>;

//! a named constant corresponding to the DDL-XML tag <Constant> and <ConstantsVector>
class DDMap : public DDBase<DDName, dd_map_type* >
class DDMap : public DDBase<DDName, std::unique_ptr<dd_map_type> >
{
public:
//! the type of the managed object
typedef dd_map_type value_type;
using value_type = dd_map_type;

//! size type for the size of the stored values
typedef dd_map_type::size_type size_t;
using size_t = dd_map_type::size_type;

//! an uninitialized constant; one can assign an initialized constant to make it valid
DDMap();
Expand All @@ -34,7 +35,7 @@ class DDMap : public DDBase<DDName, dd_map_type* >
DDMap(const DDName & name);

//! creation of a new named constant; if it already existed with the given name, it's overwritten with new values
DDMap(const DDName & name, dd_map_type* value);
DDMap(const DDName & name, std::unique_ptr<dd_map_type> value);

//! the size of the array of values
size_t size() const { return rep().size(); }
Expand Down
5 changes: 3 additions & 2 deletions DetectorDescription/Core/interface/DDMaterial.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DDMaterial_h

#include <iostream>
#include <memory>
#include <vector>
#include <utility>
#include "DetectorDescription/Core/interface/DDName.h"
Expand Down Expand Up @@ -39,12 +40,12 @@ namespace DDI { class Material; }
to specify the units of the quantities
making up a material.
*/
class DDMaterial : public DDBase<DDName,DDI::Material*>
class DDMaterial : public DDBase<DDName,std::unique_ptr<DDI::Material>>
{
friend std::ostream & operator<<(std::ostream &, const DDMaterial &);

public:
typedef std::vector<std::pair<DDMaterial,double> > FractionV;
using FractionV = std::vector<std::pair<DDMaterial, double>>;

//! Creates a uninitialized reference-object (see DDLogicalPart documentation for details on reference objects)
DDMaterial();
Expand Down
4 changes: 2 additions & 2 deletions DetectorDescription/Core/interface/DDPosData.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct DDPosData
const DDTranslation & translation() const { return trans_; }
const DDTranslation & trans() const { return trans_; }

const DDRotationMatrix & rotation() const { return *(rot_.rotation()); }
const DDRotationMatrix & rot() const { return *(rot_.rotation()); }
const DDRotationMatrix & rotation() const { return rot_.rotation(); }
const DDRotationMatrix & rot() const { return rot_.rotation(); }
const DDRotation & ddrot() const { return rot_; }
int copyno() const { return copyno_; }

Expand Down
9 changes: 4 additions & 5 deletions DetectorDescription/Core/interface/DDSolid.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cstddef>
#include <iosfwd>
#include <memory>
#include <vector>

#include "DetectorDescription/Core/interface/DDTranslation.h"
Expand Down Expand Up @@ -35,12 +36,10 @@ std::ostream & operator<<( std::ostream &, const DDSolid & );
to the documentation of DDLogicalPart.
*/
class DDSolid : public DDBase<DDName, DDI::Solid*>
class DDSolid : public DDBase< DDName, std::unique_ptr< DDI::Solid >>
{
friend std::ostream & operator <<( std::ostream &, const DDSolid & );
friend struct DDSolidFactory;
friend class DDDToPersFactory;
friend class DDPersToDDDFactory;

public:
//! Uninitialilzed solid reference-object; for further details on reference-objects see documentation of DDLogicalPart
Expand All @@ -67,7 +66,7 @@ class DDSolid : public DDBase<DDName, DDI::Solid*>
DDSolidShape shape( void ) const;

private:
DDSolid( const DDName &, DDI::Solid * );
DDSolid( const DDName &, std::unique_ptr<DDI::Solid> );
DDSolid( const DDName &, DDSolidShape, const std::vector<double> & );
};

Expand Down Expand Up @@ -196,7 +195,7 @@ class DDBooleanSolid : public DDSolid

private:

DDI::BooleanSolid * boolean_;
const DDI::BooleanSolid & boolean_;
};

class DDMultiUnionSolid : public DDSolid
Expand Down
3 changes: 2 additions & 1 deletion DetectorDescription/Core/interface/DDSpecifics.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <iosfwd>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -38,7 +39,7 @@ std::ostream & operator<<( std::ostream &, const DDSpecifics & );
DDSpecifics are lightweighted reference-objects. For further information concerning
reference-objects refere to the documentation of DDLogicalPart.
*/
class DDSpecifics : public DDBase< DDName, DDI::Specific* >
class DDSpecifics : public DDBase< DDName, std::unique_ptr<DDI::Specific> >
{
friend std::ostream & operator<<( std::ostream &, const DDSpecifics &);

Expand Down
9 changes: 5 additions & 4 deletions DetectorDescription/Core/interface/DDStrVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define DETECTOR_DESCRIPTION_CORE_DDSTRVECTOR_H

#include <iostream>
#include <memory>
#include <string>
#include <vector>

Expand All @@ -14,9 +15,9 @@ class DDStrVector;
std::ostream & operator<<( std::ostream & o, const DDStrVector & cons );

//! a named constant corresponding to the DDL-XML tag <Constant> and <ConstantsStrVector>
class DDStrVector : public DDBase< DDName, std::vector<std::string>* >
class DDStrVector : public DDBase< DDName, std::unique_ptr<std::vector<std::string>>>
{
public:
public:

//! size type for the size of the stored values
using size_t = std::vector<std::string>::size_type;
Expand All @@ -31,9 +32,9 @@ class DDStrVector : public DDBase< DDName, std::vector<std::string>* >
DDStrVector( const DDName & name );

//! creation of a new named constant; if it already existed with the given name, it's overwritten with new values
DDStrVector( const DDName & name, std::vector<std::string>* value );
DDStrVector( const DDName & name, std::unique_ptr<std::vector<std::string>> value );

//! the size of the array of values
//! the size of the array of values
size_t size() const { return rep().size(); }

//! the stored values
Expand Down
5 changes: 3 additions & 2 deletions DetectorDescription/Core/interface/DDString.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "DetectorDescription/Core/interface/DDName.h"
#include <string>
#include <iostream>
#include <memory>

class DDString;

Expand All @@ -13,7 +14,7 @@ class DDString;
std::ostream & operator<<(std::ostream & o, const DDString & cons);

//! a named constant corresponding to the DDL-XML tag <Constant> and <ConstantsVector>
class DDString : public DDBase<DDName, std::string * >
class DDString : public DDBase<DDName, std::unique_ptr<std::string> >
{
public:
//! an uninitialized constant; one can assign an initialized constant to make it valid
Expand All @@ -23,7 +24,7 @@ class DDString : public DDBase<DDName, std::string * >
DDString(const DDName & name);

//! creation of a new named constant; if it already existed with the given name, it's overwritten with new values
DDString(const DDName & name, std::string* value);
DDString(const DDName & name, std::unique_ptr<std::string> value);

//! return the first stored value; does not check boundaries!
const std::string & value() const { return rep(); }
Expand Down

0 comments on commit eb3f27d

Please sign in to comment.