mbed.org implementation of the abstract SmartREST library for the Cumulocity Platform SmartREST protocol.
Dependents: MbedSmartRestMain MbedSmartRestMain
Diff: Aggregator.h
- Revision:
- 5:2b74510900da
- Parent:
- 0:099f76422485
- Child:
- 6:cd7ba1ddb664
--- a/Aggregator.h Wed Jul 09 15:37:19 2014 +0200 +++ b/Aggregator.h Thu Jul 10 16:20:31 2014 +0200 @@ -32,6 +32,7 @@ #include "config.h" #include <stddef.h> #include "DataGenerator.h" +#include "Record.h" #ifndef SMARTREST_AGGREGATOR_INITIAL_CAPACITY #define SMARTREST_AGGREGATOR_INITIAL_CAPACITY 50 @@ -42,11 +43,7 @@ //#define SMARTREST_AGGREGATOR_FIXED_SIZE 100 /** - * An aggregator of data generators. This class can aggregate instances of - * itself. - * If the aggregator is set to copying all added data generators using - * the copy() method, all objects are being properly deallocated on - * destruction. + * An aggregator of records. * * Example: * @code @@ -88,26 +85,34 @@ * Creates a new Aggregator instance. * @param capacity the initial capacity of the instance * @param growing specifies the capability of this instance to grow - * @param copy specifies whether all added data generators shall be - * copied using the copy() method + * @param managed specifies whether internal memory management shall be + * used. If true, all added records will be copied to + * the heap and freed accordingly. */ - Aggregator(size_t=SMARTREST_AGGREGATOR_INITIAL_CAPACITY, bool=true, bool=false); + Aggregator(size_t = SMARTREST_AGGREGATOR_INITIAL_CAPACITY, bool = true, bool = false); #else /** * Creates a new Aggregator instance. - * @param copy specifies whether all added data generators shall be - * copied using the copy() method + * @param managed specifies whether internal memory management shall be + * used. If true, all added records will be copied to + * the heap and freed accordingly. */ - Aggregator(bool=false); + Aggregator(bool = false); #endif ~Aggregator(); /** - * Adds a data generator to the aggregator. - * @param generator the data generator to add + * Adds a record to the aggregator. + * @param record the record to add * @return true if added, false otherwise. */ - bool add(const DataGenerator&); + bool add(const Record&); + + /** + * Retrieves the nth record from the aggregator. + * @param index the index of the nth element to retrieve + */ + const Record& get(size_t); /** * Clears the aggregator. The capacity will shrink to it's initial @@ -116,8 +121,8 @@ void clear(); /** - * Returns the number of data generators aggregated by this instance. - * @return the number of data generators aggregated + * Returns the number of records aggregated by this instance. + * @return the number of records aggregated */ size_t length(); @@ -134,18 +139,24 @@ */ size_t capacity(); + /** + * Returns whether this aggregator is using internal memory management. + * @return whether internal memory management is being used + */ + bool isManaged(); + size_t writeTo(AbstractDataSink&) const; size_t writtenLength() const; - DataGenerator* copy() const; + Aggregator* copy() const; private: #ifdef SMARTREST_AGGREGATOR_FIXED_SIZE - const DataGenerator *_list[SMARTREST_AGGREGATOR_FIXED_SIZE]; + const Record *_list[SMARTREST_AGGREGATOR_FIXED_SIZE]; #else - const DataGenerator **_list; + const Record **_list; #endif size_t _length; - bool _alloc; + bool _managed; #ifndef SMARTREST_AGGREGATOR_FIXED_SIZE size_t _capacity, _initial; bool _growing;