|
|
|
1 |
|
// valarray standard header |
2 |
|
#pragma once |
3 |
|
#ifndef _VALARRAY_ |
4 |
|
#define _VALARRAY_ |
5 |
|
#ifndef RC_INVOKED |
6 |
|
#include <cmath> |
7 |
|
#include <xmemory> |
8 |
|
#include <xstddef> |
9 |
|
|
10 |
|
#ifdef _MSC_VER |
11 |
|
#pragma pack(push,_CRT_PACKING) |
12 |
|
#pragma warning(push,3) |
13 |
|
#if defined(min) |
14 |
|
#pragma push_macro("min") |
15 |
|
#undef min |
16 |
|
#define _POP_MIN |
17 |
|
#endif |
18 |
|
|
19 |
|
#if defined(max) |
20 |
|
#pragma push_macro("max") |
21 |
|
#undef max |
22 |
|
#define _POP_MAX |
23 |
|
#endif |
24 |
|
|
25 |
|
#pragma warning(disable: 4244 4700) |
26 |
|
#endif /* _MSC_VER */ |
27 |
|
|
28 |
|
_STD_BEGIN |
29 |
|
|
30 |
|
// FORWARD REFERENCES |
31 |
|
class gslice; |
32 |
|
class slice; |
33 |
|
|
34 |
|
template<class _Ty> |
35 |
|
class gslice_array; |
36 |
|
template<class _Ty> |
37 |
|
class indirect_array; |
38 |
|
template<class _Ty> |
39 |
|
class mask_array; |
40 |
|
template<class _Ty> |
41 |
|
class slice_array; |
42 |
|
template<class _Ty> |
43 |
|
class valarray; |
44 |
|
|
45 |
|
typedef valarray<_Bool> _Boolarray; |
46 |
|
typedef valarray<size_t> _Sizarray; |
47 |
|
|
48 |
|
// MACROS FOR valarray |
49 |
|
#define _VALOP(TYPE, LENGTH, RHS) /* assign RHS(_Idx) to new valarray */ \ |
50 |
|
valarray<TYPE> _Ans(LENGTH); \ |
51 |
|
for (size_t _Idx = 0; _Idx < _Ans.size(); ++_Idx) \ |
52 |
|
_Ans[_Idx] = RHS; \ |
53 |
|
return _Ans |
54 |
|
|
55 |
|
#define _VALGOP(RHS) /* apply RHS(_Idx) to valarray */ \ |
56 |
|
for (size_t _Idx = 0; _Idx < size(); ++_Idx) \ |
57 |
|
_Myptr[_Idx] RHS; \ |
58 |
|
return *this |
59 |
|
|
60 |
|
// TEMPLATE CLASS valarray |
61 |
|
template<class _Ty> |
62 |
|
class valarray |
63 |
|
{ // store array with various indexing options |
64 |
|
public: |
65 |
|
typedef _Ty value_type; |
66 |
|
|
67 |
|
valarray() |
68 |
|
{ // construct empty valarray |
69 |
|
_Tidy(); |
70 |
|
_Myres = 0; |
71 |
|
_Grow(0); |
72 |
|
} |
1527 |
|
// mask_array TEMPLATE FUNCTIONS |
1528 |
|
template<class _Ty> inline |
1529 |
|
valarray<_Ty>& valarray<_Ty>::operator=(const mask_array<_Ty>& _Maskarr) |
1530 |
|
{ // assign masked array to valarray |
1531 |
|
_Tidy(true); |
1532 |
|
_Grow(_Maskarr._Totlen()); |
1533 |
|
size_t _Count = 0; |
1534 |
|
|
1535 |
|
for (size_t _Idx = 0; _Idx < size(); ++_Count) |
1536 |
|
if (_Maskarr._Mask(_Count)) |
1537 |
|
_Myptr[_Idx++] = _Maskarr._Data(_Count); |
1538 |
|
return (*this); |
1539 |
|
} |
1540 |
|
|
1541 |
|
template<class _Ty> inline |
1542 |
|
valarray<_Ty> valarray<_Ty>::operator[](const _Boolarray& _Boolarr) const |
1543 |
|
{ // subscript nonmutable valarray by boolean (mask) array |
1544 |
|
return (valarray<_Ty>(mask_array<_Ty>(_Boolarr, _Myptr))); |
1545 |
|
} |
1546 |
|
|
1547 |
|
template<class _Ty> inline |
1548 |
|
mask_array<_Ty> valarray<_Ty>::operator[](const _Boolarray& _Boolarr) |
1549 |
|
{ // subscript nonmutable valarray by boolean (mask) array |
1550 |
|
return (mask_array<_Ty>(_Boolarr, _Myptr)); |
1551 |
|
} |
1552 |
|
|
1553 |
|
// indirect_array TEMPLATE FUNCTIONS |
1554 |
|
template<class _Ty> inline |
1555 |
|
valarray<_Ty>& valarray<_Ty>::operator=( |
1556 |
|
const indirect_array<_Ty>& _Indarr) |
1557 |
|
{ // assign indirect array to valarray |
1558 |
|
_Tidy(true); |
1559 |
|
_Grow(_Indarr._Totlen()); |
1560 |
|
_VALGOP(= _Indarr._Data(_Indarr._Indir(_Idx))); |
1561 |
|
} |
1562 |
|
|
1563 |
|
template<class _Ty> inline |
1564 |
|
valarray<_Ty> valarray<_Ty>::operator[](const _Sizarray& _Indarr) const |
1565 |
|
{ // subscript nonmutable valarray by indirect (mapping) array |
1566 |
|
return (valarray<_Ty>(indirect_array<_Ty>(_Indarr, _Myptr))); |
1567 |
|
} |
1568 |
|
|
1569 |
|
template<class _Ty> inline |
1570 |
|
indirect_array<_Ty> valarray<_Ty>::operator[](const _Sizarray& _Indarr) |
1571 |
|
{ // subscript mutable valarray by indirect (mapping) array |
1572 |
|
return (indirect_array<_Ty>(_Indarr, _Myptr)); |
1573 |
|
} |
1574 |
|
_STD_END |
1575 |
|
|
1576 |
|
#ifdef _MSC_VER |
1577 |
|
#pragma warning(default: 4244) |
1578 |
|
#pragma warning(default: 4700) |
1579 |
|
#ifdef _POP_MIN |
1580 |
|
#pragma pop_macro("min") |
1581 |
|
#endif |
1582 |
|
#ifdef _POP_MAX |
1583 |
|
#pragma pop_macro("max") |
1584 |
|
#endif |
1585 |
|
#pragma warning(pop) |
1586 |
|
#pragma pack(pop) |
1587 |
|
#endif /* _MSC_VER */ |
1588 |
|
|
1589 |
|
#endif /* RC_INVOKED */ |
1590 |
|
#endif /* _VALARRAY_ */ |
1591 |
|
|
1592 |
|
/* |
1593 |
|
* Copyright (c) 1992-2007 by P.J. Plauger. ALL RIGHTS RESERVED. |
1594 |
|
* Consult your license regarding permissions and restrictions. |
1595 |
|
V5.03:0009 */ |
1596 |
|
|
|
|
|