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 |
|
---|
21 | template<class _Target,
|
---|
22 | class _Container>
|
---|
23 | class DescriptorBase_impl{
|
---|
24 | public:
|
---|
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;
|
---|
44 | protected:
|
---|
45 | const _take<Target,value_type> take;
|
---|
46 | };
|
---|
47 |
|
---|
48 | template<class _Target,
|
---|
49 | class _Container>
|
---|
50 | DescriptorBase_impl<_Target,_Container>::DescriptorBase_impl(){}
|
---|
51 |
|
---|
52 | template<class _Target,
|
---|
53 | class _Container>
|
---|
54 | DescriptorBase_impl<_Target,_Container>::~DescriptorBase_impl(){}
|
---|
55 |
|
---|
56 | template<class _Target,
|
---|
57 | class _Container>
|
---|
58 | typename 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 |
|
---|
66 | template<class _Target,
|
---|
67 | class _Container>
|
---|
68 | typename 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 |
|
---|
76 | template<class _Target,
|
---|
77 | class _Container>
|
---|
78 | typename 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 |
|
---|
90 | template<class _Target,
|
---|
91 | class _Container>
|
---|
92 | typename 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_ */
|
---|