Ignore:
Timestamp:
Apr 15, 2010, 10:54:26 AM (16 years ago)
Author:
Tillmann Crueger <crueger@…>
Children:
32842d8
Parents:
1f591b
Message:

Changed implementation of Vector to forward operations to contained objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • molecuilder/src/vector.hpp

    r1f591b re7ea64  
    1515#include <gsl/gsl_multimin.h>
    1616
     17#include <memory>
     18
    1719#include "defs.hpp"
    1820
     
    2628  // this struct is used to indicate calls to the Baseconstructor from inside vectors.
    2729  struct Baseconstructor{};
    28   public:
     30public:
    2931
    3032  Vector();
     
    3335  virtual ~Vector();
    3436
    35   virtual double Distance(const Vector &y) const;
     37  // Method implemented by forwarding to the Representation
     38
    3639  virtual double DistanceSquared(const Vector &y) const;
    3740  virtual double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
     
    3942  virtual double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const;
    4043  virtual double ScalarProduct(const Vector &y) const;
    41   virtual double Norm() const;
    42   virtual double NormSquared() const;
    4344  virtual double Angle(const Vector &y) const;
    4445  virtual bool IsZero() const;
     
    4950  virtual void AddVector(const Vector &y);
    5051  virtual void SubtractVector(const Vector &y);
    51   virtual void CopyVector(const Vector &y);
    5252  virtual void VectorProduct(const Vector &y);
    5353  virtual void ProjectOntoPlane(const Vector &y);
    5454  virtual void ProjectIt(const Vector &y);
    5555  virtual Vector Projection(const Vector &y) const;
    56   virtual void Zero();
    57   virtual void One(const double one);
    58   virtual void Init(const double x1, const double x2, const double x3);
    59   virtual void Normalize();
    60   virtual void Translate(const Vector &x);
    6156  virtual void Mirror(const Vector &x);
    62   virtual void Scale(const double ** const factor);
    63   virtual void Scale(const double * const factor);
     57  virtual void ScaleAll(const double *factor);
    6458  virtual void Scale(const double factor);
    6559  virtual void MatrixMultiplication(const double * const M);
    6660  virtual bool InverseMatrixMultiplication(const double * const M);
    6761  virtual void KeepPeriodic(const double * const matrix);
    68   virtual void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors);
    6962  virtual bool GetOneNormalVector(const Vector &x1);
    7063  virtual bool MakeNormalTo(const Vector &y1);
    71   //bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c);
    7264  virtual bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
    7365  virtual void WrapPeriodically(const double * const M, const double * const Minv);
     
    7668  virtual double& operator[](size_t i);
    7769  virtual const double& operator[](size_t i) const;
    78   virtual double& at(size_t i);
    79   virtual const double& at(size_t i) const;
     70  double& at(size_t i);
     71  const double& at(size_t i) const;
    8072
    8173  // Assignment operator
     
    8476  // Access to internal structure
    8577  virtual double* get();
     78
     79  // Methods that are derived directly from other methods
     80  double Distance(const Vector &y) const;
     81  double Norm() const;
     82  double NormSquared() const;
     83  void Normalize();
     84  void Zero();
     85  void One(const double one);
     86  void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors);
    8687
    8788  // operators for mathematical operations
     
    9293  Vector const operator-(const Vector& b) const;
    9394
     95protected:
     96  typedef std::auto_ptr<Vector> rep_ptr;
     97  Vector(Baseconstructor);
     98  Vector(Baseconstructor,const Vector*);
     99  static Vector VecFromRep(const Vector*);
     100
    94101private:
    95   double x[NDIM];
     102  // method used for protection, i.e. to avoid infinite recursion
     103  // when our internal rep becomes messed up
     104  virtual bool isBaseClass() const;
     105  virtual Vector* clone() const;
     106  // this is used to represent the vector internally
     107  rep_ptr rep;
    96108
    97109};
Note: See TracChangeset for help on using the changeset viewer.