Generic SmartRest library
Dependents: SmartRestUnitTest MbedSmartRest MbedSmartRestStreaming
Aggregator.h@0:744801d5734d, 2014-03-24 (annotated)
- Committer:
- vwochnik
- Date:
- Mon Mar 24 09:57:40 2014 +0000
- Revision:
- 0:744801d5734d
fix;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vwochnik | 0:744801d5734d | 1 | /* |
vwochnik | 0:744801d5734d | 2 | * Aggregator.h |
vwochnik | 0:744801d5734d | 3 | * |
vwochnik | 0:744801d5734d | 4 | * Created on: Nov 1, 2013 |
vwochnik | 0:744801d5734d | 5 | * * Authors: Vincent Wochnik <v.wochnik@gmail.com> |
vwochnik | 0:744801d5734d | 6 | * |
vwochnik | 0:744801d5734d | 7 | * Copyright (c) 2013 Cumulocity GmbH |
vwochnik | 0:744801d5734d | 8 | * |
vwochnik | 0:744801d5734d | 9 | * Permission is hereby granted, free of charge, to any person obtaining |
vwochnik | 0:744801d5734d | 10 | * a copy of this software and associated documentation files (the |
vwochnik | 0:744801d5734d | 11 | * "Software"), to deal in the Software without restriction, including |
vwochnik | 0:744801d5734d | 12 | * without limitation the rights to use, copy, modify, merge, publish, |
vwochnik | 0:744801d5734d | 13 | * distribute, sublicense, and/or sell copies of the Software, and to |
vwochnik | 0:744801d5734d | 14 | * permit persons to whom the Software is furnished to do so, subject to |
vwochnik | 0:744801d5734d | 15 | * the following conditions: |
vwochnik | 0:744801d5734d | 16 | * |
vwochnik | 0:744801d5734d | 17 | * The above copyright notice and this permission notice shall be |
vwochnik | 0:744801d5734d | 18 | * included in all copies or substantial portions of the Software. |
vwochnik | 0:744801d5734d | 19 | * |
vwochnik | 0:744801d5734d | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
vwochnik | 0:744801d5734d | 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
vwochnik | 0:744801d5734d | 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
vwochnik | 0:744801d5734d | 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
vwochnik | 0:744801d5734d | 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
vwochnik | 0:744801d5734d | 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
vwochnik | 0:744801d5734d | 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
vwochnik | 0:744801d5734d | 27 | */ |
vwochnik | 0:744801d5734d | 28 | |
vwochnik | 0:744801d5734d | 29 | #ifndef AGGREGATOR_H |
vwochnik | 0:744801d5734d | 30 | #define AGGREGATOR_H |
vwochnik | 0:744801d5734d | 31 | |
vwochnik | 0:744801d5734d | 32 | #ifdef HAVE_CONFIG_H |
vwochnik | 0:744801d5734d | 33 | #include <config.h> |
vwochnik | 0:744801d5734d | 34 | #endif |
vwochnik | 0:744801d5734d | 35 | |
vwochnik | 0:744801d5734d | 36 | #include <stddef.h> |
vwochnik | 0:744801d5734d | 37 | #include "DataGenerator.h" |
vwochnik | 0:744801d5734d | 38 | |
vwochnik | 0:744801d5734d | 39 | #ifndef AGGREGATOR_INITIAL_CAPACITY |
vwochnik | 0:744801d5734d | 40 | #define AGGREGATOR_INITIAL_CAPACITY 50 |
vwochnik | 0:744801d5734d | 41 | #endif |
vwochnik | 0:744801d5734d | 42 | #ifndef AGGREGATOR_MEMORY_INCREMENT |
vwochnik | 0:744801d5734d | 43 | #define AGGREGATOR_MEMORY_INCREMENT 25 |
vwochnik | 0:744801d5734d | 44 | #endif |
vwochnik | 0:744801d5734d | 45 | //#define AGGREGATOR_FIXED_SIZE 100 |
vwochnik | 0:744801d5734d | 46 | |
vwochnik | 0:744801d5734d | 47 | /** |
vwochnik | 0:744801d5734d | 48 | * An aggregator of data generators. This class can aggregate instances of |
vwochnik | 0:744801d5734d | 49 | * itself. |
vwochnik | 0:744801d5734d | 50 | * If the aggregator is set to copying all added data generators using |
vwochnik | 0:744801d5734d | 51 | * the copy() method, all objects are being properly deallocated on |
vwochnik | 0:744801d5734d | 52 | * destruction. |
vwochnik | 0:744801d5734d | 53 | */ |
vwochnik | 0:744801d5734d | 54 | class Aggregator : public DataGenerator |
vwochnik | 0:744801d5734d | 55 | { |
vwochnik | 0:744801d5734d | 56 | public: |
vwochnik | 0:744801d5734d | 57 | #ifndef AGGREGATOR_FIXED_SIZE |
vwochnik | 0:744801d5734d | 58 | /** |
vwochnik | 0:744801d5734d | 59 | * Creates a new Aggregator instance. |
vwochnik | 0:744801d5734d | 60 | * @param capacity the initial capacity of the instance |
vwochnik | 0:744801d5734d | 61 | * @param growing specifies the capability of this instance to grow |
vwochnik | 0:744801d5734d | 62 | * @param copy specifies whether all added data generators shall be |
vwochnik | 0:744801d5734d | 63 | * copied using the copy() method |
vwochnik | 0:744801d5734d | 64 | */ |
vwochnik | 0:744801d5734d | 65 | Aggregator(size_t=AGGREGATOR_INITIAL_CAPACITY, bool=true, bool=false); |
vwochnik | 0:744801d5734d | 66 | #else |
vwochnik | 0:744801d5734d | 67 | /** |
vwochnik | 0:744801d5734d | 68 | * Creates a new Aggregator instance. |
vwochnik | 0:744801d5734d | 69 | * @param copy specifies whether all added data generators shall be |
vwochnik | 0:744801d5734d | 70 | * copied using the copy() method |
vwochnik | 0:744801d5734d | 71 | */ |
vwochnik | 0:744801d5734d | 72 | Aggregator(bool=false); |
vwochnik | 0:744801d5734d | 73 | #endif |
vwochnik | 0:744801d5734d | 74 | ~Aggregator(); |
vwochnik | 0:744801d5734d | 75 | |
vwochnik | 0:744801d5734d | 76 | /** |
vwochnik | 0:744801d5734d | 77 | * Adds a data generator to the aggregator. |
vwochnik | 0:744801d5734d | 78 | * @param generator the data generator to add |
vwochnik | 0:744801d5734d | 79 | * @return true if added, false otherwise. |
vwochnik | 0:744801d5734d | 80 | */ |
vwochnik | 0:744801d5734d | 81 | bool add(const DataGenerator&); |
vwochnik | 0:744801d5734d | 82 | |
vwochnik | 0:744801d5734d | 83 | /** |
vwochnik | 0:744801d5734d | 84 | * Clears the aggregator. The capacity will shrink to it's initial |
vwochnik | 0:744801d5734d | 85 | * size. |
vwochnik | 0:744801d5734d | 86 | */ |
vwochnik | 0:744801d5734d | 87 | void clear(); |
vwochnik | 0:744801d5734d | 88 | |
vwochnik | 0:744801d5734d | 89 | /** |
vwochnik | 0:744801d5734d | 90 | * Returns the number of data generators aggregated by this instance. |
vwochnik | 0:744801d5734d | 91 | * @return the number of data generators aggregated |
vwochnik | 0:744801d5734d | 92 | */ |
vwochnik | 0:744801d5734d | 93 | size_t length(); |
vwochnik | 0:744801d5734d | 94 | |
vwochnik | 0:744801d5734d | 95 | /** |
vwochnik | 0:744801d5734d | 96 | * Returns whether the aggregator is full. If growing, this will |
vwochnik | 0:744801d5734d | 97 | * always return false. |
vwochnik | 0:744801d5734d | 98 | * @return whether the aggregator is full |
vwochnik | 0:744801d5734d | 99 | */ |
vwochnik | 0:744801d5734d | 100 | bool full(); |
vwochnik | 0:744801d5734d | 101 | |
vwochnik | 0:744801d5734d | 102 | /** |
vwochnik | 0:744801d5734d | 103 | * Returns the capacity of the aggregator. This will always return zero |
vwochnik | 0:744801d5734d | 104 | * if the aggregator is growing. |
vwochnik | 0:744801d5734d | 105 | */ |
vwochnik | 0:744801d5734d | 106 | size_t capacity(); |
vwochnik | 0:744801d5734d | 107 | |
vwochnik | 0:744801d5734d | 108 | size_t writeTo(AbstractDataSink&) const; |
vwochnik | 0:744801d5734d | 109 | size_t writtenLength() const; |
vwochnik | 0:744801d5734d | 110 | DataGenerator* copy() const; |
vwochnik | 0:744801d5734d | 111 | |
vwochnik | 0:744801d5734d | 112 | private: |
vwochnik | 0:744801d5734d | 113 | #ifdef AGGREGATOR_FIXED_SIZE |
vwochnik | 0:744801d5734d | 114 | const DataGenerator *_list[AGGREGATOR_FIXED_SIZE]; |
vwochnik | 0:744801d5734d | 115 | #else |
vwochnik | 0:744801d5734d | 116 | const DataGenerator **_list; |
vwochnik | 0:744801d5734d | 117 | #endif |
vwochnik | 0:744801d5734d | 118 | size_t _length; |
vwochnik | 0:744801d5734d | 119 | bool _alloc; |
vwochnik | 0:744801d5734d | 120 | #ifndef AGGREGATOR_FIXED_SIZE |
vwochnik | 0:744801d5734d | 121 | size_t _capacity, _initial; |
vwochnik | 0:744801d5734d | 122 | bool _growing; |
vwochnik | 0:744801d5734d | 123 | #endif |
vwochnik | 0:744801d5734d | 124 | }; |
vwochnik | 0:744801d5734d | 125 | |
vwochnik | 0:744801d5734d | 126 | #endif |