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