Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Tuple.H

Go to the documentation of this file.
00001 /* _______              __
00002   / ___/ /  ___  __ _  / /  ___
00003  / /__/ _ \/ _ \/  ' \/ _ \/ _ \
00004  \___/_//_/\___/_/_/_/_.__/\___/ 
00005 */
00006 //
00007 // This software is copyright (C) by the Lawrence Berkeley
00008 // National Laboratory.  Permission is granted to reproduce
00009 // this software for non-commercial purposes provided that
00010 // this notice is left intact.
00011 // 
00012 // It is acknowledged that the U.S. Government has rights to
00013 // this software under Contract DE-AC03-765F00098 between
00014 // the U.S.  Department of Energy and the University of
00015 // California.
00016 //
00017 // This software is provided as a professional and academic
00018 // contribution for joint exchange. Thus it is experimental,
00019 // is provided ``as is'', with no warranties of any kind
00020 // whatsoever, no support, no promise of updates, or printed
00021 // documentation. By using this software, you acknowledge
00022 // that the Lawrence Berkeley National Laboratory and
00023 // Regents of the University of California shall have no
00024 // liability with respect to the infringement of other
00025 // copyrights by any part of this software.
00026 //
00027 
00028 #ifndef CH_TUPLE_H
00029 #define CH_TUPLE_H
00030 
00031 //
00032 // $Id: Tuple.H,v 1.2 2001/06/20 02:56:59 ligocki Exp $
00033 //
00034 
00035 #include <cstdlib>
00036 using namespace std;
00037 
00038 #include <cassert>
00039 
00040 //
00041 //@Man:
00042 //@Memo: Ordered Tuples for Types T
00043 /*@Doc:
00044 
00045   This class represents ordered tuples of some user-specified concrete
00046   type T for N > 0. The type T must have a default constructor.  If the
00047   non-default constructor, copy constructor, or copy assignment operator
00048   are used, T must also have a copy constructor.
00049 */
00050 
00051 template <class T, size_t N>
00052 class Tuple
00053 {
00054 public:
00055  
00056     /*@ManDoc: The default constructor.  For user-defined types T, the
00057                default constructor for T will be run on each of the N
00058                objects in the Tuple.  For builtin (intrinsic) types,
00059                the values in the Tuple will be garbage.
00060     */
00061     Tuple ();
00062 
00063     /*@ManDoc: Constructs a Tuple, initializing the elements in the Tuple
00064                with the corresponding elements in the vector v.  This assumes
00065                that v contains at least N elements of type T -- an assumption
00066                that is NOT checked.  For user-defined types, T must have a
00067                well-defined and accessible copy constructor.
00068     */
00069   //explicit Tuple (const T* v);
00070     //
00071     // The copy constructor.
00072     //
00073     Tuple (const Tuple& rhs);
00074     //
00075     // The copy assignment operator.
00076     //
00077     Tuple& operator= (const Tuple& rhs);
00078  
00079     /*@ManDoc: Returns a modifiable lvalue reference to the i'th
00080                element in the Tuple, counting from zero.  Performs
00081                range checking when the library is compiled in debug
00082                mode.  */
00083     T& operator[] (int i);
00084  
00085     /*@ManDoc: Returns a constant reference to the i'th element in the Tuple,
00086                counting from zero.  Performs range checking when the library
00087                is compiled in debug mode.
00088     */
00089     const T& operator[] (int i) const;
00090  
00091     /*@ManDoc: Returns the address of the underlying vector of T
00092                representation.  This should ONLY be used when interfacing
00093                to Fortran as it breaks the encapsulation of the class.
00094     */
00095     operator const T* () const;
00096 
00097 protected:
00098     //
00099     // The underlying vector of T representing the Tuple.
00100     //
00101     T vect[N];
00102 };
00103 
00104 //
00105 // Inlines.
00106 //
00107 
00108 template <class T, size_t N>
00109 inline
00110 Tuple<T,N>::Tuple()
00111 {}
00112 
00113 template <class T, size_t N>
00114 inline
00115 T&
00116 Tuple<T,N>::operator[] (int i)
00117 {
00118     assert(0 <= i && i < (int)N);
00119     return vect[i];
00120 }
00121 
00122 template <class T, size_t N>
00123 inline
00124 const T&
00125 Tuple<T,N>::operator[] (int i) const
00126 {
00127     assert(0 <= i && i < (int)N);
00128     return vect[i];
00129 }
00130 
00131 template <class T, size_t N>
00132 inline
00133 Tuple<T,N>::operator const T* () const
00134 {
00135     return &vect[0];
00136 }
00137 
00138 
00139 //template <class T, size_t N>
00140 //Tuple<T,N>::Tuple (const T* v)
00141 //{
00142 //    assert(v != 0);
00143 //    for (size_t i = 0; i < N; ++i)
00144 //        vect[i] = v[i];
00145 //}
00146 
00147 template <class T, size_t N>
00148 Tuple<T,N>::Tuple (const Tuple<T,N>& rhs)
00149 {
00150     for (size_t i = 0; i < N; ++i)
00151         vect[i] = rhs.vect[i];
00152 }
00153 
00154 template <class T, size_t N>
00155 Tuple<T,N>&
00156 Tuple<T,N>::operator= (const Tuple<T,N>& rhs)
00157 {
00158     for (size_t i = 0; i < N; ++i)
00159         vect[i] = rhs.vect[i];
00160     return *this;
00161 }
00162 
00163 #endif /*CH_TUPLE_H*/

Generated on Tue Jul 2 10:42:20 2002 for Chombo by doxygen1.2.16