NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgTagSearch.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_TAG_SEARCH_H
27 #define TG_TAG_SEARCH_H
28 
29 #include <string>
30 
31 #include "tgTags.h"
32 #include "tgTaggable.h"
33 
34 /* @todo: Implement more advanced search capability
35 
36  Currently, tag searches just matches all tags, so something like
37  tgTagSearch("a b").matches(tgTags("a b c")) is true.
38 
39  Plans: search operators like 'or' and 'not', for instance
40  - tgTagSearch("a -b") would match tgTags("a c") but not tgTags("a b")
41  - tgTagSearch("a b|c") would match tgTags("a b") and tgTags("a c")
42  but not tgTags("a d")
43 */
44 
49 {
50 public:
51 
52  tgTagSearch() {}
53 
54  tgTagSearch(std::string search_string) : m_search(search_string)
55  {}
56 
57  virtual ~tgTagSearch() {}
58 
62  const bool matches(const tgTags& tags) const
63  {
64  // Simple for now, just check that the tags contain the tags in the
65  // search
66  return tags.contains(m_search);
67  }
68 
69  const bool matches(const tgTaggable& taggable) const
70  {
71  return matches(taggable.getTags());
72  }
73 
78  bool matches(const tgTags& parentTags, const tgTags& tags)
79  {
80  // @todo: make sure this works correctly...
81  tgTags s(parentTags);
82  s.append(tags);
83  return matches(s);
84  }
85 
89  void remove(const tgTags& tags)
90  {
91  tgTags s(tags);
92  m_search.remove(tags);
93  }
94 
95 private:
96 
97  // @todo: change this to a parsed representation of the and/or/not setup
98  tgTags m_search;
99 
100 };
101 
102 
103 #endif
bool matches(const tgTags &parentTags, const tgTags &tags)
Definition: tgTagSearch.h:78
Contains the definition of class tgTags.
const bool matches(const tgTags &tags) const
Definition: tgTagSearch.h:62
Contains the definition of class tgTaggable.
Definition: tgTags.h:44