Own fork of MbedSmartRest

Dependents:   MbedSmartRestMain MbedSmartRestMain

Fork of MbedSmartRest by Cumulocity Official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ComposedRecord.h Source File

ComposedRecord.h

00001 /*
00002  * ComposedRecord.h
00003  *
00004  * Created on: Nov 1, 2013
00005  * * Authors: Vincent Wochnik <v.wochnik@gmail.com>
00006  *
00007  * Copyright (c) 2013 Cumulocity GmbH
00008  *
00009  * Permission is hereby granted, free of charge, to any person obtaining
00010  * a copy of this software and associated documentation files (the
00011  * "Software"), to deal in the Software without restriction, including
00012  * without limitation the rights to use, copy, modify, merge, publish,
00013  * distribute, sublicense, and/or sell copies of the Software, and to
00014  * permit persons to whom the Software is furnished to do so, subject to
00015  * the following conditions:
00016  *
00017  * The above copyright notice and this permission notice shall be
00018  * included in all copies or substantial portions of the Software.
00019  *
00020  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00021  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00022  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00023  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00024  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00025  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00026  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00027  */
00028 
00029 #ifndef COMPOSEDRECORD_H
00030 #define COMPOSEDRECORD_H
00031 
00032 #include "config.h"
00033 #include "DataGenerator.h"
00034 #include "Record.h"
00035 #include "Value.h"
00036 
00037 #ifndef SMARTREST_COMPOSED_INITIAL_CAPACITY
00038 #define SMARTREST_COMPOSED_INITIAL_CAPACITY 10
00039 #endif
00040 #ifndef SMARTREST_COMPOSED_MEMORY_INCREMENT
00041 #define SMARTREST_COMPOSED_MEMORY_INCREMENT 5
00042 #endif
00043 //#define SMARTREST_COMPOSED_FIXED_SIZE 25
00044 
00045 /**
00046  * This value set collects values and serializes them into a SmartRequest.
00047  * 
00048  * Example 1 (low memory usage):
00049  * @code
00050  * // this record does not copy added values into the heap because the
00051  * // lifetime of the instance does not exceed the lifetime of its added
00052  * // values.
00053  * ComposedRecord record(false);
00054  * IntegerValue msgId(100);
00055  * CharValue str("Hello World!");
00056  * FloatValue num(3.1415, 2);
00057  * record.add(msgId).add(str).add(num);
00058  * @encode
00059  * 
00060  * Example 2 (short form):
00061  * @code
00062  * // this record needs to copy added values due to the limited
00063  * // lifetime of temporary objects.
00064  * ComposedRecord record(true);
00065  * record.add(IntegerValue(100)).add(CharValue("Hello World!");
00066  * record.add(FloatValue(3.1415, 2));
00067  * @encode
00068  */
00069 class ComposedRecord : public Record
00070 {
00071     public:
00072         ComposedRecord(bool = false);
00073         virtual ~ComposedRecord();
00074 
00075         bool add(const Value&);
00076         void clear();
00077 
00078         virtual size_t values() const;
00079         virtual const Value& value(size_t) const;
00080 
00081         virtual ComposedRecord* copy() const;
00082 
00083     private:
00084 #ifndef SMARTREST_COMPOSED_FIXED_SIZE
00085         const Value **_values;
00086         size_t _capacity;
00087 #else
00088         const Value *_values[SMARTREST_COMPOSED_FIXED_SIZE];
00089 #endif
00090         size_t _count;
00091         bool _alloc;
00092 };
00093 
00094 #endif