Own fork of MbedSmartRest

Dependents:   MbedSmartRestMain MbedSmartRestMain

Fork of MbedSmartRest by Cumulocity Official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ParsedValue.h Source File

ParsedValue.h

00001 /*
00002  * ParsedValue.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 PARSEDVALUE_H
00030 #define PARSEDVALUE_H
00031 
00032 #include "config.h"
00033 #include "Value.h"
00034 #include "CharValue.h"
00035 
00036 #ifndef SMARTREST_PARSED_FIXED_SIZE
00037 #define SMARTREST_PARSED_FIXED_SIZE 16
00038 #endif
00039 
00040 /**
00041  * Provides access to a parsed value by implementing the value interface.
00042  * 
00043  * Example:
00044  * @code
00045  * // given a filled parsed record
00046  * ParsedRecord record;
00047  * 
00048  * // get first value
00049  * const Value& val = record.value(0);
00050  * switch (val.valueType()) {
00051  * case VALUE_NULL:
00052  *     printf("Null value.\n");
00053  *     break;
00054  * case VALUE_CHARACTER:
00055  *     printf("Character value: %s\n", val.characterValue());
00056  *     break;
00057  * case VALUE_INTEGER:
00058  *     printf("Integer value: %d\n", val.integerValue());
00059  *     break;
00060  * case VALUE_FLOAT:
00061  *     printf("Float value: %lf\n", val.floatValue());
00062  *     break;
00063  * }
00064  * @encode
00065  */
00066 class ParsedValue : public Value
00067 {
00068     public:
00069         ParsedValue(const char*, bool = false);
00070 
00071         virtual uint8_t valueType() const;
00072         virtual long integerValue() const;
00073         virtual double floatValue() const;
00074         virtual const char * characterValue() const;
00075 
00076         virtual size_t write(AbstractDataSink&) const;
00077         virtual size_t length() const;
00078         virtual Value* copy() const;
00079 
00080     private:
00081         void extractValue();
00082 
00083     private:
00084         CharValue _value;
00085         uint8_t _type;
00086         double _float;
00087         long _integer;
00088 };
00089 
00090 #endif