Taskolib  1.3.3
VariableName.h
Go to the documentation of this file.
1 
24 // SPDX-License-Identifier: LGPL-2.1-or-later
25 
26 #ifndef TASKOLIB_VARIABLENAME_H_
27 #define TASKOLIB_VARIABLENAME_H_
28 
29 #include <functional>
30 #include <string>
31 #include <gul14/string_view.h>
32 
33 namespace task {
34 
44 {
45 public:
46  using SizeType = std::string::size_type;
47  using size_type = std::string::size_type;
48 
57  VariableName(const char* name);
58 
64  explicit VariableName(const std::string& name);
65  explicit VariableName(std::string&& name);
66 
68  SizeType length() const noexcept { return name_.size(); }
69 
71  friend bool operator==(const VariableName& a, const VariableName& b) noexcept
72  {
73  return a.string() == b.string();
74  }
75 
77  friend bool operator!=(const VariableName& a, const VariableName& b) noexcept
78  {
79  return a.string() != b.string();
80  }
81 
83  friend bool operator<(const VariableName& a, const VariableName& b) noexcept
84  {
85  return a.string() < b.string();
86  }
87 
89  friend bool operator>(const VariableName& a, const VariableName& b) noexcept
90  {
91  return a.string() > b.string();
92  }
93 
98  friend bool operator<=(const VariableName& a, const VariableName& b) noexcept
99  {
100  return a.string() <= b.string();
101  }
102 
107  friend bool operator>=(const VariableName& a, const VariableName& b) noexcept
108  {
109  return a.string() >= b.string();
110  }
111 
117  VariableName& operator+=(gul14::string_view suffix);
118 
120  friend std::string& operator+=(std::string& lhs, const VariableName& rhs)
121  {
122  lhs += rhs.string();
123  return lhs;
124  }
125 
127  friend std::string operator+(const VariableName& lhs, gul14::string_view rhs)
128  {
129  return lhs.string() + rhs;
130  }
131 
133  friend std::string operator+(gul14::string_view lhs, const VariableName& rhs)
134  {
135  return lhs + rhs.string();
136  }
137 
139  explicit operator const std::string&() const { return name_; }
140 
142  SizeType size() const noexcept { return name_.size(); }
143 
145  const std::string& string() const noexcept { return name_; }
146 
147 private:
148  std::string name_;
149 };
150 
151 } // namespace task
152 
153 
154 namespace std {
155 
157 template<>
158 struct hash<task::VariableName>
159 {
160  std::size_t operator()(const task::VariableName& name) const noexcept
161  {
162  return std::hash<std::string>{}(name.string());
163  }
164 };
165 
166 } // namespace std
167 
168 #endif
A variable name is a string with limited functionality and some limitations on the allowed characters...
Definition: VariableName.h:44
friend bool operator==(const VariableName &a, const VariableName &b) noexcept
Determine if two variable names are identical.
Definition: VariableName.h:71
friend std::string operator+(gul14::string_view lhs, const VariableName &rhs)
Concatenate a string_view and a VariableName.
Definition: VariableName.h:133
friend std::string & operator+=(std::string &lhs, const VariableName &rhs)
Append a VariableName to a std::string.
Definition: VariableName.h:120
friend bool operator<(const VariableName &a, const VariableName &b) noexcept
Determine if the left variable name is lexicographically less than the right one.
Definition: VariableName.h:83
VariableName & operator+=(gul14::string_view suffix)
Append a suffix to a VariableName.
Definition: VariableName.cc:81
VariableName(const char *name)
Construct a variable name from a C string.
Definition: VariableName.cc:60
friend bool operator!=(const VariableName &a, const VariableName &b) noexcept
Determine if two variable names differ.
Definition: VariableName.h:77
const std::string & string() const noexcept
Return a const reference to the internal string member.
Definition: VariableName.h:145
SizeType length() const noexcept
Return the length of the variable name string.
Definition: VariableName.h:68
friend bool operator>(const VariableName &a, const VariableName &b) noexcept
Determine if the left variable name is lexicographically greater than the right one.
Definition: VariableName.h:89
std::string name_
Definition: VariableName.h:148
std::string::size_type SizeType
Definition: VariableName.h:46
friend bool operator<=(const VariableName &a, const VariableName &b) noexcept
Determine if the left variable name is lexicographically less than or equal to the right one.
Definition: VariableName.h:98
SizeType size() const noexcept
Return the length of the variable name string.
Definition: VariableName.h:142
friend std::string operator+(const VariableName &lhs, gul14::string_view rhs)
Concatenate a VariableName and a string_view.
Definition: VariableName.h:127
friend bool operator>=(const VariableName &a, const VariableName &b) noexcept
Determine if the left variable name is lexicographically greater than or equal to the right one.
Definition: VariableName.h:107
std::string::size_type size_type
Definition: VariableName.h:47
Definition: VariableName.h:154
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33
std::size_t operator()(const task::VariableName &name) const noexcept
Definition: VariableName.h:160