Array.h

Go to the documentation of this file.
00001 
00007 #ifndef ARRAY_H
00008 #define ARRAY_H
00009 
00010 template <class Elem, int Size> class Array {
00011 
00012   public:
00013     Elem data[Size];
00014 
00015     // constructor
00016     Array(void) { ; }
00017 
00018     // destructor
00019     ~Array(void) { ; }
00020 
00021     // copy constructor
00022     Array(const Array<Elem,Size> &a2) {
00023       for ( int i = 0; i < Size; ++i ) { data[i] = a2.data[i]; }
00024     }
00025 
00026     // assignment operator
00027     Array<Elem,Size> & operator= (const Array<Elem,Size> &a2) {
00028       for ( int i = 0; i < Size; ++i ) { data[i] = a2.data[i]; }
00029       return (*this);
00030     }
00031 
00032     // set all elements to a given value (like 0)
00033     Array(const Elem &v) {
00034       for ( int i = 0; i < Size; ++i ) { data[i] = v; }
00035     }
00036     Array<Elem,Size> & operator= (const Elem &v) {
00037       for ( int i = 0; i < Size; ++i ) { data[i] = v; }
00038       return (*this);
00039     }
00040 
00041     // element access
00042     inline Elem & operator[](int index) { return data[index]; }
00043     inline const Elem & operator[](int index) const { return data[index]; }
00044 
00045     // STL-style interface
00046     typedef Elem* iterator;
00047     iterator begin(void) { return &data[0]; }
00048     iterator end(void) { return &data[0] + Size; }
00049     typedef const Elem* const_iterator;
00050     const_iterator const_begin(void) const { return &data[0]; }
00051     const_iterator const_end(void) const { return &data[0] + Size; }
00052 
00053 };
00054 
00055 #endif
00056 

Generated on Thu Sep 21 01:17:10 2017 for NAMD by  doxygen 1.4.7