48 tgTags(
const std::string& space_separated_tags)
50 append(space_separated_tags);
53 bool contains(
const std::string& space_separated_tags)
const
55 const std::deque<std::string> tags = splitTags(space_separated_tags);
56 return contains(tags);
59 bool contains(
const tgTags& tags)
const
61 return contains(tags.getTags());
64 bool containsAny(
const std::string& space_separated_tags)
66 std::deque<std::string> tags = splitTags(space_separated_tags);
67 return containsAny(tags);
70 bool containsAny(
const tgTags& tags)
72 return containsAny(tags.getTags());
75 void append(
const std::string& space_separated_tags)
77 append(splitTags(space_separated_tags));
80 void append(
const tgTags& tags)
82 append(tags.getTags());
85 void prepend(
const std::string& space_separated_tags)
87 prepend(splitTags(space_separated_tags));
90 void prepend(
const tgTags& tags)
92 prepend(tags.getTags());
95 void remove(
const std::string& space_separated_tags)
97 remove(splitTags(space_separated_tags));
100 void remove(
const tgTags& tags)
102 remove(tags.getTags());
105 const int size()
const
107 return m_tags.size();
110 const bool empty()
const
112 return m_tags.empty();
115 static std::deque<std::string> splitTags(
const std::string &s,
char delim =
' ') {
116 std::deque<std::string> elems;
117 std::stringstream ss(s);
119 while (std::getline(ss, item, delim)) {
121 elems.push_back(item);
130 static std::deque<std::string>
splitTags(
const std::deque<std::string> &s,
132 std::deque<std::string> result;
133 for(std::size_t i = 0; i < s.size(); i++) {
134 std::deque<std::string> spl = splitTags(s[i]);
135 for(std::size_t j = 0; j < spl.size(); j++) {
136 result.push_back(spl[j]);
142 std::string joinTags(std::string delim =
"_") {
143 std::stringstream ss;
144 for(std::size_t i = 0; i < m_tags.size(); i++) {
161 std::stringstream ss;
162 ss << atoi(s.c_str());
169 bool isValid(std::string tag)
179 if(tag.find(
' ') != std::string::npos) {
190 std::deque<std::string>& getTags()
195 const std::deque<std::string>& getTags()
const
203 const std::set<std::string>
asSet()
const
205 return std::set<std::string>(m_tags.begin(), m_tags.end());
218 const std::string&
operator[](
int key)
const {
232 const std::deque<std::string>& other = rhs.getTags();
233 m_tags.insert(m_tags.end(), other.begin(), other.end());
243 void appendOne(std::string tag) {
245 throw tgTagException(
"Invalid tag '" + tag +
"' - tags must be alphanumeric and may not be castable to int.");
247 if(!containsOne(tag)) {
248 m_tags.push_back(tag);
252 void append(
const std::deque<std::string>& tags)
254 for(std::size_t i = 0; i < tags.size(); i++) {
259 void prependOne(std::string tag) {
260 if(isValid(tag) && !containsOne(tag)) {
261 m_tags.push_front(tag);
265 void prepend(
const std::deque<std::string>& tags)
267 for(std::size_t i = 0; i < tags.size(); i++) {
272 bool contains(
const std::deque<std::string>& tags)
const {
273 for(std::size_t i = 0; i < tags.size(); i++) {
274 if(!containsOne(tags[i]))
280 bool containsAny(
const std::deque<std::string>& tags)
const {
281 for(std::size_t i = 0; i < tags.size(); i++) {
282 if(containsOne(tags[i]))
291 bool containsOne(std::string tag)
const {
292 return (std::find(m_tags.begin(), m_tags.end(), tag) != m_tags.end());
295 void removeOne(std::string tag) {
296 m_tags.erase(std::remove(m_tags.begin(), m_tags.end(), tag), m_tags.end());
299 void remove(std::deque<std::string> tags) {
300 for(std::size_t i = 0; i < tags.size(); i++) {
305 std::deque<std::string> m_tags;
318 const std::deque<std::string>& t = tags.getTags();
319 for(
size_t i = 0; i < t.size(); ++i)
336 inline std::string operator+(
tgTags tags, std::string str)
339 std::stringstream os;
344 inline std::string operator+(std::string str,
tgTags tags)
347 std::stringstream os;
358 std::stringstream os;
360 for(
size_t i = 0; i < tags.size(); i++) {
361 os <<
'"' << tags[i] <<
'"';
362 if(i != tags.size() - 1)
370 inline bool operator> (
const tgTags& lhs,
const tgTags& rhs){
return rhs < lhs;}
371 inline bool operator<=(
const tgTags& lhs,
const tgTags& rhs){
return !(lhs > rhs);}
372 inline bool operator>=(
const tgTags& lhs,
const tgTags& rhs){
return !(lhs < rhs);}
Extension of std::exception for use within the library.