Skip to content
Snippets Groups Projects
Commit fea32cc8 authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Replaced member auto_ptr and pure pointers with boost::scoped_ptr

parent 7826f5c0
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@
#include "FormFactorDecoratorFactor.h"
#include "HomogeneousMaterial.h"
#include <memory>
#include <boost/scoped_ptr.hpp>
//! @class FormFactorDecoratorMaterial
//! @ingroup formfactors_decorations
......@@ -56,8 +56,8 @@ private:
complex_t getRefractiveIndexFactor() const;
complex_t m_wavevector_scattering_factor;
std::auto_ptr<IMaterial> mP_material;
std::auto_ptr<IMaterial> mP_ambient_material;
boost::scoped_ptr<IMaterial> mP_material;
boost::scoped_ptr<IMaterial> mP_ambient_material;
};
#endif /* FORMFACTORDECORATORMATERIAL_H_ */
......
......@@ -20,7 +20,6 @@
#include "IMaterial.h"
#include "Rotations.h"
#include <memory>
#include <boost/scoped_ptr.hpp>
//! @class IParticle
......@@ -73,7 +72,7 @@ public:
protected:
virtual void applyTransformationToSubParticles(const IRotation &rotation) = 0;
std::auto_ptr<IRotation> mP_rotation;
boost::scoped_ptr<IRotation> mP_rotation;
};
inline void IParticle::setTransformation(const IRotation &rotation)
......
......@@ -21,6 +21,8 @@
#include "FormFactorDecoratorTransformation.h"
#include "IMaterial.h"
#include <boost/scoped_ptr.hpp>
//! @class Particle
//! @ingroup samples
//! @brief A particle with a form factor and refractive index
......@@ -47,14 +49,13 @@ public:
//! scattering power)
virtual void setAmbientMaterial(const IMaterial& material)
{
if(mp_ambient_material != &material) {
delete mp_ambient_material;
mp_ambient_material = material.clone();
if(mP_ambient_material.get() != &material) {
mP_ambient_material.reset(material.clone());
}
}
//! Returns particle's material.
virtual const IMaterial* getAmbientMaterial() const { return mp_ambient_material; }
virtual const IMaterial* getAmbientMaterial() const { return mP_ambient_material.get(); }
//! Create a form factor which includes the particle's shape,
//! material, ambient material, an optional transformation and an extra
......@@ -64,19 +65,18 @@ public:
//! Sets _material_.
virtual void setMaterial(const IMaterial& material) {
if(mp_material != &material) {
delete mp_material;
mp_material = material.clone();
if(mP_material.get() != &material) {
mP_material.reset(material.clone());
}
}
//! Returns particle's material.
virtual const IMaterial* getMaterial() const { return mp_material; }
virtual const IMaterial* getMaterial() const { return mP_material.get(); }
//! Returns refractive index of the particle
virtual complex_t getRefractiveIndex() const
{
return (mp_material ? mp_material->getRefractiveIndex()
return (mP_material.get() ? mP_material->getRefractiveIndex()
: complex_t(0,0));
}
......@@ -85,16 +85,16 @@ public:
//! Returns the form factor
const IFormFactor* getFormFactor() const {
return mp_form_factor;
return mP_form_factor.get();
}
protected:
IFormFactor *createTransformedFormFactor() const;
//! Propagates a transformation to child particles
virtual void applyTransformationToSubParticles(const IRotation& rotation);
IMaterial* mp_material;
IMaterial* mp_ambient_material;
IFormFactor* mp_form_factor;
boost::scoped_ptr<IMaterial> mP_material;
boost::scoped_ptr<IMaterial> mP_ambient_material;
boost::scoped_ptr<IFormFactor> mP_form_factor;
};
#endif // PARTICLE_H
......
......@@ -26,7 +26,7 @@ void ICompositeSample::registerChild(ISample *sample)
{
if(sample) {
m_samples.push_back(sample);
}else {
} else {
throw NullPointerException("ICompositeSample::registerChild -> Error. Null pointer.");
}
}
......
......@@ -20,50 +20,40 @@
Particle::Particle()
: mp_material(0)
, mp_ambient_material(0)
, mp_form_factor(0)
{
setName("Particle");
}
Particle::Particle(const IMaterial &p_material)
: mp_material(p_material.clone())
, mp_ambient_material(0)
, mp_form_factor(0)
: mP_material(p_material.clone())
{
setName("Particle");
}
Particle::Particle(const IMaterial &p_material, const IFormFactor &form_factor)
: mp_material(p_material.clone())
, mp_ambient_material(0)
, mp_form_factor(form_factor.clone())
: mP_material(p_material.clone())
, mP_form_factor(form_factor.clone())
{
setName("Particle");
registerChild(mp_form_factor);
registerChild(mP_form_factor.get());
}
Particle::Particle(const IMaterial &p_material, const IFormFactor& form_factor,
const IRotation &rotation)
: mp_material(p_material.clone())
, mp_ambient_material(0)
, mp_form_factor(form_factor.clone())
: mP_material(p_material.clone())
, mP_form_factor(form_factor.clone())
{
setName("Particle");
mP_rotation.reset(rotation.clone());
registerChild(mp_form_factor);
registerChild(mP_form_factor.get());
}
Particle::~Particle()
{
delete mp_material;
delete mp_ambient_material;
delete mp_form_factor;
}
......@@ -71,9 +61,9 @@ Particle* Particle::clone() const
{
Particle *result = new Particle();
if(mp_form_factor) result->setFormFactor(*mp_form_factor);
result->setMaterial(*mp_material);
result->setAmbientMaterial(*mp_ambient_material);
if(mP_form_factor.get()) result->setFormFactor(*mP_form_factor);
result->setMaterial(*mP_material);
result->setAmbientMaterial(*mP_ambient_material);
if(mP_rotation.get()) result->setTransformation(*mP_rotation);
result->setName(getName());
......@@ -84,11 +74,12 @@ Particle* Particle::clone() const
Particle* Particle::cloneInvertB() const
{
Particle *result = new Particle();
if(mp_form_factor) result->setFormFactor(*mp_form_factor);
if(mP_form_factor.get()) result->setFormFactor(*mP_form_factor);
if(mp_material) result->mp_material = Materials::createInvertedMaterial(mp_material);
if(mp_ambient_material)
result->mp_ambient_material = Materials::createInvertedMaterial(mp_ambient_material);
if(mP_material.get())
result->mP_material.reset(Materials::createInvertedMaterial(mP_material.get()));
if(mP_ambient_material)
result->mP_ambient_material.reset(Materials::createInvertedMaterial(mP_ambient_material.get()));
if(mP_rotation.get()) result->mP_rotation.reset(mP_rotation->clone());
......@@ -107,36 +98,35 @@ IFormFactor* Particle::createFormFactor(
new FormFactorDecoratorMaterial(
p_transformed_ff, wavevector_scattering_factor);
if (mP_rotation.get()) {
boost::scoped_ptr<const IMaterial> transformed_material(mp_material->
boost::scoped_ptr<const IMaterial> transformed_material(mP_material->
createTransformedMaterial(*mP_rotation));
p_ff->setMaterial(*transformed_material);
} else {
p_ff->setMaterial(*mp_material);
p_ff->setMaterial(*mP_material);
}
p_ff->setAmbientMaterial(*mp_ambient_material);
p_ff->setAmbientMaterial(*mP_ambient_material);
return p_ff;
}
void Particle::setFormFactor(const IFormFactor &form_factor)
{
if (&form_factor != mp_form_factor) {
deregisterChild(mp_form_factor);
delete mp_form_factor;
mp_form_factor = form_factor.clone();
registerChild(mp_form_factor);
if (&form_factor != mP_form_factor.get()) {
deregisterChild(mP_form_factor.get());
mP_form_factor.reset(form_factor.clone());
registerChild(mP_form_factor.get());
}
}
IFormFactor* Particle::createTransformedFormFactor() const
{
if(!mp_form_factor) return 0;
if(!mP_form_factor.get()) return 0;
IFormFactor *p_result;
if(mP_rotation.get()) {
p_result = new FormFactorDecoratorTransformation(
mp_form_factor->clone(), *mP_rotation);
mP_form_factor->clone(), *mP_rotation);
}
else {
p_result = mp_form_factor->clone();
p_result = mP_form_factor->clone();
}
return p_result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment