Refactoring #1693

Feature #1290: === Core: framework ===

Feature #1712: == Code maintenance ==

Make consequential use of default values in initializer lists.

Added by wuttke almost 3 years ago. Updated almost 3 years ago.

Status:BacklogStart date:01 Dec 2016
Priority:LowDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

For example, in ParticleLayout.h we currently have three constructors, and four versions of addParticle:

class BA_CORE_API_ ParticleLayout : public ILayout
{
public:
    ParticleLayout();
    ParticleLayout(const IAbstractParticle& particle);
    ParticleLayout(const IAbstractParticle& particle, double abundance);
    ...
    void addParticle(const IAbstractParticle& particle);
    void addParticle(const IAbstractParticle& particle, double abundance);
    void addParticle(const IParticle& particle, double abundance, const kvector_t position);
    void addParticle(const IParticle& particle, double abundance, const kvector_t position, const IRotation& rotation);
    ...
}

By using default values in the longest initializer list, the shorter forms can be made redudant. This will save duplicate code, ensure consistency, and simplify the API.

Also consider: is there a need at all for ParticleLayout(const IAbstractParticle& particle) if the same can be achieved by ParticleLayout() followed by addParticle(const IAbstractParticle& particle) ? Only the latter form works if there is more than one layout, so why have special support for the special case of just one layout?

History

#1 Updated by wuttke almost 3 years ago

  • Description updated (diff)
  • Parent task set to #1290

#2 Updated by pospelov almost 3 years ago

I think such sequence of constructors with growing list of parameters was because of boost-python bindings. Probably with swig bindings we indeed can use single constructor with default values.

#3 Updated by wuttke almost 3 years ago

  • Parent task changed from #1290 to #1714

#4 Updated by wuttke almost 3 years ago

  • Parent task changed from #1714 to #1712

#5 Updated by wuttke almost 3 years ago

Particle also has four constructors (but may be more onerous to refactor):

    Particle();
    Particle(const IMaterial& p_material);
    Particle(const IMaterial& p_material, const IFormFactor& form_factor);
    Particle(const IMaterial& p_material, const IFormFactor& form_factor,
             const IRotation& rotation);

Also available in: Atom PDF