PEXSI
 All Classes Namespaces Files Functions Variables Typedefs Pages
tinyvec_impl.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2012 The Regents of the University of California,
3  through Lawrence Berkeley National Laboratory.
4 
5  Authors: Lexing Ying, Mathias Jacquelin and Lin Lin
6 
7  This file is part of PEXSI. All rights reserved.
8 
9  Redistribution and use in source and binary forms, with or without
10  modification, are permitted provided that the following conditions are met:
11 
12  (1) Redistributions of source code must retain the above copyright notice, this
13  list of conditions and the following disclaimer.
14  (2) Redistributions in binary form must reproduce the above copyright notice,
15  this list of conditions and the following disclaimer in the documentation
16  and/or other materials provided with the distribution.
17  (3) Neither the name of the University of California, Lawrence Berkeley
18  National Laboratory, U.S. Dept. of Energy nor the names of its contributors may
19  be used to endorse or promote products derived from this software without
20  specific prior written permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
26  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33  You are under no obligation whatsoever to provide any bug fixes, patches, or
34  upgrades to the features, functionality or performance of the source code
35  ("Enhancements") to anyone; however, if you choose to make your Enhancements
36  available either publicly, or directly to Lawrence Berkeley National
37  Laboratory, without imposing a separate written license agreement for such
38  Enhancements, then you hereby grant the following license: a non-exclusive,
39  royalty-free perpetual license to install, use, modify, prepare derivative
40  works, incorporate into other computer software, distribute, and sublicense
41  such enhancements or derivative works thereof, in binary and source code form.
42 */
46 #ifndef _PEXSI_TINYVEC_IMPL_HPP_
47 #define _PEXSI_TINYVEC_IMPL_HPP_
48 
49 
50 namespace PEXSI{
51 
52  // Template for tiny vectors of dimension 3.
53 
54  template <class F>
55  inline F&
56  Vec3T<F>::operator() ( Int i )
57  {
58 #ifndef _RELEASE_
59  PushCallStack("Vec3T::operator()");
60 #endif // ifndef _RELEASE_
61  if( i < 0 || i > 2 ){
62  #ifdef USE_ABORT
63 abort();
64 #endif
65 throw std::logic_error( "Index is out of bound." );
66  }
67 #ifndef _RELEASE_
68  PopCallStack();
69 #endif // ifndef _RELEASE_
70  return v_[i];
71  } // ----- end of method Vec3T::operator() -----
72 
73  template <class F>
74  inline const F&
75  Vec3T<F>::operator() ( Int i ) const
76  {
77 #ifndef _RELEASE_
78  PushCallStack("Vec3T::operator()");
79 #endif // ifndef _RELEASE_
80  if( i < 0 || i > 2 ){
81  #ifdef USE_ABORT
82 abort();
83 #endif
84 throw std::logic_error( "Index is out of bound." );
85  }
86 #ifndef _RELEASE_
87  PopCallStack();
88 #endif // ifndef _RELEASE_
89  return v_[i];
90  } // ----- end of method Vec3T::operator() -----
91 
92  template <class F>
93  inline F&
94  Vec3T<F>::operator[] ( Int i )
95  {
96 #ifndef _RELEASE_
97  PushCallStack("Vec3T::operator[]");
98 #endif // ifndef _RELEASE_
99  if( i < 0 || i > 2 ){
100  #ifdef USE_ABORT
101 abort();
102 #endif
103 throw std::logic_error( "Index is out of bound." );
104  }
105 #ifndef _RELEASE_
106  PopCallStack();
107 #endif // ifndef _RELEASE_
108  return v_[i];
109  } // ----- end of method Vec3T::operator[] -----
110 
111  template <class F>
112  inline const F&
113  Vec3T<F>::operator[] ( Int i ) const
114  {
115 #ifndef _RELEASE_
116  PushCallStack("Vec3T::operator[]");
117 #endif // ifndef _RELEASE_
118  if( i < 0 || i > 2 ){
119  #ifdef USE_ABORT
120 abort();
121 #endif
122 throw std::logic_error( "Index is out of bound." );
123  }
124 #ifndef _RELEASE_
125  PopCallStack();
126 #endif // ifndef _RELEASE_
127  return v_[i];
128  } // ----- end of method Vec3T::operator[] -----
129 
130 
131 } // namespace PEXSI
132 
133 #endif // _PEXSI_TINYVEC_IMPL_HPP_