NTRT Simulator
 All Classes Files Functions Variables Typedefs Friends Pages
tgTaggable.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2012, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The NASA Tensegrity Robotics Toolkit (NTRT) v1 platform is licensed
7  * under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0.
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15  * either express or implied. See the License for the specific language
16  * governing permissions and limitations under the License.
17 */
18 
25 #ifndef TG_TAGGABLE_H
26 #define TG_TAGGABLE_H
27 
28 #include <sstream>
29 #include <vector>
30 #include <set>
31 #include <assert.h>
32 #include <cstdio>
33 #include <stdlib.h> //atoi
34 #include <algorithm>
35 
36 #include "tgTags.h"
37 
39 {
40 public:
41 
42  tgTaggable() {}
43 
44  tgTaggable(const std::string& space_separated_tags) : m_tags(space_separated_tags)
45  {}
46 
47  tgTaggable(tgTags tags) : m_tags(tags)
48  {}
49 
50  ~tgTaggable() {}
51 
52  void addTags(const std::string& space_separated_tags)
53  {
54  m_tags.append(space_separated_tags);
55  }
56 
57  void addTags(const tgTags& tags)
58  {
59  m_tags.append(tags);
60  }
61 
62  bool hasTag(const std::string tag) const
63  {
64  return m_tags.contains(tag);
65  }
66 
67 
68  bool hasAllTags(std::string tags)
69  {
70  return m_tags.contains(tags);
71  }
72 
73  bool hasAnyTags(const std::string tags)
74  {
75  return m_tags.containsAny(tags);
76  }
77 
78  bool hasNoTags()
79  {
80  return m_tags.empty();
81  }
82 
83  tgTags& getTags()
84  {
85  return m_tags;
86  }
87 
88  const tgTags& getTags() const
89  {
90  return m_tags;
91  }
92 
93  void setTags(tgTags tags)
94  {
95  m_tags = tags;
96  }
97 
98  // @todo: remove this -- tgTags does this...
99  std::string getTagStr(std::string delim = " ") const {
100  if(m_tags.empty())
101  return "";
102  std::ostringstream result;
103  result << m_tags[0];
104  for(int i = 1; i < m_tags.size(); i++) {
105  result << delim << m_tags[i];
106  }
107  return result.str();
108  }
109 
110 private:
111 
112  tgTags m_tags;
113 };
114 
115 #endif
Contains the definition of class tgTags $Id$.
Definition: tgTags.h:43