Support Class Library
A set of tools providing classes and utility
Version.h
Go to the documentation of this file.
1 #pragma once
2 #include <scl/macros.h>
3 #include <scl/utils/toString.h>
4 
5 namespace scl{
6  namespace http{
10  class Version{
11  public:
17 
22  using integral_type = unsigned char;
23 
24  protected:
30 
36 
42  explicit constexpr Version(const version_type& v, integral_type i) : str{v}, nb{i} {
43  }
44 
45  public:
50  constexpr explicit operator version_type() const{
51  return this->str;
52  }
53 
58  constexpr explicit operator integral_type() const{
59  return this->nb;
60  }
61 
62  constexpr bool operator==(const Version& other) const{
63  return this->nb == other.nb;
64  }
65 
66  constexpr bool operator<(const Version& other) const{
67  return this->nb < other.nb;
68  }
69 
70  constexpr bool operator<=(const Version& other) const{
71  return *this < other || *this == other;
72  }
73 
74  constexpr bool operator>(const Version& other) const{
75  return !(*this <= other);
76  }
77 
78  constexpr bool operator>=(const Version& other) const{
79  return !(*this < other);
80  }
81 
82  constexpr bool operator!=(const Version& other) const{
83  return !(*this == other);
84  }
85 
86  public:
88 
89 #define VERSION(name) static const Version name
94 #undef VERSION
95  };
96 
97 #define DEF_VERSION(name, str, nb) const Version Version::name{str, nb}
98  DEF_VERSION(V1_0, "1.0", 10);
99  DEF_VERSION(V1_1, "1.1", 11);
100  DEF_VERSION(V2_0, "2.0", 20);
101  DEF_VERSION(V3_0, "3.0", 30);
102 #undef DEF_VERSION
103  }
104 
105  namespace utils{
106  template <>
107  struct ToString<scl::http::Version, void>{
108  static const std::string HTTP;
109  std::string operator()(const scl::http::Version& v) const{
110  return HTTP + v.str;
111  }
112  };
113 
114  const std::string ToString<scl::http::Version, void>::HTTP = "HTTP";
115  }
116 }
std::string operator()(const scl::http::Version &v) const
Definition: Version.h:109
const char * version_type
The string representation type.
Definition: Version.h:16
const integral_type nb
The integer representation of the version.
Definition: Version.h:35
A pseudo enum class that describes the version of the HTTP Protocol.
Definition: Version.h:10
Global namespace of the SCL.
Definition: alias.hpp:3
constexpr bool operator!=(const Version &other) const
Definition: Version.h:82
static const Version V1_1
Definition: Version.h:91
constexpr bool operator==(const Version &other) const
Definition: Version.h:62
#define VERSION(name)
Definition: Version.h:89
const version_type str
The string representation of the version.
Definition: Version.h:29
constexpr bool operator<(const Version &other) const
Definition: Version.h:66
constexpr Version(const version_type &v, integral_type i)
Constrct a version from its string and integer representation.
Definition: Version.h:42
constexpr bool operator>=(const Version &other) const
Definition: Version.h:78
static const Version V2_0
Definition: Version.h:92
static const Version V1_0
Definition: Version.h:90
constexpr bool operator<=(const Version &other) const
Definition: Version.h:70
constexpr bool operator>(const Version &other) const
Definition: Version.h:74
static const Version V3_0
Definition: Version.h:93
unsigned char integral_type
The integer representation type.
Definition: Version.h:22
#define stringLiteral
Definition: macros.h:4
#define DEF_VERSION(name, str, nb)
Definition: Version.h:97