Own fork of MbedSmartRest
Dependents: MbedSmartRestMain MbedSmartRestMain
Fork of MbedSmartRest by
Value.h
00001 /* 00002 * Value.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 /** 00030 * @file Value.h 00031 * Represents a generic data value. 00032 */ 00033 00034 #ifndef VALUE_H 00035 #define VALUE_H 00036 00037 #include "config.h" 00038 #include <stddef.h> 00039 #include <stdint.h> 00040 #include "AbstractDataSink.h" 00041 00042 /** Return value indicating a null value. */ 00043 #define VALUE_NULL 0 00044 /** Return value indicating an integer value. */ 00045 #define VALUE_INTEGER 1 00046 /** Return value indicating a floating-point number. */ 00047 #define VALUE_FLOAT 2 00048 /** Return value indicating a character string. */ 00049 #define VALUE_CHARACTER 3 00050 00051 /** 00052 * A generic value offering means to obtain the value type and contents 00053 * as well as writing the value to a sink. 00054 */ 00055 class Value 00056 { 00057 public: 00058 virtual ~Value() { }; 00059 00060 /** 00061 * Returns the value type which can be VALUE_NULL, VALUE_INTEGER, 00062 * VALUE_FLOAT or VALUE_CHARACTER. 00063 * @return the value type 00064 */ 00065 virtual uint8_t valueType() const = 0; 00066 00067 /** 00068 * Returns the integer value if an integer type, otherwise zero. 00069 * @return integer value 00070 */ 00071 virtual long integerValue() const = 0; 00072 00073 /** 00074 * Returns the float value if a float type, otherwise zero. 00075 * @return float value 00076 */ 00077 virtual double floatValue() const = 0; 00078 00079 /** 00080 * Returns the character value if a character type, otherwise zero. 00081 * @return character value 00082 */ 00083 virtual const char * characterValue() const = 0; 00084 00085 /** 00086 * Writes the value to a sink. 00087 * If necessary, quotes and escape characters may be added. 00088 * @param sink the sink to write the value to 00089 * @return the number of bytes written 00090 */ 00091 virtual size_t write(AbstractDataSink&) const = 0; 00092 00093 /** 00094 * Returns the number of bytes required to write this value to a sink. 00095 * @return number of bytes required to write this value 00096 */ 00097 virtual size_t length() const = 0; 00098 00099 /** 00100 * Copies this value to the heap. Referenced contents must also be 00101 * copied. 00102 * @return a new value instance allocated on the heap 00103 */ 00104 virtual Value* copy() const = 0; 00105 }; 00106 00107 #endif
Generated on Tue Jul 12 2022 17:00:01 by 1.7.2