Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:17:12

0001 //
0002 // APFEL++ 2017
0003 //
0004 // Author: Valerio Bertone: valerio.bertone@cern.ch
0005 //
0006 
0007 #pragma once
0008 
0009 #include <vector>
0010 
0011 namespace apfel
0012 {
0013   /**
0014    * @brief Class that extends vectors to negative indices
0015    */
0016   template<class T>
0017   class ExtendedVector
0018   {
0019   public:
0020     /**
0021      * @brief The ExtendedVector constructor.
0022      * @param size: the size of the container (default: 0)
0023      * @param value: initialisation value (default: 0)
0024      * @param imin: the lowest allowed index (default: 0)
0025      */
0026     ExtendedVector(int const& size = 0, T const& value = 0, int const& imin = 0): _imin(imin), _vector(size, value) {}
0027 
0028     /**
0029      * @brief Returns the value at the possibly negative given index
0030      * @param index: the position index
0031      * @return the value at the possibly negative given index
0032      * @note Settable version
0033      */
0034     T& operator [] (int const& index) { return _vector[index - _imin]; }
0035 
0036     /**
0037      * @brief Returns the value at the possibly negative given index
0038      * @param index: the position index
0039      * @return the value at the possibly negative given index
0040      * @note Non-settable version
0041      */
0042     const T& operator [] (int const& index) const { return _vector[index - _imin]; }
0043 
0044     /**
0045      * @brief Returns the lower bound
0046      * @return the lower bound
0047      */
0048     int min() const { return _imin; };
0049 
0050     /**
0051      * @brief Returns the upper bound
0052      * @return the upper bound
0053      */
0054     int max() const { return _vector.size() + _imin; };
0055 
0056     /**
0057      * @brief Returns the size of the vector
0058      */
0059     size_t size() const { return _vector.size(); }
0060 
0061     /**
0062      * @brief Resizes the continer
0063      * @param size: the new size
0064      * @param value: the value used to fill in the additional (if any) slots
0065      * @param imin: the lowest allowed index (default: 0)
0066      */
0067     void resize(int const& size, T const& value = 0, int const& imin = 0) { _imin = imin; _vector.resize(size, value); }
0068 
0069     /**
0070      * @brief Non-constant begin iterator
0071      */
0072     typename std::vector<T>::iterator begin() { return _vector.begin(); }
0073 
0074     /**
0075      * @brief Constant begin iterator
0076      */
0077     typename std::vector<T>::const_iterator begin() const { return _vector.begin(); }
0078 
0079     /**
0080      * @brief Non-constant end iterator
0081      */
0082     typename std::vector<T>::iterator end() { return _vector.end(); }
0083 
0084     /**
0085      * @brief Constant end iterator
0086      */
0087     typename std::vector<T>::const_iterator end() const { return _vector.end(); }
0088 
0089   private:
0090     int            _imin;    //!< The lower bound
0091     std::vector<T> _vector;  //!< The container
0092   };
0093 }