Generic SmartRest library
Dependents: SmartRestUnitTest MbedSmartRest MbedSmartRestStreaming
Value.h@1:3e7b4c9e0821, 2014-04-16 (annotated)
- Committer:
- vwochnik
- Date:
- Wed Apr 16 08:30:49 2014 +0000
- Revision:
- 1:3e7b4c9e0821
- Parent:
- 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 | * Value.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 | /** |
vwochnik | 0:744801d5734d | 30 | * @file Value.h |
vwochnik | 0:744801d5734d | 31 | * Represents a generic data value. |
vwochnik | 0:744801d5734d | 32 | */ |
vwochnik | 0:744801d5734d | 33 | |
vwochnik | 0:744801d5734d | 34 | #ifndef VALUE_H |
vwochnik | 0:744801d5734d | 35 | #define VALUE_H |
vwochnik | 0:744801d5734d | 36 | |
vwochnik | 0:744801d5734d | 37 | #ifdef HAVE_CONFIG_H |
vwochnik | 0:744801d5734d | 38 | #include <config.h> |
vwochnik | 0:744801d5734d | 39 | #endif |
vwochnik | 0:744801d5734d | 40 | |
vwochnik | 0:744801d5734d | 41 | #include <stddef.h> |
vwochnik | 0:744801d5734d | 42 | #include <stdint.h> |
vwochnik | 0:744801d5734d | 43 | #include "AbstractDataSink.h" |
vwochnik | 0:744801d5734d | 44 | |
vwochnik | 0:744801d5734d | 45 | /** Return value indicating a null value. */ |
vwochnik | 0:744801d5734d | 46 | #define VALUE_NULL 0 |
vwochnik | 0:744801d5734d | 47 | /** Return value indicating an integer value. */ |
vwochnik | 0:744801d5734d | 48 | #define VALUE_INTEGER 1 |
vwochnik | 0:744801d5734d | 49 | /** Return value indicating a floating-point number. */ |
vwochnik | 0:744801d5734d | 50 | #define VALUE_FLOAT 2 |
vwochnik | 0:744801d5734d | 51 | /** Return value indicating a character string. */ |
vwochnik | 0:744801d5734d | 52 | #define VALUE_CHARACTER 3 |
vwochnik | 0:744801d5734d | 53 | |
vwochnik | 0:744801d5734d | 54 | /** |
vwochnik | 0:744801d5734d | 55 | * A generic value offering means to obtain the value type and contents |
vwochnik | 0:744801d5734d | 56 | * as well as writing the value to a sink. |
vwochnik | 0:744801d5734d | 57 | */ |
vwochnik | 0:744801d5734d | 58 | class Value |
vwochnik | 0:744801d5734d | 59 | { |
vwochnik | 0:744801d5734d | 60 | public: |
vwochnik | 0:744801d5734d | 61 | virtual ~Value() { }; |
vwochnik | 0:744801d5734d | 62 | |
vwochnik | 0:744801d5734d | 63 | /** |
vwochnik | 0:744801d5734d | 64 | * Returns the value type which can be VALUE_NULL, VALUE_INTEGER, |
vwochnik | 0:744801d5734d | 65 | * VALUE_FLOAT or VALUE_CHARACTER. |
vwochnik | 0:744801d5734d | 66 | * @return the value type |
vwochnik | 0:744801d5734d | 67 | */ |
vwochnik | 0:744801d5734d | 68 | virtual uint8_t valueType() const = 0; |
vwochnik | 0:744801d5734d | 69 | |
vwochnik | 0:744801d5734d | 70 | /** |
vwochnik | 0:744801d5734d | 71 | * Returns the integer value if an integer type, otherwise zero. |
vwochnik | 0:744801d5734d | 72 | * @return integer value |
vwochnik | 0:744801d5734d | 73 | */ |
vwochnik | 0:744801d5734d | 74 | virtual long integerValue() const = 0; |
vwochnik | 0:744801d5734d | 75 | |
vwochnik | 0:744801d5734d | 76 | /** |
vwochnik | 0:744801d5734d | 77 | * Returns the float value if a float type, otherwise zero. |
vwochnik | 0:744801d5734d | 78 | * @return float value |
vwochnik | 0:744801d5734d | 79 | */ |
vwochnik | 0:744801d5734d | 80 | virtual double floatValue() const = 0; |
vwochnik | 0:744801d5734d | 81 | |
vwochnik | 0:744801d5734d | 82 | /** |
vwochnik | 0:744801d5734d | 83 | * Returns the character value if a character type, otherwise zero. |
vwochnik | 0:744801d5734d | 84 | * @return character value |
vwochnik | 0:744801d5734d | 85 | */ |
vwochnik | 0:744801d5734d | 86 | virtual const char * characterValue() const = 0; |
vwochnik | 0:744801d5734d | 87 | |
vwochnik | 0:744801d5734d | 88 | /** |
vwochnik | 0:744801d5734d | 89 | * Writes the value to a sink. |
vwochnik | 0:744801d5734d | 90 | * If necessary, quotes and escape characters may be added. |
vwochnik | 0:744801d5734d | 91 | * @param sink the sink to write the value to |
vwochnik | 0:744801d5734d | 92 | * @return the number of bytes written |
vwochnik | 0:744801d5734d | 93 | */ |
vwochnik | 0:744801d5734d | 94 | virtual size_t write(AbstractDataSink&) const = 0; |
vwochnik | 0:744801d5734d | 95 | |
vwochnik | 0:744801d5734d | 96 | /** |
vwochnik | 0:744801d5734d | 97 | * Returns the number of bytes required to write this value to a sink. |
vwochnik | 0:744801d5734d | 98 | * @return number of bytes required to write this value |
vwochnik | 0:744801d5734d | 99 | */ |
vwochnik | 0:744801d5734d | 100 | virtual size_t length() const = 0; |
vwochnik | 0:744801d5734d | 101 | |
vwochnik | 0:744801d5734d | 102 | /** |
vwochnik | 0:744801d5734d | 103 | * Copies this value to the heap. Referenced contents must also be |
vwochnik | 0:744801d5734d | 104 | * copied. |
vwochnik | 0:744801d5734d | 105 | * @return a new value instance allocated on the heap |
vwochnik | 0:744801d5734d | 106 | */ |
vwochnik | 0:744801d5734d | 107 | virtual Value* copy() const = 0; |
vwochnik | 0:744801d5734d | 108 | }; |
vwochnik | 0:744801d5734d | 109 | |
vwochnik | 0:744801d5734d | 110 | #endif |