Changeset 1535
- Timestamp:
- Sep 25, 2008, 9:01:48 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/data_weight_proxy_test.cc
r1533 r1535 25 25 #include "yat/utility/DataWeightProxy.h" 26 26 27 namespace theplu { 28 namespace yat { 29 namespace test { 30 class ProxyHolder 31 { 32 public: 33 ProxyHolder(utility::DataWeightProxy& proxy) 34 : proxy_(proxy) {} 35 36 inline utility::DataWeightProxy& operator()(void) { return proxy_; } 37 inline const utility::DataWeightProxy& operator()(void) const 38 { return proxy_; } 39 private: 40 utility::DataWeightProxy& proxy_; 41 }; 42 }}} 43 27 44 using namespace theplu::yat; 28 45 … … 33 50 34 51 using utility::DataWeightProxy; 52 using utility::DataWeight; 35 53 36 54 double x=1.2; 37 double y=3.14; 38 DataWeightProxy proxy(x,y); 55 double w=3.14; 56 DataWeight xw(x, w); 57 DataWeightProxy proxy(x,w); 58 if (xw != proxy) { 59 suite.add(false); 60 } 61 if (proxy != xw) { 62 suite.add(false); 63 } 39 64 40 suite.return_value(); 65 suite.err() << "testing conversion to DataWeight\n"; 66 test::ProxyHolder holder(proxy); 67 const test::ProxyHolder const_holder(proxy); 68 69 xw = holder(); 70 xw = const_holder(); 71 72 if (holder() != holder()) { 73 suite.add(false); 74 } 75 if (holder() != const_holder()) { 76 suite.add(false); 77 } 78 79 suite.err() << "testing assignment\n"; 80 holder().data() = 1.0; 81 suite.add(suite.equal(holder().data(), 1.0)); 82 holder().weight() = 1.0; 83 suite.add(suite.equal(holder().weight(), 1.0)); 84 85 DataWeight xw2(3.14, 0.5); 86 holder() = xw2; 87 suite.add(suite.equal(holder().data(), 3.14)); 88 suite.add(suite.equal(holder().weight(), 0.5)); 89 90 DataWeight xw3; 91 xw3 = const_holder(); 92 suite.add(suite.equal(xw3.data(), 3.14)); 93 suite.add(suite.equal(xw3.weight(), 0.5)); 94 95 return suite.return_value(); 41 96 } -
trunk/yat/utility/DataWeightProxy.cc
r1533 r1535 52 52 } 53 53 54 55 DataWeightProxy& DataWeightProxy::operator=(const DataWeight& rhs) 56 { 57 data() = rhs.data(); 58 weight() = rhs.weight(); 59 return *this; 60 } 61 62 63 DataWeightProxy::operator DataWeight() const 64 { 65 return DataWeight(data(), weight()); 66 } 67 68 54 69 }}} // of namespace utility, yat, and theplu -
trunk/yat/utility/DataWeightProxy.h
r1533 r1535 22 22 along with yat. If not, see <http://www.gnu.org/licenses/>. 23 23 */ 24 25 #include "DataWeight.h" 24 26 25 27 namespace theplu { … … 62 64 */ 63 65 const double& weight(void) const; 66 67 /** 68 \brief assignment operator 69 */ 70 DataWeightProxy& operator=(const DataWeight& rhs); 71 72 /** 73 \brief Conversion to DataWeight 74 */ 75 operator DataWeight() const; 76 64 77 private: 65 78 double& data_;
Note: See TracChangeset
for help on using the changeset viewer.