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  void Reset() NLIB_NOEXCEPT;
39  errno_t SetTemplate(const char* first, const char* last) NLIB_NOEXCEPT;
40  errno_t SetTemplate(const char* str) NLIB_NOEXCEPT {
41  return SetTemplate(str, str + nlib_strlen(str));
42  }
43  errno_t SetParameter(const char* param, const char* value) NLIB_NOEXCEPT;
44  void ResetParameter() NLIB_NOEXCEPT;
45  errno_t Resolve(size_t* written, char* str, size_t n) const NLIB_NOEXCEPT;
46  template<size_t N>
47  errno_t Resolve(size_t* written, char (&str)[N]) const NLIB_NOEXCEPT {
48  return Resolve(written, str, N);
49  }
50  std::pair<errno_t, size_t> Resolve(char* str, size_t n) const NLIB_NOEXCEPT {
51  size_t written;
52  errno_t e = Resolve(&written, str, n);
53  return std::make_pair(e, written);
54  }
55  template<size_t N>
56  std::pair<errno_t, size_t> Resolve(char (&str)[N]) const NLIB_NOEXCEPT {
57  size_t written;
58  errno_t e = Resolve(&written, str, N);
59  return std::make_pair(e, written);
60  }
61 
62  private:
63  struct UriTemplatePrivate;
64  mutable UriTemplatePrivate* prv_;
66 };
67 
68 NLIB_NAMESPACE_END
69 #ifndef __cpp_rvalue_references
70 NLIB_DEFINE_STD_SWAP(::nlib_ns::UriTemplate)
71 #endif
72 #endif // INCLUDE_NN_NLIB_URITEMPLATE_H_
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:183
~UriTemplate() noexcept
デストラクタです。
Definition: UriTemplate.h:36
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
URI Template(RFC 6570, Level3)をサポートします。
Definition: UriTemplate.h:29
std::pair< errno_t, size_t > Resolve(char *str, size_t n) const noexcept
URIテンプレートに値を代入した文字列をstrに書き込みます。
Definition: UriTemplate.h:50
constexpr UriTemplate() noexcept
デフォルトコンストラクタです。
Definition: UriTemplate.h:35
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:109
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:111
URIを扱うためのクラスを定義しています。
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
std::pair< errno_t, size_t > Resolve(char(&str)[N]) const noexcept
上記関数のテンプレートオーバーロードです。
Definition: UriTemplate.h:56
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:250
static bool IsUriTemplate(const char *str) noexcept
上記関数の引数省略版で、ヌル終端する文字列を受け取ります。
Definition: UriTemplate.h:32
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37