Own fork of MbedSmartRest
Dependents: MbedSmartRestMain MbedSmartRestMain
Fork of MbedSmartRest by
ParsedRecord.h
00001 /* 00002 * ParsedRecord.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 PARSEDRECORD_H 00030 #define PARSEDRECORD_H 00031 00032 #include "config.h" 00033 #include "DataGenerator.h" 00034 #include "Record.h" 00035 #include "Value.h" 00036 00037 #ifndef SMARTREST_PARSED_DYNAMIC_ALLOC 00038 #ifndef SMARTREST_PARSED_FIXED_SIZE 00039 #define SMARTREST_PARSED_FIXED_SIZE 24 00040 #endif 00041 #endif 00042 00043 class Parser; 00044 00045 /** 00046 * This class provides accessors for values in a parsed record. 00047 * 00048 * Example: 00049 * @code 00050 * // given a concrete SmartRest client instance 00051 * SmartRest client; 00052 00053 * ParsedRecord record; 00054 * if (client.receive(record) == SMARTREST_SUCCESS) { 00055 * for (size_ i = 0; i < record.values(); i++) { 00056 * const Value& val = record.value(i); 00057 * switch (val.valueType()) { 00058 * case VALUE_NULL: 00059 * printf("Null value.\n"); 00060 * break; 00061 * case VALUE_CHARACTER: 00062 * printf("Character value: %s\n", val.characterValue()); 00063 * break; 00064 * case VALUE_INTEGER: 00065 * printf("Integer value: %d\n", val.integerValue()); 00066 * break; 00067 * case VALUE_FLOAT: 00068 * printf("Float value: %lf\n", val.floatValue()); 00069 * break; 00070 * } 00071 * } 00072 * } 00073 * @encode 00074 */ 00075 class ParsedRecord : public Record 00076 { 00077 public: 00078 ParsedRecord(bool = false); 00079 virtual ~ParsedRecord(); 00080 00081 virtual size_t values() const; 00082 virtual const Value& value(size_t) const; 00083 00084 virtual ParsedRecord* copy() const; 00085 00086 /** 00087 * Returns the raw value string by index 00088 * @param index the index of the value 00089 * @return a pointer to the raw value 00090 */ 00091 const char * rawValue(size_t) const; 00092 00093 protected: 00094 bool set(const char*, size_t); 00095 void clear(); 00096 00097 private: 00098 #ifdef SMARTREST_PARSED_DYNAMIC_ALLOC 00099 const Value **_values; 00100 #else 00101 const Value *_values[SMARTREST_PARSED_FIXED_SIZE]; 00102 #endif 00103 const char *_buffer; 00104 size_t _count; 00105 bool _copy; 00106 00107 friend class Parser; 00108 }; 00109 00110 00111 #endif
Generated on Tue Jul 12 2022 17:00:00 by 1.7.2