Own fork of MbedSmartRest
Dependents: MbedSmartRestMain MbedSmartRestMain
Fork of MbedSmartRest by
Value.h@11:e1bee9a77652, 2014-11-15 (annotated)
- Committer:
- Cumulocity
- Date:
- Sat Nov 15 11:21:01 2014 +0100
- Revision:
- 11:e1bee9a77652
- Parent:
- 0:099f76422485
Updated from revision ce16ad78546a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Cumulocity | 0:099f76422485 | 1 | /* |
Cumulocity | 0:099f76422485 | 2 | * Value.h |
Cumulocity | 0:099f76422485 | 3 | * |
Cumulocity | 0:099f76422485 | 4 | * Created on: Nov 1, 2013 |
Cumulocity | 0:099f76422485 | 5 | * * Authors: Vincent Wochnik <v.wochnik@gmail.com> |
Cumulocity | 0:099f76422485 | 6 | * |
Cumulocity | 0:099f76422485 | 7 | * Copyright (c) 2013 Cumulocity GmbH |
Cumulocity | 0:099f76422485 | 8 | * |
Cumulocity | 0:099f76422485 | 9 | * Permission is hereby granted, free of charge, to any person obtaining |
Cumulocity | 0:099f76422485 | 10 | * a copy of this software and associated documentation files (the |
Cumulocity | 0:099f76422485 | 11 | * "Software"), to deal in the Software without restriction, including |
Cumulocity | 0:099f76422485 | 12 | * without limitation the rights to use, copy, modify, merge, publish, |
Cumulocity | 0:099f76422485 | 13 | * distribute, sublicense, and/or sell copies of the Software, and to |
Cumulocity | 0:099f76422485 | 14 | * permit persons to whom the Software is furnished to do so, subject to |
Cumulocity | 0:099f76422485 | 15 | * the following conditions: |
Cumulocity | 0:099f76422485 | 16 | * |
Cumulocity | 0:099f76422485 | 17 | * The above copyright notice and this permission notice shall be |
Cumulocity | 0:099f76422485 | 18 | * included in all copies or substantial portions of the Software. |
Cumulocity | 0:099f76422485 | 19 | * |
Cumulocity | 0:099f76422485 | 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
Cumulocity | 0:099f76422485 | 21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
Cumulocity | 0:099f76422485 | 22 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Cumulocity | 0:099f76422485 | 23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
Cumulocity | 0:099f76422485 | 24 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
Cumulocity | 0:099f76422485 | 25 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
Cumulocity | 0:099f76422485 | 26 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Cumulocity | 0:099f76422485 | 27 | */ |
Cumulocity | 0:099f76422485 | 28 | |
Cumulocity | 0:099f76422485 | 29 | /** |
Cumulocity | 0:099f76422485 | 30 | * @file Value.h |
Cumulocity | 0:099f76422485 | 31 | * Represents a generic data value. |
Cumulocity | 0:099f76422485 | 32 | */ |
Cumulocity | 0:099f76422485 | 33 | |
Cumulocity | 0:099f76422485 | 34 | #ifndef VALUE_H |
Cumulocity | 0:099f76422485 | 35 | #define VALUE_H |
Cumulocity | 0:099f76422485 | 36 | |
Cumulocity | 0:099f76422485 | 37 | #include "config.h" |
Cumulocity | 0:099f76422485 | 38 | #include <stddef.h> |
Cumulocity | 0:099f76422485 | 39 | #include <stdint.h> |
Cumulocity | 0:099f76422485 | 40 | #include "AbstractDataSink.h" |
Cumulocity | 0:099f76422485 | 41 | |
Cumulocity | 0:099f76422485 | 42 | /** Return value indicating a null value. */ |
Cumulocity | 0:099f76422485 | 43 | #define VALUE_NULL 0 |
Cumulocity | 0:099f76422485 | 44 | /** Return value indicating an integer value. */ |
Cumulocity | 0:099f76422485 | 45 | #define VALUE_INTEGER 1 |
Cumulocity | 0:099f76422485 | 46 | /** Return value indicating a floating-point number. */ |
Cumulocity | 0:099f76422485 | 47 | #define VALUE_FLOAT 2 |
Cumulocity | 0:099f76422485 | 48 | /** Return value indicating a character string. */ |
Cumulocity | 0:099f76422485 | 49 | #define VALUE_CHARACTER 3 |
Cumulocity | 0:099f76422485 | 50 | |
Cumulocity | 0:099f76422485 | 51 | /** |
Cumulocity | 0:099f76422485 | 52 | * A generic value offering means to obtain the value type and contents |
Cumulocity | 0:099f76422485 | 53 | * as well as writing the value to a sink. |
Cumulocity | 0:099f76422485 | 54 | */ |
Cumulocity | 0:099f76422485 | 55 | class Value |
Cumulocity | 0:099f76422485 | 56 | { |
Cumulocity | 11:e1bee9a77652 | 57 | public: |
Cumulocity | 11:e1bee9a77652 | 58 | virtual ~Value() { }; |
Cumulocity | 0:099f76422485 | 59 | |
Cumulocity | 11:e1bee9a77652 | 60 | /** |
Cumulocity | 11:e1bee9a77652 | 61 | * Returns the value type which can be VALUE_NULL, VALUE_INTEGER, |
Cumulocity | 11:e1bee9a77652 | 62 | * VALUE_FLOAT or VALUE_CHARACTER. |
Cumulocity | 11:e1bee9a77652 | 63 | * @return the value type |
Cumulocity | 11:e1bee9a77652 | 64 | */ |
Cumulocity | 11:e1bee9a77652 | 65 | virtual uint8_t valueType() const = 0; |
Cumulocity | 0:099f76422485 | 66 | |
Cumulocity | 11:e1bee9a77652 | 67 | /** |
Cumulocity | 11:e1bee9a77652 | 68 | * Returns the integer value if an integer type, otherwise zero. |
Cumulocity | 11:e1bee9a77652 | 69 | * @return integer value |
Cumulocity | 11:e1bee9a77652 | 70 | */ |
Cumulocity | 11:e1bee9a77652 | 71 | virtual long integerValue() const = 0; |
Cumulocity | 0:099f76422485 | 72 | |
Cumulocity | 11:e1bee9a77652 | 73 | /** |
Cumulocity | 11:e1bee9a77652 | 74 | * Returns the float value if a float type, otherwise zero. |
Cumulocity | 11:e1bee9a77652 | 75 | * @return float value |
Cumulocity | 11:e1bee9a77652 | 76 | */ |
Cumulocity | 11:e1bee9a77652 | 77 | virtual double floatValue() const = 0; |
Cumulocity | 0:099f76422485 | 78 | |
Cumulocity | 11:e1bee9a77652 | 79 | /** |
Cumulocity | 11:e1bee9a77652 | 80 | * Returns the character value if a character type, otherwise zero. |
Cumulocity | 11:e1bee9a77652 | 81 | * @return character value |
Cumulocity | 11:e1bee9a77652 | 82 | */ |
Cumulocity | 11:e1bee9a77652 | 83 | virtual const char * characterValue() const = 0; |
Cumulocity | 0:099f76422485 | 84 | |
Cumulocity | 11:e1bee9a77652 | 85 | /** |
Cumulocity | 11:e1bee9a77652 | 86 | * Writes the value to a sink. |
Cumulocity | 11:e1bee9a77652 | 87 | * If necessary, quotes and escape characters may be added. |
Cumulocity | 11:e1bee9a77652 | 88 | * @param sink the sink to write the value to |
Cumulocity | 11:e1bee9a77652 | 89 | * @return the number of bytes written |
Cumulocity | 11:e1bee9a77652 | 90 | */ |
Cumulocity | 11:e1bee9a77652 | 91 | virtual size_t write(AbstractDataSink&) const = 0; |
Cumulocity | 0:099f76422485 | 92 | |
Cumulocity | 11:e1bee9a77652 | 93 | /** |
Cumulocity | 11:e1bee9a77652 | 94 | * Returns the number of bytes required to write this value to a sink. |
Cumulocity | 11:e1bee9a77652 | 95 | * @return number of bytes required to write this value |
Cumulocity | 11:e1bee9a77652 | 96 | */ |
Cumulocity | 11:e1bee9a77652 | 97 | virtual size_t length() const = 0; |
Cumulocity | 0:099f76422485 | 98 | |
Cumulocity | 11:e1bee9a77652 | 99 | /** |
Cumulocity | 11:e1bee9a77652 | 100 | * Copies this value to the heap. Referenced contents must also be |
Cumulocity | 11:e1bee9a77652 | 101 | * copied. |
Cumulocity | 11:e1bee9a77652 | 102 | * @return a new value instance allocated on the heap |
Cumulocity | 11:e1bee9a77652 | 103 | */ |
Cumulocity | 11:e1bee9a77652 | 104 | virtual Value* copy() const = 0; |
Cumulocity | 0:099f76422485 | 105 | }; |
Cumulocity | 0:099f76422485 | 106 | |
Cumulocity | 0:099f76422485 | 107 | #endif |