nlib
CsvReader.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_MSGPACK_CSVREADER_H_
17 #define INCLUDE_NN_NLIB_MSGPACK_CSVREADER_H_
18 
19 #include <utility>
20 
22 #include "nn/nlib/Swap.h"
23 
24 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
25 #undef NLIB_VIS_PUBLIC
26 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
27 #endif
28 
29 NLIB_NAMESPACE_BEGIN
30 class InputStream;
31 namespace msgpack {
32 
34  public:
35  // In Conformance with RFC4180(https://www.ietf.org/rfc/rfc4180.txt).
36  // except that
37  // pass UTF-8, the UTF-8 string is checked validity.
38  // pass CR, LF, CRLF as a new line.
39  NLIB_CEXPR CsvReader() NLIB_NOEXCEPT : prv_(nullptr), error_(0) {}
40  ~CsvReader() NLIB_NOEXCEPT { Reset(); }
41  NLIB_DEFMOVE_PIMPL(CsvReader);
42  NLIB_DEPRECATED void swap(CsvReader& rhs) NLIB_NOEXCEPT {
43  using std::swap;
44  swap(prv_, rhs.prv_);
45  }
46  void Reset() NLIB_NOEXCEPT;
47  errno_t Init() NLIB_NOEXCEPT;
48  errno_t Open(InputStream* stream) NLIB_NOEXCEPT;
49  bool Close() NLIB_NOEXCEPT;
50  errno_t GetErrorValue() const NLIB_NOEXCEPT { return error_; }
51 
52  public:
53  static bool Read(MpObject* obj, const nlib_utf8_t* csvtext) NLIB_NOEXCEPT NLIB_NONNULL;
54 #ifdef __cpp_rvalue_references
55  static std::pair<bool, MpObject>
56  Read(const nlib_utf8_t* csvtext) NLIB_NOEXCEPT {
57  std::pair<bool, MpObject> rval;
58  rval.first = Read(&rval.second, csvtext);
59  return rval;
60  }
61 #endif
62  bool Read(MpObject* obj) NLIB_NOEXCEPT NLIB_NONNULL;
63  InputStream* GetStream() NLIB_NOEXCEPT;
64  NLIB_SAFE_BOOL(CsvReader, error_ == 0)
65 
66  private:
67  void SetError(errno_t e) NLIB_NOEXCEPT {
68  if (error_ == 0) error_ = e;
69  }
70 
71  private:
72  struct CsvReaderPrivate;
73  CsvReaderPrivate* prv_;
74  errno_t error_;
76 };
77 
78 } // namespace msgpack
79 NLIB_NAMESPACE_END
80 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::CsvReader)
81 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
82 #undef NLIB_VIS_PUBLIC
83 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
84 #endif
85 
86 #endif // INCLUDE_NN_NLIB_MSGPACK_CSVREADER_H_
CSV parser. Reads and parses the CSV string from the stream.
Definition: CsvReader.h:33
#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:179
#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:194
#define NLIB_DEPRECATED
Indicates that a function or something has been deprecated.
Definition: Config.h:109
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
Object created when MessagePack or JSON is read.
Definition: MpObject.h:95
Object created when MessagePack, JSON, or CSV is read.
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:29
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
~CsvReader() noexcept
Destructor.
Definition: CsvReader.h:40
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
constexpr CsvReader() noexcept
Instantiates the object with default parameters (default constructor).
Definition: CsvReader.h:39
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:245
bool Read(BinaryReader *r, T *x)
You can read to user-defined class objects by specializing this function template.
Definition: BinaryReader.h:172
errno_t GetErrorValue() const noexcept
Gets the error that occurred.
Definition: CsvReader.h:50
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:308
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37