- Timestamp:
- Sep 27, 2008, 12:37:33 AM (15 years ago)
- Location:
- trunk/yat/utility
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/DataWeightProxy.h
r1535 r1537 33 33 34 34 \brief Proxy class for DataWeight 35 36 DataIterator and WeightIterator should be a TrivialIterator 35 37 */ 38 template<typename DataIterator, typename WeightIterator> 36 39 class DataWeightProxy 37 40 { … … 40 43 \brief Default constructor 41 44 42 \param data data valueto hold43 \param weight weight valueto hold45 \param data iterator pointing to data to hold 46 \param weight iterator pointing to weight to hold 44 47 */ 45 DataWeightProxy(double& data, double& weight); 48 DataWeightProxy(DataIterator data, WeightIterator weight) 49 : data_(data), weight_(weight) {} 46 50 47 51 /** 48 52 \return reference to data 49 53 */ 50 double& data(void) ;54 double& data(void) { return *data_; } 51 55 52 56 /** 53 57 \return const reference to data 54 58 */ 55 const double& data(void) const ;59 const double& data(void) const { return *data_ ; } 56 60 57 61 /** 58 62 \return reference to weight 59 63 */ 60 double& weight(void) ;64 double& weight(void) { return *weight_; } 61 65 62 66 /** 63 67 \return const reference to weight 64 68 */ 65 const double& weight(void) const ;69 const double& weight(void) const { return *weight_; } 66 70 67 71 /** 68 72 \brief assignment operator 69 73 */ 70 DataWeightProxy& operator=(const DataWeight& rhs); 74 DataWeightProxy& operator=(const DataWeight& rhs) 75 { 76 data() = rhs.data(); 77 weight() = rhs.weight(); 78 return *this; 79 } 71 80 72 81 /** 73 82 \brief Conversion to DataWeight 74 83 */ 75 operator DataWeight() const ;84 operator DataWeight() const { return DataWeight(data(), weight()); } 76 85 77 86 private: 78 double&data_;79 double&weight_;87 DataIterator data_; 88 WeightIterator weight_; 80 89 81 // no copying82 DataWeightProxy(const DataWeightProxy&);83 DataWeightProxy& operator=(const DataWeightProxy&);90 // using compiler generated copy and assignment 91 //DataWeightProxy& operator=(const DataWeightProxy&); 92 //DataWeightProxy(const DataWeightProxy&); 84 93 }; 94 95 96 /** 97 \brief equality operator 98 */ 99 template<typename DataIterator, typename WeightIterator> 100 bool operator==(const DataWeightProxy<DataIterator, WeightIterator>& lhs, 101 const DataWeightProxy<DataIterator, WeightIterator>& rhs) 102 { 103 return lhs.data()==rhs.data() && lhs.weight()==rhs.weight(); 104 } 85 105 86 106 }}} // of namespace utility, yat, and theplu -
trunk/yat/utility/Makefile.am
r1533 r1537 23 23 noinst_LTLIBRARIES = libutility.la 24 24 libutility_la_SOURCES = \ 25 Alignment.cc ColumnStream.cc CommandLine.cc DataWeight.cc DataWeightProxy.cc\25 Alignment.cc ColumnStream.cc CommandLine.cc DataWeight.cc \ 26 26 FileUtil.cc Index.cc kNNI.cc \ 27 27 Matrix.cc MatrixWeighted.cc NNI.cc Option.cc \ -
trunk/yat/utility/WeightedIterator.h
r1532 r1537 23 23 */ 24 24 25 #include <DataWeight.h> 26 #include <DataWeightProxy.h> 27 25 28 #include <boost/iterator/iterator_facade.hpp> 26 29 … … 32 35 33 36 /** 34 @brief WeightedIterator37 \brief WeightedIterator 35 38 */ 36 39 template<typename DataIterator, typename WeightIterator> … … 39 42 WeightedIterator<DataIterator, WeightIterator>, 40 43 DataWeight, 41 std::random_access_iterator_tag,42 DataWeight >44 typename std::iterator_traits<DataIterator>::iterator_category, 45 DataWeightProxy<DataIterator, WeightIterator> > 43 46 44 47 { … … 50 53 : d_iter_(d), w_iter_(w) 51 54 {} 55 56 57 /** 58 \brief element operator 59 */ 60 DataWeightProxy<DataIterator, WeightIterator> operator[](int n) const 61 { 62 return DataWeightProxy<DataIterator, WeightIterator>(d_iter_+n, 63 w_iter_+n); 64 } 65 52 66 53 67 /** 54 68 \brief Conversion constructor. 55 69 56 70 Create a WeightIterator<Base> from a 57 71 WeightIterator<B2>. Possible if B2 is convertible to a … … 72 86 DataIterator d_iter_; 73 87 WeightIterator w_iter_; 74 88 75 89 void advance(size_t n) 76 90 { std::advance(d_iter_, n); std::advance(w_iter_, n); } 77 91 78 92 void decrement(void) { --d_iter_; --w_iter_; } 79 93 80 94 typename std::iterator_traits<DataIterator>::difference_type 81 95 distance_to(const WeightedIterator& other) const 82 96 { return std::distance(d_iter_, other.d_iter_); } 83 97 84 DataWeight dereference(void) const 85 { return DataWeight(*d_iter_, *w_iter_); } 98 utility::DataWeightProxy<DataIterator, WeightIterator> 99 dereference(void) const 100 { 101 return DataWeightProxy<DataIterator, WeightIterator>(d_iter_, 102 w_iter_); 103 } 86 104 87 105 bool equal(const WeightedIterator& other) const
Note: See TracChangeset
for help on using the changeset viewer.