SimpleMatrix

Macros

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#ifndef RecoBTag_Analysis_SimpleMatrix_h
#define RecoBTag_Analysis_SimpleMatrix_h

#include <memory>
#include <vector>

namespace btag {

  template <typename T>
  class SimpleMatrix {
  public:
    typedef T value_type;
    typedef typename std::vector<T>::size_type size_type;

    SimpleMatrix(size_type rows, size_type cols) : width(cols), height(rows), container(rows * cols) {}

    ~SimpleMatrix() {}

    inline size_type rows() const { return height; }
    inline size_type cols() const { return width; }
    inline size_type size() const { return container.size(); }

    inline double &operator()(size_type row, size_type col) { return container[index(row, col)]; }
    inline double operator()(size_type row, size_type col) const { return container[index(row, col)]; }

    inline double &operator[](size_type index) { return container[index]; }
    inline double operator[](size_type index) const { return container[index]; }

    inline size_type row(size_type index) const { return index / width; }
    inline size_type col(size_type index) const { return index % width; }

  protected:
    size_type index(size_type row, size_type col) const { return row * width + col; }

  private:
    size_type width, height;
    std::vector<T> container;
  };

}  // namespace btag

#endif  // GeneratorEvent_Analysis_SimpleMatrix_h