nlib
UriTemplate.h
[詳解]
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_URITEMPLATE_H_
17 #define INCLUDE_NN_NLIB_URITEMPLATE_H_
18 
19 #include <utility>
20 
21 #include "nn/nlib/Uri.h"
22 #include "nn/nlib/Swap.h"
23 
24 NLIB_NAMESPACE_BEGIN
25 
26 class OutputStream;
27 
28 // See RFC6570: https://tools.ietf.org/html/rfc6570
30  public:
31  static bool IsUriTemplate(const char* first, const char* last) NLIB_NOEXCEPT;
32  static bool IsUriTemplate(const char* str) NLIB_NOEXCEPT {
33  return IsUriTemplate(str, str + nlib_strlen(str));
34  }
35  NLIB_CEXPR UriTemplate() NLIB_NOEXCEPT : prv_(nullptr) {}
36  ~UriTemplate() NLIB_NOEXCEPT { Reset(); }
37  NLIB_DEFMOVE_PIMPL(UriTemplate);
38  NLIB_DEPRECATED void swap(UriTemplate& rhs) NLIB_NOEXCEPT {
39  using std::swap;
40  swap(prv_, rhs.prv_);
41  }
42  void Reset() NLIB_NOEXCEPT;
43  errno_t SetTemplate(const char* first, const char* last) NLIB_NOEXCEPT;
44  errno_t SetTemplate(const char* str) NLIB_NOEXCEPT {
45  return SetTemplate(str, str + nlib_strlen(str));
46  }
47  errno_t SetParameter(const char* param, const char* value) NLIB_NOEXCEPT;
48  void ResetParameter() NLIB_NOEXCEPT;
49  errno_t Resolve(size_t* written, char* str, size_t n) const NLIB_NOEXCEPT;
50  template<size_t N>
51  errno_t Resolve(size_t* written, char (&str)[N]) const NLIB_NOEXCEPT {
52  return Resolve(written, str, N);
53  }
54  std::pair<errno_t, size_t> Resolve(char* str, size_t n) const NLIB_NOEXCEPT {
55  size_t written;
56  errno_t e = Resolve(&written, str, n);
57  return std::make_pair(e, written);
58  }
59  template<size_t N>
60  std::pair<errno_t, size_t> Resolve(char (&str)[N]) const NLIB_NOEXCEPT {
61  size_t written;
62  errno_t e = Resolve(&written, str, N);
63  return std::make_pair(e, written);
64  }
65 
66  private:
67  struct UriTemplatePrivate;
68  mutable UriTemplatePrivate* prv_;
70 };
71 
72 NLIB_NAMESPACE_END
73 #ifndef __cpp_rvalue_references
74 NLIB_DEFINE_STD_SWAP(::nlib_ns::UriTemplate)
75 #endif
76 #endif // INCLUDE_NN_NLIB_URITEMPLATE_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
#define NLIB_DEPRECATED
関数等がdeprecatedになったことを示します。
Definition: Config.h:109
errno_t SetTemplate(const char *str) noexcept
SetTemplate(str, nlib_strlen(str))を返します。
Definition: UriTemplate.h:44
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
URI Template(RFC 6570, Level3)をサポートします。
Definition: UriTemplate.h:29
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
URIを扱うためのクラスを定義しています。
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
errno_t Resolve(size_t *written, char(&str)[N]) const noexcept
Resolve(written, str, N)を呼び出します。
Definition: UriTemplate.h:51
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
static bool IsUriTemplate(const char *str) noexcept
IsUriTemplate(str, str + strlen(str))を返します。
Definition: UriTemplate.h:32
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37