blitz
Version 1.0.2
Toggle main menu visibility
Loading...
Searching...
No Matches
listinit.h
Go to the documentation of this file.
1
// -*- C++ -*-
2
/***************************************************************************
3
* blitz/listinit.h Classes for initialization lists
4
*
5
* $Id$
6
*
7
* Copyright (C) 1997-2011 Todd Veldhuizen <tveldhui@acm.org>
8
*
9
* This file is a part of Blitz.
10
*
11
* Blitz is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU Lesser General Public License
13
* as published by the Free Software Foundation, either version 3
14
* of the License, or (at your option) any later version.
15
*
16
* Blitz is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU Lesser General Public License for more details.
20
*
21
* You should have received a copy of the GNU Lesser General Public
22
* License along with Blitz. If not, see <http://www.gnu.org/licenses/>.
23
*
24
* Suggestions: blitz-devel@lists.sourceforge.net
25
* Bugs: blitz-support@lists.sourceforge.net
26
*
27
* For more information, please see the Blitz++ Home Page:
28
* https://sourceforge.net/projects/blitz/
29
*
30
***************************************************************************/
31
32
/*
33
* Initialization lists provide a convenient way to set the elements
34
* of an array. For example,
35
*
36
* Array<int,2> A(3,3);
37
* A = 1, 0, 0,
38
* 0, 1, 0,
39
* 0, 0, 1;
40
*/
41
42
#ifndef BZ_LISTINIT_H
43
#define BZ_LISTINIT_H
44
45
namespace
blitz
{
46
47
template
<
typename
T_numtype,
typename
T_iterator>
48
class
ListInitializer
{
49
50
public
:
51
ListInitializer
(T_iterator iter)
52
:
iter_
(iter)
53
{
54
}
55
56
ListInitializer<T_numtype, T_iterator>
operator,
(T_numtype x)
57
{
58
*
iter_
= x;
59
++
iter_
;
60
return
ListInitializer<T_numtype, T_iterator>
(
iter_
);
61
}
62
63
private
:
64
ListInitializer
();
65
66
protected
:
67
T_iterator
iter_
;
68
};
69
70
template
<
typename
T_array,
typename
T_iterator = _bz_
typename
T_array::T_numtype*>
71
class
ListInitializationSwitch
{
72
73
public
:
74
typedef
_bz_typename
T_array::T_numtype
T_numtype
;
75
76
ListInitializationSwitch
(
const
ListInitializationSwitch<T_array>
& lis)
77
:
array_
(lis.
array_
),
value_
(lis.
value_
),
78
wipeOnDestruct_
(
true
)
79
{
80
lis.
disable
();
81
}
82
83
ListInitializationSwitch
(T_array& array,
T_numtype
value)
84
:
array_
(array),
value_
(value),
wipeOnDestruct_
(
true
)
85
{ }
86
87
~ListInitializationSwitch
()
88
{
89
if
(
wipeOnDestruct_
)
90
array_
.initialize(
value_
);
91
}
92
93
ListInitializer<T_numtype, T_iterator>
operator,
(
T_numtype
x)
94
{
95
wipeOnDestruct_
=
false
;
96
T_iterator iter =
array_
.getInitializationIterator();
97
*iter =
value_
;
98
++iter;
99
//T_iterator iter2 = iter + 1;
100
*iter = x;
101
++iter;
102
return
ListInitializer<T_numtype, T_iterator>
(iter);
103
}
104
105
void
disable
()
const
106
{
107
wipeOnDestruct_
=
false
;
108
}
109
110
private
:
111
ListInitializationSwitch
();
112
113
protected
:
114
T_array&
array_
;
115
T_numtype
value_
;
116
mutable
bool
wipeOnDestruct_
;
117
};
118
119
}
120
121
#endif
// BZ_LISTINIT_H
122
blitz::ListInitializationSwitch::value_
T_numtype value_
Definition
listinit.h:115
blitz::ListInitializationSwitch::~ListInitializationSwitch
~ListInitializationSwitch()
Definition
listinit.h:87
blitz::ListInitializationSwitch::disable
void disable() const
Definition
listinit.h:105
blitz::ListInitializationSwitch::ListInitializationSwitch
ListInitializationSwitch(const ListInitializationSwitch< T_array > &lis)
Definition
listinit.h:76
blitz::ListInitializationSwitch::array_
T_array & array_
Definition
listinit.h:114
blitz::ListInitializationSwitch::ListInitializationSwitch
ListInitializationSwitch()
blitz::ListInitializationSwitch::T_numtype
_bz_typename T_array::T_numtype T_numtype
Definition
listinit.h:74
blitz::ListInitializationSwitch::wipeOnDestruct_
bool wipeOnDestruct_
Definition
listinit.h:116
blitz::ListInitializationSwitch::operator,
ListInitializer< T_numtype, T_iterator > operator,(T_numtype x)
Definition
listinit.h:93
blitz::ListInitializationSwitch::ListInitializationSwitch
ListInitializationSwitch(T_array &array, T_numtype value)
Definition
listinit.h:83
blitz::ListInitializer
Definition
listinit.h:48
blitz::ListInitializer::iter_
T_iterator iter_
Definition
listinit.h:67
blitz::ListInitializer::ListInitializer
ListInitializer(T_iterator iter)
Definition
listinit.h:51
blitz::ListInitializer::operator,
ListInitializer< T_numtype, T_iterator > operator,(T_numtype x)
Definition
listinit.h:56
blitz::ListInitializer::ListInitializer
ListInitializer()
_bz_typename
#define _bz_typename
Definition
compiler.h:80
true
#define true
Definition
compiler.h:101
blitz
Definition
array-impl.h:66
blitz
listinit.h
Generated by
1.17.0