Changeset 1651


Ignore:
Timestamp:
Dec 15, 2008, 1:57:43 PM (15 years ago)
Author:
Peter
Message:

fixes #467 - implicit conversion between Vector and its Views are no longer allowed

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r1619 r1651  
    55Version 0.5 (released DATE)
    66
     7  - Imlicit conversion between Vector and its Views disabled (ticket:467)
    78  - Averager::add (and siblings) take a (signed) long (ticket:361)
    89  - IteratorPolicy removed (ticket:398)
  • trunk/yat/utility/Vector.h

    r1506 r1651  
    7171       \throw GSL_error if memory allocation fails.
    7272    */
    73     Vector(size_t n, double init_value=0);
     73    explicit Vector(size_t n, double init_value=0);
    7474
    7575    /**
     
    8787       fails.
    8888    */
    89     Vector(const VectorBase& other);
     89    explicit Vector(const VectorBase& other);
    9090
    9191    /**
  • trunk/yat/utility/VectorConstView.h

    r1615 r1651  
    6464       \brief Copy a VectorBase
    6565    */
    66     VectorConstView(const VectorBase& other);
     66    explicit VectorConstView(const VectorBase& other);
    6767
    6868    /**
  • trunk/yat/utility/VectorMutable.cc

    r1487 r1651  
    180180
    181181
    182   VectorMutable::operator proxy()
    183   {
    184     assert(vec_==const_vec_);
    185     proxy p;
    186     p.vec_ = vec_;
    187     vec_ = NULL; // proxy takes ownership and delivers to its receiver
    188     const_vec_ = NULL;
    189     return p;
    190   }
    191 
    192182}}} // of namespace utility, yat, and thep
  • trunk/yat/utility/VectorMutable.h

    r1551 r1651  
    220220    gsl_vector* vec_;
    221221
    222     /**
    223        Proxy class used to allow copy and assignment of VectorView. By
    224        design vectors and matrices are passed as non-const references
    225        in all constructors of VectorView. Because the standard does
    226        not allow temporary objects to be bound to non-const
    227        references, it is not possible to directly construct a
    228        VectorView from a temporary VectorView returned from a
    229        function. Instead this proxy class is created from the
    230        temporary object and then a VectorView can be created from this
    231        proxy.
    232 
    233        \see VectorView
    234      */
    235     struct proxy
    236     {
    237       /// pointer to GSL vector keeping everything we need to create a
    238       /// new VectorMutable from a proxy.
    239       gsl_vector* vec_;
    240     };
    241 
    242222  private:
    243223    // copy assignment not allowed
    244224    const VectorMutable& operator=(const VectorMutable&);
    245   public:
    246     /**
    247        conversion operator to protected proxy class.
    248      */
    249     operator proxy();
    250225
    251226  };
  • trunk/yat/utility/VectorView.cc

    r1487 r1651  
    124124
    125125
    126 
    127126  const VectorView& VectorView::operator=(const VectorView& other )
    128127  {
     
    147146
    148147
     148  VectorView::operator proxy()
     149  {
     150    assert(vec_==const_vec_);
     151    proxy p;
     152    p.vec_ = vec_;
     153    vec_ = NULL; // proxy takes ownership and delivers to its receiver
     154    const_vec_ = NULL;
     155    return p;
     156  }
     157
     158
    149159}}} // of namespace utility, yat, and thep
  • trunk/yat/utility/VectorView.h

    r1487 r1651  
    110110       is undefined.
    111111    */
    112     VectorView(VectorMutable& other);
     112    explicit VectorView(VectorMutable& other);
    113113
    114114    /**
     
    143143    VectorView(Matrix& m, size_t i, bool row=true);
    144144
    145     /**
    146        \brief create VectorView from proxy class
    147      */
    148     VectorView(proxy p);
    149 
    150145    ///
    151146    /// The destructor.
     
    186181
    187182    gsl_vector_view* view_;
     183
     184    /**
     185       Proxy class used to allow copy and assignment of VectorView. By
     186       design vectors and matrices are passed as non-const references
     187       in all constructors of VectorView. Because the standard does
     188       not allow temporary objects to be bound to non-const
     189       references, it is not possible to directly construct a
     190       VectorView from a temporary VectorView returned from a
     191       function. Instead this proxy class is created from the
     192       temporary object and then a VectorView can be created from this
     193       proxy.
     194     */
     195    struct proxy
     196    {
     197      /// pointer to GSL vector keeping everything we need to create a
     198      /// new VectorMutable from a proxy.
     199      gsl_vector* vec_;
     200    };
     201
     202  public:
     203    /**
     204       \brief create VectorView from proxy class
     205     */
     206    VectorView(proxy p);
     207
     208    /**
     209       conversion operator to private proxy class.
     210     */
     211    operator proxy();
    188212  };
    189213
Note: See TracChangeset for help on using the changeset viewer.