Taskolib  1.4.4
Tag.h
Go to the documentation of this file.
1 
23 // SPDX-License-Identifier: LGPL-2.1-or-later
24 
25 #ifndef TASKOLIB_TAG_H_
26 #define TASKOLIB_TAG_H_
27 
28 #include <iosfwd>
29 #include <string_view>
30 #include <string>
31 
32 namespace task {
33 
42 class Tag
43 {
44 public:
46  static constexpr std::size_t max_length = 32;
47 
49  static const std::string_view valid_characters;
50 
51 
53  Tag() : name_{ "-" }
54  {}
55 
64  explicit Tag(std::string_view name);
65 
67  friend bool operator==(const Tag& a, const Tag& b)
68  {
69  return a.name_ == b.name_;
70  }
71 
73  friend bool operator!=(const Tag& a, const Tag& b)
74  {
75  return a.name_ != b.name_;
76  }
77 
79  friend bool operator<(const Tag& a, const Tag& b)
80  {
81  return a.name_ < b.name_;
82  }
83 
88  friend bool operator<=(const Tag& a, const Tag& b)
89  {
90  return a.name_ <= b.name_;
91  }
92 
94  friend bool operator>(const Tag& a, const Tag& b)
95  {
96  return a.name_ > b.name_;
97  }
98 
103  friend bool operator>=(const Tag& a, const Tag& b)
104  {
105  return a.name_ >= b.name_;
106  }
107 
109  friend std::string operator+(const std::string& lhs, const Tag& rhs)
110  {
111  return lhs + rhs.name_;
112  }
113 
115  friend std::string operator+(const Tag& lhs, const std::string& rhs)
116  {
117  return lhs.name_ + rhs;
118  }
119 
121  friend std::string& operator+=(std::string& lhs, const Tag& rhs)
122  {
123  lhs += rhs.name_;
124  return lhs;
125  }
126 
128  friend std::ostream& operator<<(std::ostream& stream, const Tag& tag);
129 
131  std::size_t size() const noexcept { return name_.size(); }
132 
134  const std::string& string() const noexcept { return name_; }
135 
136 private:
137  std::string name_;
138 
144  static std::string_view check_validity(std::string_view);
145 };
146 
147 } // namespace task
148 
149 #endif
A tag used for categorizing sequences.
Definition: Tag.h:43
friend std::ostream & operator<<(std::ostream &stream, const Tag &tag)
Output the tag name to the given stream.
Definition: Tag.cc:61
friend std::string & operator+=(std::string &lhs, const Tag &rhs)
Concatenate a string and a tag.
Definition: Tag.h:121
std::size_t size() const noexcept
Return the length of the tag name.
Definition: Tag.h:131
static constexpr std::size_t max_length
Maximum number of bytes of a tag name.
Definition: Tag.h:46
friend bool operator!=(const Tag &a, const Tag &b)
Determine if two tags are different.
Definition: Tag.h:73
friend bool operator>=(const Tag &a, const Tag &b)
Determine if tag a comes after or is equal to tag b in a lexicographical comparison.
Definition: Tag.h:103
friend std::string operator+(const std::string &lhs, const Tag &rhs)
Concatenate a string and a tag.
Definition: Tag.h:109
friend bool operator<=(const Tag &a, const Tag &b)
Determine if tag a comes before or is equal to tag b in a lexicographical comparison.
Definition: Tag.h:88
friend bool operator==(const Tag &a, const Tag &b)
Determine if two tags are equal.
Definition: Tag.h:67
const std::string & string() const noexcept
Return the name of the tag as a string.
Definition: Tag.h:134
static std::string_view check_validity(std::string_view)
Throw an exception if the given string violates the length or character constraints of a tag name; ot...
Definition: Tag.cc:42
static const std::string_view valid_characters
A string containing all of the valid characters for a tag name.
Definition: Tag.h:49
std::string name_
Definition: Tag.h:137
Tag()
Default-construct a tag with the name "-".
Definition: Tag.h:53
friend bool operator>(const Tag &a, const Tag &b)
Determine if tag a comes after tag b in a lexicographical comparison.
Definition: Tag.h:94
friend std::string operator+(const Tag &lhs, const std::string &rhs)
Concatenate a tag and a string.
Definition: Tag.h:115
friend bool operator<(const Tag &a, const Tag &b)
Determine if tag a comes before tag b in a lexicographical comparison.
Definition: Tag.h:79
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33