RSB  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PredicateConverterList.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is part of the RSB project
4  *
5  * Copyright (C) 2011 Jan Moringen <jmoringe@techfak.uni-bielefeld.de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <algorithm>
30 #include <iterator>
31 
32 #include <boost/shared_ptr.hpp>
33 
35 
36 namespace rsb {
37 namespace converter {
38 
48 class ConverterPredicate: public rsc::runtime::Printable {
49 public:
50  virtual ~ConverterPredicate() {
51  }
52 
62  virtual bool match(const std::string& key) const = 0;
63 };
64 
65 typedef boost::shared_ptr<ConverterPredicate> ConverterPredicatePtr;
66 
74 public:
75  bool match(const std::string& /*key*/) const {
76  return true;
77  }
78 
79  std::string getClassName() const {
80  return "AlwaysApplicable";
81  }
82 
83  void printContents(std::ostream& /*stream*/) const {
84  }
85 };
86 
97 template <typename WireType>
99 public:
101  typedef std::list< std::pair<ConverterPredicatePtr, ConverterPtr> > ConverterList;
102 
113  template <typename ForwardIterator>
114  PredicateConverterList(ForwardIterator begin, ForwardIterator end) {
115  std::copy(begin, end, std::inserter(this->converters,
116  this->converters.begin()));
117  }
118 
119  ConverterPtr getConverter(const std::string& key) const {
120  for (typename ConverterList::const_iterator it = this->converters.begin();
121  it != this->converters.end(); ++it) {
122  if (it->first->match(key)) {
123  return it->second;
124  }
125  }
126  return ConverterPtr();
127  }
128 
129  std::string getClassName() const {
130  return "PredicateConverterList";
131  }
132 
133  void printContents(std::ostream& stream) const {
134  stream << "converters = " << this->converters;
135  }
136 private:
138 };
139 
140 }
141 }
Implementation of this interface perform mappings of one of the followings forms: ...
ConverterPtr getConverter(const std::string &key) const
Tries to look up the converter designator by key.
void printContents(std::ostream &stream) const
void printContents(std::ostream &) const
Objects of this class are used to perform Converter selection via a chain-of-responsibility strategy...
PredicateConverterList(ForwardIterator begin, ForwardIterator end)
Construct a new PredicateConverterList object, initializing its Converter to the elements of the iter...
virtual bool match(const std::string &key) const =0
Return true if the Converter associated to this predicate should be selected for key.
Implementations of this interface can be used to perform Converter selection based on predicate evalu...
A predicate that unconditionally causes its associated Converter to be selected.
bool match(const std::string &) const
Return true if the Converter associated to this predicate should be selected for key.
std::list< std::pair< ConverterPredicatePtr, ConverterPtr > > ConverterList
boost::shared_ptr< ConverterPredicate > ConverterPredicatePtr
ConverterSelectionStrategy< WireType >::ConverterPtr ConverterPtr