NTRT Simulator  v1.1
 All Classes Namespaces 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 
26 #ifndef TG_TAGGABLE_H
27 #define TG_TAGGABLE_H
28 
29 #include <sstream>
30 #include <vector>
31 #include <set>
32 #include <assert.h>
33 #include <cstdio>
34 #include <stdlib.h> //atoi
35 #include <algorithm>
36 
37 #include "tgTags.h"
38 
40 {
41 public:
42 
43  tgTaggable() {}
44 
45  tgTaggable(const std::string& space_separated_tags) : m_tags(space_separated_tags)
46  {}
47 
48  tgTaggable(tgTags tags) : m_tags(tags)
49  {}
50 
51  ~tgTaggable() {}
52 
53  void addTags(const std::string& space_separated_tags)
54  {
55  m_tags.append(space_separated_tags);
56  }
57 
58  void addTags(const tgTags& tags)
59  {
60  m_tags.append(tags);
61  }
62 
63  bool hasTag(const std::string tag) const
64  {
65  return m_tags.contains(tag);
66  }
67 
68 
69  bool hasAllTags(std::string tags)
70  {
71  return m_tags.contains(tags);
72  }
73 
74  bool hasAnyTags(const std::string tags)
75  {
76  return m_tags.containsAny(tags);
77  }
78 
79  bool hasNoTags()
80  {
81  return m_tags.empty();
82  }
83 
84  tgTags& getTags()
85  {
86  return m_tags;
87  }
88 
89  const tgTags& getTags() const
90  {
91  return m_tags;
92  }
93 
94  void setTags(tgTags tags)
95  {
96  m_tags = tags;
97  }
98 
99  // @todo: remove this -- tgTags does this...
100  std::string getTagStr(std::string delim = " ") const {
101  if(m_tags.empty())
102  return "";
103  std::ostringstream result;
104  result << m_tags[0];
105  for(int i = 1; i < m_tags.size(); i++) {
106  result << delim << m_tags[i];
107  }
108  return result.str();
109  }
110 
111 private:
112 
113  tgTags m_tags;
114 };
115 
116 #endif
Contains the definition of class tgTags.
Definition: tgTags.h:44