![]() |
Blitz Devel : |
From: Theodore Papadopoulo (Theodore.Papadopoulo_at_[hidden])
Date: 2004-07-28 08:16:41
Hi,
Here is the second of the patch set. This one allows for the use of
swap on blitz arrays. Because of the way operator= is defined in
blitz (no deep copy), the standard implementation of std::swap does
not work, so an overload is needed. This is what this patch provides.
Like the previous one, this post is to give people a chance to
comment and amend. And I'll wait for an OK from Julian to commit it.
Thank's,
Theo.
2004-07-28 Theodore Papadopoulo <Theodore.Papadopoulo_at_[hidden]>
* blitz/memblock.h: Added support for swapping memblocks.
* blitz/array-impl.h: Added support for swapping arrays using the
memblock swapping.
Index: blitz/array-impl.h
===================================================================
RCS file: /cvsroot/blitz/blitz/blitz/array-impl.h,v
retrieving revision 1.16
diff -c -3 -p -r1.16 array-impl.h
*** blitz/array-impl.h 19 Jun 2004 03:14:11 -0000 1.16
--- blitz/array-impl.h 28 Jul 2004 13:06:34 -0000
*************** class _bz_ArrayExpr;
*** 95,101 ****
template<typename T_array, typename T_index>
class IndirectArray;
!
/*
* Declaration of class Array
--- 95,102 ----
template<typename T_array, typename T_index>
class IndirectArray;
! template <typename P_numtype,int N_rank>
! void swap(Array<P_numtype,N_rank>&,Array<P_numtype,N_rank>&);
/*
* Declaration of class Array
*************** protected:
*** 2385,2390 ****
--- 2386,2393 ----
void doTranspose(int destRank, int sourceRank, T_array& array);
+ friend void swap<>(Array<P_numtype,N_rank>&,Array<P_numtype,N_rank>&);
+
protected:
//////////////////////////////////////////////
// Data members
*************** ostream& operator<<(ostream&, const Arra
*** 2465,2470 ****
--- 2468,2482 ----
template<typename T_numtype, int N_rank>
istream& operator>>(istream& is, Array<T_numtype,N_rank>& x);
+ template <typename P_numtype,int N_rank>
+ void swap(Array<P_numtype,N_rank>& a,Array<P_numtype,N_rank>& b) {
+ MemoryBlockReference<P_numtype>::swap(a,b);
+ std::swap(a.storage_,b.storage_);
+ std::swap(a.length_,b.length_);
+ std::swap(a.stride_,b.stride_);
+ std::swap(a.zeroOffset_,b.zeroOffset_);
+ }
+
BZ_NAMESPACE_END
/*
*************** BZ_NAMESPACE_END
*** 2492,2495 ****
#include <blitz/array/stencils.h> // Stencil objects
#endif // BZ_ARRAY_H
-
--- 2504,2506 ----
Index: blitz/memblock.h
===================================================================
RCS file: /cvsroot/blitz/blitz/blitz/memblock.h,v
retrieving revision 1.13
diff -c -3 -p -r1.13 memblock.h
*** blitz/memblock.h 20 Jan 2004 20:28:29 -0000 1.13
--- blitz/memblock.h 28 Jul 2004 13:06:34 -0000
*************** public:
*** 314,319 ****
--- 314,325 ----
return block_->references();
}
+ static void swap(MemoryBlockReference<P_type>& a,MemoryBlockReference<P_type>& b) {
+ std::swap(a.data_,b.data_);
+ std::swap(a.block_,b.block_);
+ }
+
+
protected:
void changeToNullBlock()
--------------------------------------------------------------------
Theodore Papadopoulo
Email: Theodore.Papadopoulo_at_[hidden] Tel: (33) 04 92 38 76 01
--------------------------------------------------------------------