AbstractLinAlgPack: C++ Interfaces For Vectors, Matrices And Related Linear Algebra Objects  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AbstractLinAlgPack_VectorDenseEncap.hpp
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 // /////////////////////////////////////////////////////////////////////
45 // AbstractLinAlgPack_VectorDenseEncap.hpp
46 
47 #ifndef SLAP_VECTOR_DENSE_ENCAP_H
48 #define SLAP_VECTOR_DENSE_ENCAP_H
49 
50 #include "AbstractLinAlgPack_Types.hpp"
51 #include "AbstractLinAlgPack_VectorMutable.hpp"
52 #include "DenseLinAlgPack_DVectorClass.hpp"
53 
54 namespace AbstractLinAlgPack {
55 
79 public:
80 
82  VectorDenseEncap( const Vector& vec );
86  const DVectorSlice& operator()() const;
87 
88 private:
89 
90  const Vector &vec_;
91  RTOpPack::SubVector sub_vec_;
92  DVectorSlice vs_;
93  VectorDenseEncap(); // Not defined and not to be called!
94  VectorDenseEncap(const VectorDenseEncap&); // ""
95  VectorDenseEncap& operator=(const VectorDenseEncap&); // ""
96 
97 }; // end class VectorDenseEncap
98 
106 public:
107 
115  const DVectorSlice& operator()() const;
116 
117 private:
118 
119  VectorMutable &vec_;
120  RTOpPack::MutableSubVector sub_vec_;
121  DVectorSlice vs_;
122  VectorDenseMutableEncap(); // Not defined and not to be called!
124  VectorDenseMutableEncap& operator=(const VectorDenseMutableEncap&); // ""
125 
126 }; // end class VectorDenseMutableEncap
127 
128 // ///////////////////////////////////////////
129 // Inline members
130 
131 // VectorDenseEncap
132 
133 inline
134 VectorDenseEncap::VectorDenseEncap( const Vector& vec )
135  :vec_(vec)
136 {
137  vec_.get_sub_vector(Range1D(),&sub_vec_);
138  vs_.bind( DVectorSlice(
139  const_cast<value_type*>(sub_vec_.values())
140  ,sub_vec_.subDim()
141  ,sub_vec_.stride()
142  )
143  );
144 }
145 
146 inline
148 {
149  vec_.free_sub_vector(&sub_vec_);
150 }
151 
152 inline
154 {
155  return vs_;
156 }
157 
158 // VectorDenseMutableEncap
159 
160 inline
161 VectorDenseMutableEncap::VectorDenseMutableEncap( VectorMutable& vec )
162  :vec_(vec)
163 {
164  vec_.get_sub_vector(Range1D(),&sub_vec_);
165  vs_.bind( DVectorSlice(
166  sub_vec_.values()
167  ,sub_vec_.subDim()
168  ,sub_vec_.stride()
169  )
170  );
171 }
172 
173 inline
175 {
176  vec_.commit_sub_vector(&sub_vec_);
177 }
178 
179 inline
181 {
182  return vs_;
183 }
184 
185 inline
187 {
188  return vs_;
189 }
190 
191 } // end namespace SparseLinALgPack
192 
193 #endif // SLAP_VECTOR_DENSE_ENCAP_H
const DVectorSlice & operator()() const
Returns a reference to a constant view of the dense vector.
virtual void get_sub_vector(const Range1D &rng, RTOpPack::SubVector *sub_vec) const
Get a non-mutable explicit view of a sub-vector.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
DVectorSlice & operator()()
Returns a reference to a constant view of the dense vector.
virtual void commit_sub_vector(RTOpPack::MutableSubVector *sub_vec)
Free a mutable explicit view of a sub-vector.
~VectorDenseMutableEncap()
Calls vec.commit_sub_vector(&sub_vec) to release the view.
~VectorDenseEncap()
Calls vec.free_sub_vector(&sub_vec) to release the view.
Extract a constant DenseLinAlgPack::DVectorSlice view of a Vector object.
virtual void free_sub_vector(RTOpPack::SubVector *sub_vec) const
Free an explicit view of a sub-vector.
void bind(VectorSliceTmpl< value_type > vs)
virtual void get_sub_vector(const Range1D &rng, RTOpPack::MutableSubVector *sub_vec)
Get a mutable explicit view of a sub-vector.
Abstract interface for mutable coordinate vectors {abstract}.
Extract a non-const DenseLinAlgPack::DVectorSlice view of a VectorMutable object. ...