| 15 | |
| 16 | template <class Handle> |
| 17 | class ScalesState |
| 18 | { |
| 19 | template <class OtherHandle> friend class ScalesState; |
| 20 | |
| 21 | public: |
| 22 | ScalesState (const AnyType& inArray): |
| 23 | mStorage(inArray.getAs<Handle>()) |
| 24 | { |
| 25 | rebind(); |
| 26 | } |
| 27 | |
| 28 | inline operator AnyType () const |
| 29 | { |
| 30 | return mStorage; |
| 31 | } |
| 32 | |
| 33 | inline void allocate (const Allocator& inAllocator, |
| 34 | uint32_t inDimension) |
| 35 | { |
| 36 | mStorage = inAllocator.allocateArray<double, |
| 37 | dbal::AggregateContext, |
| 38 | dbal::DoZero, |
| 39 | dbal::ThrowBadAlloc>( |
| 40 | arraySize(inDimension)); |
| 41 | dimension.rebind(&mStorage[0]); |
| 42 | dimension = inDimension; |
| 43 | rebind(); |
| 44 | } |
| 45 | |
| 46 | template <class OtherHandle> |
| 47 | ScalesState& operator= (const ScalesState<OtherHandle>& inOtherState) |
| 48 | { |
| 49 | for (size_t i = 0; i < mStorage.size(); i++) |
| 50 | mStorage[i] = inOtherState.mStorage[i]; |
| 51 | return *this; |
| 52 | } |
| 53 | |
| 54 | static inline uint32_t arraySize (const uint32_t inDimension) |
| 55 | { |
| 56 | return 2 + 2 * inDimension; |
| 57 | } |
| 58 | |
| 59 | protected: |
| 60 | void rebind () |
| 61 | { |
| 62 | dimension.rebind(&mStorage[0]); |
| 63 | numRows.rebind(&mStorage[1]); |
| 64 | mean.rebind(&mStorage[2], dimension); |
| 65 | std.rebind(&mStorage[2 + dimension], dimension); |
| 66 | } |
| 67 | |
| 68 | Handle mStorage; |
| 69 | |
| 70 | public: |
| 71 | typename HandleTraits<Handle>::ReferenceToUInt32 dimension; |
| 72 | typename HandleTraits<Handle>::ReferenceToUInt64 numRows; |
| 73 | typename HandleTraits<Handle>::ColumnVectorTransparentHandleMap mean; |
| 74 | typename HandleTraits<Handle>::ColumnVectorTransparentHandleMap std; |