Taskolib  1.3.3
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>
30 
31 #include <gul14/string_view.h>
32 
33 namespace task {
34 
43 class Tag
44 {
45 public:
47  static constexpr std::size_t max_length = 32;
48 
50  static const gul14::string_view valid_characters;
51 
52 
54  Tag() : name_{ "-" }
55  {}
56 
65  explicit Tag(gul14::string_view name);
66 
68  friend bool operator==(const Tag& a, const Tag& b)
69  {
70  return a.name_ == b.name_;
71  }
72 
74  friend bool operator!=(const Tag& a, const Tag& b)
75  {
76  return a.name_ != b.name_;
77  }
78 
80  friend bool operator<(const Tag& a, const Tag& b)
81  {
82  return a.name_ < b.name_;
83  }
84 
89  friend bool operator<=(const Tag& a, const Tag& b)
90  {
91  return a.name_ <= b.name_;
92  }
93 
95  friend bool operator>(const Tag& a, const Tag& b)
96  {
97  return a.name_ > b.name_;
98  }
99 
104  friend bool operator>=(const Tag& a, const Tag& b)
105  {
106  return a.name_ >= b.name_;
107  }
108 
110  friend std::string operator+(const std::string& lhs, const Tag& rhs)
111  {
112  return lhs + rhs.name_;
113  }
114 
116  friend std::string operator+(const Tag& lhs, const std::string& rhs)
117  {
118  return lhs.name_ + rhs;
119  }
120 
122  friend std::string& operator+=(std::string& lhs, const Tag& rhs)
123  {
124  lhs += rhs.name_;
125  return lhs;
126  }
127 
129  friend std::ostream& operator<<(std::ostream& stream, const Tag& tag);
130 
132  std::size_t size() const noexcept { return name_.size(); }
133 
135  const std::string& string() const noexcept { return name_; }
136 
137 private:
138  std::string name_;
139 
145  static gul14::string_view check_validity(gul14::string_view);
146 };
147 
148 } // namespace task
149 
150 #endif
A tag used for categorizing sequences.
Definition: Tag.h:44
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:122
static const gul14::string_view valid_characters
A string containing all of the valid characters for a tag name.
Definition: Tag.h:50
std::size_t size() const noexcept
Return the length of the tag name.
Definition: Tag.h:132
static constexpr std::size_t max_length
Maximum number of bytes of a tag name.
Definition: Tag.h:47
friend bool operator!=(const Tag &a, const Tag &b)
Determine if two tags are different.
Definition: Tag.h:74
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:104
friend std::string operator+(const std::string &lhs, const Tag &rhs)
Concatenate a string and a tag.
Definition: Tag.h:110
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:89
friend bool operator==(const Tag &a, const Tag &b)
Determine if two tags are equal.
Definition: Tag.h:68
const std::string & string() const noexcept
Return the name of the tag as a string.
Definition: Tag.h:135
std::string name_
Definition: Tag.h:138
Tag()
Default-construct a tag with the name "-".
Definition: Tag.h:54
friend bool operator>(const Tag &a, const Tag &b)
Determine if tag a comes after tag b in a lexicographical comparison.
Definition: Tag.h:95
friend std::string operator+(const Tag &lhs, const std::string &rhs)
Concatenate a tag and a string.
Definition: Tag.h:116
friend bool operator<(const Tag &a, const Tag &b)
Determine if tag a comes before tag b in a lexicographical comparison.
Definition: Tag.h:80
static gul14::string_view check_validity(gul14::string_view)
Throw an exception if the given string violates the length or character constraints of a tag name; ot...
Definition: Tag.cc:42
Namespace task contains all Taskolib functions and classes.
Definition: CommChannel.h:33