nlib
CsvReader.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_MSGPACK_CSVREADER_H_
4 #define INCLUDE_NN_NLIB_MSGPACK_CSVREADER_H_
5 
7 #include "nn/nlib/InputStream.h"
8 #include "nn/nlib/TextReader.h"
9 
10 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
11 #undef NLIB_VIS_PUBLIC
12 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
13 #endif
14 
15 NLIB_NAMESPACE_BEGIN
16 namespace msgpack {
17 
19  public:
20  // In Conformance with RFC4180(https://www.ietf.org/rfc/rfc4180.txt).
21  // except that
22  // pass UTF-8, the UTF-8 string is checked validity.
23  // pass CR, LF, CRLF as a new line.
24  CsvReader() NLIB_NOEXCEPT : m_ErrorValue(0) {}
25  ~CsvReader() NLIB_NOEXCEPT { m_Reader.Close(); }
26  bool Init(InputStream* stream) NLIB_NOEXCEPT NLIB_NONNULL;
27  bool Close() NLIB_NOEXCEPT { return m_Reader.Close(); }
28  errno_t GetErrorValue() const NLIB_NOEXCEPT { return m_ErrorValue; }
29 
30  public:
31  static bool Read(MpObject* obj, const char* csvtext) NLIB_NOEXCEPT NLIB_NONNULL;
33  InputStream* GetStream() NLIB_NOEXCEPT { return m_Reader.GetStream(); }
34  NLIB_SAFE_BOOL(CsvReader, GetErrorValue() == 0)
35 
36  private:
37  void SetError(errno_t e) NLIB_NOEXCEPT {
38  if (m_ErrorValue == 0) m_ErrorValue = e;
39  }
40 
41  private:
42  errno_t m_ErrorValue;
43  TextReader m_Reader;
45 };
46 
47 } // namespace msgpack
48 NLIB_NAMESPACE_END
49 
50 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
51 #undef NLIB_VIS_PUBLIC
52 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
53 #endif
54 
55 #endif // INCLUDE_NN_NLIB_MSGPACK_CSVREADER_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
CSV parser. Reads and parses the CSV string from the stream.
Definition: CsvReader.h:18
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
Definition: Platform_unix.h:66
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:126
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
Definition: Config.h:141
Defines the base class for input streams.
Object created when MessagePack or JSON is read.
Definition: MpObject.h:83
errno_t GetErrorValue() const noexcept
Gets the error that occurred.
Definition: CsvReader.h:28
InputStream * GetStream() noexcept
Gets the base stream specified in Init.
Definition: CsvReader.h:33
Defines the class for reading text from streams.
The class for reading text from streams.
Definition: TextReader.h:20
Object created when MessagePack, JSON, or CSV is read.
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:15
~CsvReader() noexcept
Destructor.
Definition: CsvReader.h:25
CsvReader() noexcept
Instantiates the object with default parameters (default constructor).
Definition: CsvReader.h:24
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
bool Read(BinaryReader *r, T *x)
You can read to user-defined class objects by specializing this function template.
Definition: BinaryReader.h:158
bool Close() noexcept
Closes CsvReader.
Definition: CsvReader.h:27
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24