Generic SmartRest library
Dependents: SmartRestUnitTest MbedSmartRest MbedSmartRestStreaming
Parser.h
00001 /* 00002 * Parser.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 Parser.h 00031 * A CSV parser utilizing an AbstractDataSource instance for reading from 00032 * a connection. 00033 */ 00034 00035 #ifndef PARSER_H 00036 #define PARSER_H 00037 00038 #ifdef HAVE_CONFIG_H 00039 #include <config.h> 00040 #endif 00041 00042 #include <stddef.h> 00043 #include <stdint.h> 00044 #include "ParsedRecord.h" 00045 #include "AbstractDataSource.h" 00046 00047 #ifndef PARSER_BUFFER_SIZE 00048 #define PARSER_BUFFER_SIZE 81 00049 #endif 00050 00051 /** Return value indicating that no error occurred. */ 00052 #define PARSER_SUCCESS 0 00053 /** Return value indicating that a transmission timeout occurred during 00054 * the transmission of a record. */ 00055 #define PARSER_TIMEOUT_ERROR 1 00056 /** Return value indicating the end of response. */ 00057 #define PARSER_END_OF_RESPONSE 2 00058 /** Return value indicating a parse error. */ 00059 #define PARSER_PARSE_ERROR 3 00060 00061 /* 00062 * A CSV parser implementation. 00063 * This class parses CSV rows from a stream. 00064 */ 00065 class Parser 00066 { 00067 public: 00068 /* 00069 * Creates a new Parser instance. 00070 */ 00071 Parser(); 00072 00073 /* 00074 * Parses a row from a stream. 00075 * @param source the source to read from 00076 * @param row the object written to 00077 * @return a non-zero value if and only if an error occured. 00078 */ 00079 uint8_t readFrom(AbstractDataSource&,ParsedRecord&); 00080 00081 private: 00082 void parse(char); 00083 void append(char); 00084 void close(); 00085 void reset(); 00086 00087 private: 00088 char _buffer[PARSER_BUFFER_SIZE]; 00089 uint8_t _state; 00090 char *_ptr; 00091 size_t _count, _length, _trailing; 00092 }; 00093 00094 #endif
Generated on Wed Jul 13 2022 09:53:06 by 1.7.2