source: src/Descriptors/DescriptorBase_impl.hpp

Candidate_v1.6.1
Last change on this file was 795c0f, checked in by Frederik Heber <heber@…>, 9 years ago

World::getAtoms() now has const versions as well.

  • this in turn required to adapt all AtomDescriptors and some fixes, e.g. predicate is now const member and works on const atom ptr.
  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * DescriptorBase_impl.hpp
3 *
4 * Created on: Mar 12, 2010
5 * Author: crueger
6 */
7
8#ifndef DESCRIPTORBASE_IMPL_HPP_
9#define DESCRIPTORBASE_IMPL_HPP_
10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
16
17#include "Descriptors/DescriptorBase.hpp"
18#include <utility>
19#include <boost/bind.hpp>
20
21template<class _Target,
22 class _Container>
23class DescriptorBase_impl{
24public:
25 typedef _Target Target;
26 typedef const _Target ConstTarget;
27 typedef std::vector<Target> TargetVec;
28 typedef std::vector<ConstTarget> ConstTargetVec;
29 typedef _Container Container;
30 typedef typename Container::value_type value_type;
31 typedef const typename Container::value_type const_value_type;
32 typedef typename Container::iterator iterator;
33 typedef typename Container::const_iterator const_iterator;
34
35 DescriptorBase_impl();
36 virtual ~DescriptorBase_impl();
37
38 virtual bool predicate(value_type)=0;
39
40 virtual Target find(Container&);
41 virtual ConstTarget find(Container&) const;
42 virtual TargetVec findAll(Container&);
43 virtual ConstTargetVec findAll(Container&) const;
44protected:
45 const _take<Target,value_type> take;
46};
47
48template<class _Target,
49 class _Container>
50DescriptorBase_impl<_Target,_Container>::DescriptorBase_impl(){}
51
52template<class _Target,
53 class _Container>
54DescriptorBase_impl<_Target,_Container>::~DescriptorBase_impl(){}
55
56template<class _Target,
57 class _Container>
58typename DescriptorBase_impl<_Target,_Container>::Target
59 DescriptorBase_impl<_Target,_Container>::find(DescriptorBase_impl<_Target,_Container>::Container& container){
60 iterator res = find_if(container.begin(),
61 container.end(),
62 boost::bind(&DescriptorBase_impl<_Target,_Container>::predicate,this,_1));
63 return (res!=container.end())?(take(*res)):0;
64}
65
66template<class _Target,
67 class _Container>
68typename DescriptorBase_impl<_Target,_Container>::ConstTarget
69 DescriptorBase_impl<_Target,_Container>::find(DescriptorBase_impl<_Target,_Container>::Container& container) const{
70 const_iterator res = find_if(container.begin(),
71 container.end(),
72 boost::bind(&DescriptorBase_impl<_Target,_Container>::predicate,this,_1));
73 return (res!=container.end())?(take(*res)):0;
74}
75
76template<class _Target,
77 class _Container>
78typename DescriptorBase_impl<_Target,_Container>::TargetVec
79 DescriptorBase_impl<_Target,_Container>::findAll(DescriptorBase_impl<_Target,_Container>::Container& container) {
80 TargetVec res;
81 iterator iter;
82 for(iter=container.begin();iter!=container.end();++iter) {
83 if(predicate(*iter)){
84 res.push_back(take(*iter));
85 }
86 }
87 return res;
88}
89
90template<class _Target,
91 class _Container>
92typename DescriptorBase_impl<_Target,_Container>::ConstTargetVec
93 DescriptorBase_impl<_Target,_Container>::findAll(DescriptorBase_impl<_Target,_Container>::Container& container) const {
94 ConstTargetVec res;
95 const_iterator iter;
96 for(iter=container.begin();iter!=container.end();++iter) {
97 if(predicate(*iter)){
98 res.push_back(take(*iter));
99 }
100 }
101 return res;
102}
103
104#endif /* DESCRIPTORBASE_IMPL_HPP_ */
Note: See TracBrowser for help on using the repository browser.