nlib
UriTemplate.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_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)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:179
#define NLIB_DEPRECATED
Indicates that a function or something has been deprecated.
Definition: Config.h:109
errno_t SetTemplate(const char *str) noexcept
Returns SetTemplate(str, nlib_strlen(str)).
Definition: UriTemplate.h:44
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
The class that supports URI Template (RFC 6570, Level 3).
Definition: UriTemplate.h:29
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
Defines the class for handling URIs.
size_t nlib_strlen(const char *s)
Internally calls strlen(). In some cases, it may operate as an independent implementation.
errno_t Resolve(size_t *written, char(&str)[N]) const noexcept
Calls Resolve(written, str, N).
Definition: UriTemplate.h:51
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:245
static bool IsUriTemplate(const char *str) noexcept
Returns IsUriTemplate(str, str + strlen(str)).
Definition: UriTemplate.h:32
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37