00001 #ifndef GeneratorInterface_LHEInterface_SimpleMatrix_h 00002 #define GeneratorInterface_LHEInterface_SimpleMatrix_h 00003 00004 #include <memory> 00005 00006 namespace lhef { 00007 00008 template<typename T> 00009 class SimpleMatrix { 00010 public: 00011 typedef T value_type; 00012 typedef typename std::vector<T>::size_type size_type; 00013 00014 SimpleMatrix(size_type rows, size_type cols) : 00015 width(cols), height(rows), container(rows * cols) {} 00016 00017 ~SimpleMatrix() {} 00018 00019 inline size_type rows() const { return height; } 00020 inline size_type cols() const { return width; } 00021 inline size_type size() const { return container.size(); } 00022 00023 inline double &operator () (size_type row, size_type col) 00024 { return container[index(row, col)]; } 00025 inline double operator () (size_type row, size_type col) const 00026 { return container[index(row, col)]; } 00027 00028 inline double &operator [] (size_type index) 00029 { return container[index]; } 00030 inline double operator [] (size_type index) const 00031 { return container[index]; } 00032 00033 inline size_type row(size_type index) const { return index / width; } 00034 inline size_type col(size_type index) const { return index % width; } 00035 00036 protected: 00037 size_type index(size_type row, size_type col) const 00038 { return row * width + col; } 00039 00040 private: 00041 size_type width, height; 00042 std::vector<T> container; 00043 }; 00044 00045 } // namespace lhef 00046 00047 #endif // GeneratorEvent_LHEInterface_SimpleMatrix_h