Wiselib
wiselib.testing/algorithms/aggregation/aggregate.h
Go to the documentation of this file.
00001 /*
00002  * File:   aggregationmsg.h
00003  * Author: Koninis
00004  *
00005  * Created on January 22, 2011, 1:16 PM
00006  */
00007 
00008 #ifndef AGGREGATE_H
00009 #define  AGGREGATE_H
00010 
00011 namespace wiselib {
00012 
00018     template
00019     <typename OsModel_P, typename AggregateValue_P>
00020     class aggregate_base {
00021     public:
00022         typedef OsModel_P OsModel;
00023         typedef typename OsModel::block_data_t block_data_t;
00024         typedef typename OsModel::Radio::node_id_t node_id_t;
00025         typedef typename OsModel::Radio::size_t size_t;
00026 
00027         typedef AggregateValue_P value_t;
00028         typedef aggregate_base<OsModel,AggregateValue_P> self_t;
00029 
00030         aggregate_base() {
00031          value = 0xFFFFFFFF;
00032 //                timeStampMillis = 0;
00033 //                source = 0;
00034 //            value = 0;
00035         }
00036 
00037         aggregate_base(block_data_t * buffer) {
00038             value = read<OsModel, block_data_t, value_t>(buffer);
00039         }
00040 
00041         void set_value (value_t v) {
00042             value = v;
00043         }
00044 
00045         value_t get() {
00046             return value;
00047         }
00048 
00049 //        aggregate_base& operator+(aggregate_base &rhs) {
00050 //            aggregate_base result;
00051 
00052 //            result.set_value((this->get() > rhs.get()) ? this->get() : rhs.get());
00053 
00054 //            result.set_value(value + rhs.get());
00055 //            return self_t();
00056 //        }
00057 
00058         self_t combine(self_t &rhs) {
00059             self_t result;
00060             result.set_value((this->get() < rhs.get()) ? this->get() : rhs.get());
00061 
00062 //            result.set_value(this->get() + rhs.get());
00063             return result;
00064         }
00065 
00066         void writeTo(uint8_t *buffer) {
00067             write<OsModel, block_data_t, value_t> (buffer, value);
00068         }
00069 
00070         size_t size() {
00071             return sizeof(value);
00072         }
00073 
00074     private:
00075         value_t value;
00076 //        node_id_t source;
00077 //        uint32_t timeStampMillis;
00078     };
00079 
00080 }
00081 
00082 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines