[221] | 1 | /***************************************************************************
|
---|
| 2 | * blitz/listinit.h Classes for initialization lists
|
---|
| 3 | *
|
---|
| 4 | * $Id: listinit.h,v 1.1.1.1 1999-04-09 17:59:02 ansari Exp $
|
---|
| 5 | *
|
---|
| 6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
|
---|
| 7 | *
|
---|
| 8 | * This program is free software; you can redistribute it and/or
|
---|
| 9 | * modify it under the terms of the GNU General Public License
|
---|
| 10 | * as published by the Free Software Foundation; either version 2
|
---|
| 11 | * of the License, or (at your option) any later version.
|
---|
| 12 | *
|
---|
| 13 | * This program is distributed in the hope that it will be useful,
|
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 16 | * GNU General Public License for more details.
|
---|
| 17 | *
|
---|
| 18 | * Suggestions: blitz-suggest@cybervision.com
|
---|
| 19 | * Bugs: blitz-bugs@cybervision.com
|
---|
| 20 | *
|
---|
| 21 | * For more information, please see the Blitz++ Home Page:
|
---|
| 22 | * http://seurat.uwaterloo.ca/blitz/
|
---|
| 23 | *
|
---|
| 24 | ***************************************************************************
|
---|
| 25 | * $Log: not supported by cvs2svn $
|
---|
| 26 | * Revision 1.2 1998/03/14 00:04:47 tveldhui
|
---|
| 27 | * 0.2-alpha-05
|
---|
| 28 | *
|
---|
| 29 | * Revision 1.1 1997/07/16 14:51:20 tveldhui
|
---|
| 30 | * Update: Alpha release 0.2 (Arrays)
|
---|
| 31 | *
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 | * Initialization lists provide a convenient way to set the elements
|
---|
| 36 | * of an array. For example,
|
---|
| 37 | *
|
---|
| 38 | * Array<int,2> A(3,3);
|
---|
| 39 | * A = 1, 0, 0,
|
---|
| 40 | * 0, 1, 0,
|
---|
| 41 | * 0, 0, 1;
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | #ifndef BZ_LISTINIT_H
|
---|
| 45 | #define BZ_LISTINIT_H
|
---|
| 46 |
|
---|
| 47 | BZ_NAMESPACE(blitz)
|
---|
| 48 |
|
---|
| 49 | template<class T_numtype, class T_iterator>
|
---|
| 50 | class ListInitializer {
|
---|
| 51 |
|
---|
| 52 | public:
|
---|
| 53 | ListInitializer(T_iterator iter)
|
---|
| 54 | : iter_(iter)
|
---|
| 55 | {
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | ListInitializer<T_numtype, T_iterator> operator,(T_numtype x)
|
---|
| 59 | {
|
---|
| 60 | *iter_ = x;
|
---|
| 61 | return ListInitializer(iter_ + 1);
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | private:
|
---|
| 65 | ListInitializer();
|
---|
| 66 |
|
---|
| 67 | protected:
|
---|
| 68 | T_iterator iter_;
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | template<class T_array, class T_iterator = _bz_typename T_array::T_numtype*>
|
---|
| 72 | class ListInitializationSwitch {
|
---|
| 73 |
|
---|
| 74 | public:
|
---|
| 75 | typedef _bz_typename T_array::T_numtype T_numtype;
|
---|
| 76 |
|
---|
| 77 | ListInitializationSwitch(const ListInitializationSwitch<T_array>& lis)
|
---|
| 78 | : array_(lis.array_), value_(lis.value_),
|
---|
| 79 | wipeOnDestruct_(_bz_true)
|
---|
| 80 | {
|
---|
| 81 | lis.disable();
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | ListInitializationSwitch(T_array& array, T_numtype value)
|
---|
| 85 | : array_(array), value_(value), wipeOnDestruct_(_bz_true)
|
---|
| 86 | { }
|
---|
| 87 |
|
---|
| 88 | ~ListInitializationSwitch()
|
---|
| 89 | {
|
---|
| 90 | if (wipeOnDestruct_)
|
---|
| 91 | array_.initialize(value_);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | ListInitializer<T_numtype, T_iterator> operator,(T_numtype x)
|
---|
| 95 | {
|
---|
| 96 | wipeOnDestruct_ = _bz_false;
|
---|
| 97 | T_iterator iter = array_.getInitializationIterator();
|
---|
| 98 | *iter = value_;
|
---|
| 99 | T_iterator iter2 = iter + 1;
|
---|
| 100 | *iter2 = x;
|
---|
| 101 | return ListInitializer<T_numtype, T_iterator>(iter2 + 1);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | void disable() const
|
---|
| 105 | {
|
---|
| 106 | wipeOnDestruct_ = _bz_false;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | private:
|
---|
| 110 | ListInitializationSwitch();
|
---|
| 111 |
|
---|
| 112 | protected:
|
---|
| 113 | T_array& array_;
|
---|
| 114 | T_numtype value_;
|
---|
| 115 | mutable _bz_bool wipeOnDestruct_;
|
---|
| 116 | };
|
---|
| 117 |
|
---|
| 118 | BZ_NAMESPACE_END
|
---|
| 119 |
|
---|
| 120 | #endif // BZ_LISTINIT_H
|
---|
| 121 |
|
---|