47 tgTags(
const std::string& space_separated_tags)
49 append(space_separated_tags);
52 bool contains(
const std::string& space_separated_tags)
const
54 const std::deque<std::string> tags = splitTags(space_separated_tags);
55 return contains(tags);
58 bool contains(
const tgTags& tags)
const
60 return contains(tags.getTags());
63 bool containsAny(
const std::string& space_separated_tags)
65 std::deque<std::string> tags = splitTags(space_separated_tags);
66 return containsAny(tags);
69 bool containsAny(
const tgTags& tags)
71 return containsAny(tags.getTags());
74 void append(
const std::string& space_separated_tags)
76 append(splitTags(space_separated_tags));
79 void append(
const tgTags& tags)
81 append(tags.getTags());
84 void prepend(
const std::string& space_separated_tags)
86 prepend(splitTags(space_separated_tags));
89 void prepend(
const tgTags& tags)
91 prepend(tags.getTags());
94 void remove(
const std::string& space_separated_tags)
96 remove(splitTags(space_separated_tags));
99 void remove(
const tgTags& tags)
101 remove(tags.getTags());
104 const int size()
const
106 return m_tags.size();
109 const bool empty()
const
111 return m_tags.empty();
114 static std::deque<std::string> splitTags(
const std::string &s,
char delim =
' ') {
115 std::deque<std::string> elems;
116 std::stringstream ss(s);
118 while (std::getline(ss, item, delim)) {
120 elems.push_back(item);
129 static std::deque<std::string>
splitTags(
const std::deque<std::string> &s,
131 std::deque<std::string> result;
132 for(
int i = 0; i < s.size(); i++) {
133 std::deque<std::string> spl = splitTags(s[i]);
134 for(
int j = 0; j < spl.size(); j++) {
135 result.push_back(spl[j]);
141 std::string joinTags(std::string delim =
"_") {
142 std::stringstream ss;
143 for(
int i = 0; i < m_tags.size(); i++) {
160 std::stringstream ss;
161 ss << atoi(s.c_str());
168 bool isValid(std::string tag)
178 if(tag.find(
' ') != std::string::npos) {
189 std::deque<std::string>& getTags()
194 const std::deque<std::string>& getTags()
const
202 const std::set<std::string>
asSet()
const
204 return std::set<std::string>(m_tags.begin(), m_tags.end());
217 const std::string&
operator[](
int key)
const {
231 const std::deque<std::string>& other = rhs.getTags();
232 m_tags.insert(m_tags.end(), other.begin(), other.end());
242 void appendOne(std::string tag) {
244 throw tgTagException(
"Invalid tag '" + tag +
"' - tags must be alphanumeric and may not be castable to int.");
246 if(!containsOne(tag)) {
247 m_tags.push_back(tag);
251 void append(
const std::deque<std::string>& tags)
253 for(
int i = 0; i < tags.size(); i++) {
258 void prependOne(std::string tag) {
259 if(isValid(tag) && !containsOne(tag)) {
260 m_tags.push_front(tag);
264 void prepend(
const std::deque<std::string>& tags)
266 for(
int i = 0; i < tags.size(); i++) {
271 bool contains(
const std::deque<std::string>& tags)
const {
272 for(
int i = 0; i < tags.size(); i++) {
273 if(!containsOne(tags[i]))
279 bool containsAny(
const std::deque<std::string>& tags)
const {
280 for(
int i = 0; i < tags.size(); i++) {
281 if(containsOne(tags[i]))
290 bool containsOne(std::string tag)
const {
291 return (std::find(m_tags.begin(), m_tags.end(), tag) != m_tags.end());
294 void removeOne(std::string tag) {
295 m_tags.erase(std::remove(m_tags.begin(), m_tags.end(), tag), m_tags.end());
298 void remove(std::deque<std::string> tags) {
299 for(
int i = 0; i < tags.size(); i++) {
304 std::deque<std::string> m_tags;
317 const std::deque<std::string>& t = tags.getTags();
318 for(
size_t i = 0; i < t.size(); ++i)
334 inline bool operator> (
const tgTags& lhs,
const tgTags& rhs){
return rhs < lhs;}
335 inline bool operator<=(
const tgTags& lhs,
const tgTags& rhs){
return !(lhs > rhs);}
336 inline bool operator>=(
const tgTags& lhs,
const tgTags& rhs){
return !(lhs < rhs);}
Extension of std::exception for use within the library.