From 101aa769eb365d229f707e501431adaf945e3c7c Mon Sep 17 00:00:00 2001 From: Antonin Portelli Date: Wed, 4 May 2016 12:15:31 -0700 Subject: [PATCH] LatticeBase contain the grid pointer and a virtual destructor to allow polymorphic lattice pointers --- lib/lattice/Lattice_base.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/lattice/Lattice_base.h b/lib/lattice/Lattice_base.h index 8812a975..d97b1204 100644 --- a/lib/lattice/Lattice_base.h +++ b/lib/lattice/Lattice_base.h @@ -55,7 +55,13 @@ extern int GridCshiftPermuteMap[4][16]; // Basic expressions used in Expression Template //////////////////////////////////////////////// -class LatticeBase {}; +class LatticeBase +{ +public: + virtual ~LatticeBase(void) = default; + GridBase *_grid; +}; + class LatticeExpressionBase {}; template using Vector = std::vector >; // Aligned allocator?? @@ -88,8 +94,6 @@ template class Lattice : public LatticeBase { public: - - GridBase *_grid; int checkerboard; Vector _odata; @@ -177,8 +181,8 @@ PARALLEL_FOR_LOOP } //GridFromExpression is tricky to do template - Lattice(const LatticeUnaryExpression & expr): _grid(nullptr){ - + Lattice(const LatticeUnaryExpression & expr) { + _grid = nullptr; GridFromExpression(_grid,expr); assert(_grid!=nullptr); @@ -199,7 +203,8 @@ PARALLEL_FOR_LOOP } }; template - Lattice(const LatticeBinaryExpression & expr): _grid(nullptr){ + Lattice(const LatticeBinaryExpression & expr) { + _grid = nullptr; GridFromExpression(_grid,expr); assert(_grid!=nullptr); @@ -220,7 +225,8 @@ PARALLEL_FOR_LOOP } }; template - Lattice(const LatticeTrinaryExpression & expr): _grid(nullptr){ + Lattice(const LatticeTrinaryExpression & expr) { + _grid = nullptr; GridFromExpression(_grid,expr); assert(_grid!=nullptr); @@ -240,7 +246,8 @@ PARALLEL_FOR_LOOP // Constructor requires "grid" passed. // what about a default grid? ////////////////////////////////////////////////////////////////// - Lattice(GridBase *grid) : _grid(grid), _odata(_grid->oSites()) { + Lattice(GridBase *grid) : _odata(grid->oSites()) { + _grid = grid; // _odata.reserve(_grid->oSites()); // _odata.resize(_grid->oSites()); // std::cout << "Constructing lattice object with Grid pointer "<<_grid< strong_inline Lattice & operator = (const sobj & r){ PARALLEL_FOR_LOOP for(int ss=0;ss<_grid->oSites();ss++){