11#ifndef RTI_ROUTING_PROCESSOR_PORTS_ITERATOR_HPP_
12#define RTI_ROUTING_PROCESSOR_PORTS_ITERATOR_HPP_
14#include <dds/core/Value.hpp>
15#include <dds/core/SafeEnumeration.hpp>
16#include <rti/core/NativeValueType.hpp>
19#include <dds/core/xtypes/DynamicData.hpp>
20#include <dds/sub/SampleInfo.hpp>
21#include <rti/routing/processor/Input.hpp>
22#include <rti/routing/processor/Output.hpp>
24namespace rti {
namespace routing {
namespace processor {
26template <
typename PORT,
typename DataRep,
typename InfoRep>
struct TypedPortType;
28template <
typename DataRep,
typename InfoRep>
29struct TypedPortType<Input, DataRep, InfoRep>
31 typedef TypedInput<DataRep, InfoRep> type;
32 typedef RTI_RoutingServiceInput native_type;
34 static native_type * begin(RTI_RoutingServiceRoute *native_route)
36 return RTI_RoutingServiceRoute_get_first_input(native_route);
39 static native_type * next(
40 RTI_RoutingServiceRoute *native_route,
43 return RTI_RoutingServiceRoute_get_next_input(native_route, native);
46 static Input* from_native(native_type *native)
48 return static_cast<Input*
>(RTI_RoutingServiceInput_get_user_data(
54template <
typename DataRep,
typename InfoRep>
55struct TypedPortType<Output, DataRep, InfoRep>
57 typedef TypedOutput<DataRep, InfoRep> type;
58 typedef RTI_RoutingServiceOutput native_type;
60 static native_type * begin(RTI_RoutingServiceRoute *native_route)
62 return RTI_RoutingServiceRoute_get_first_output(native_route);
65 static native_type * next(
66 RTI_RoutingServiceRoute *native_route,
69 return RTI_RoutingServiceRoute_get_next_output(native_route, native);
72 static Output* from_native(native_type *native)
74 return static_cast<Output*
>(RTI_RoutingServiceOutput_get_user_data(
79template <
typename PORT,
81 typename InfoRep = dds::sub::SampleInfo>
85 typedef std::random_access_iterator_tag iterator_category;
86 typedef typename TypedPortType<PORT, DataRep, InfoRep>::type value_type;
87 typedef value_type reference;
88 typedef value_type pointer;
89 typedef std::ptrdiff_t difference_type;
92 explicit PortIterator(
93 RTI_RoutingServiceRoute *native_route)
94 : native_route_(native_route)
96 native_ = TypedPortType<PORT, DataRep, InfoRep>::begin(native_route);
99 explicit PortIterator()
100 : native_route_(NULL), native_(NULL)
104 PortIterator (
const PortIterator<PORT, DataRep, InfoRep>& other)
105 : native_route_(other.native_route_),
106 native_(other.native_)
109 PortIterator & operator = (
const PortIterator<PORT, DataRep, InfoRep>& other)
111 native_route_ = other.native_route_;
112 native_ = other.native_;
117 value_type operator*()
119 return TypedPortType<PORT, DataRep, InfoRep>::from_native(native_);
122 value_type operator->()
127 PortIterator & operator++()
129 native_ = TypedPortType<PORT, DataRep, InfoRep>::next(
136 PortIterator operator++(
int)
138 PortIterator temp(*
this);
144 friend bool operator<(
145 const PortIterator & s1,
146 const PortIterator & s2)
148 return s1.index() < s2.index();
151 friend bool operator>(
152 const PortIterator & s1,
153 const PortIterator & s2)
155 return s1.index() > s2.index();
158 friend bool operator<=(
159 const PortIterator & s1,
160 const PortIterator & s2)
162 return s1.index() <= s2.index();
165 friend bool operator>=(
166 const PortIterator & s1,
167 const PortIterator & s2)
169 return s1.index() >= s2.index();
172 friend bool operator==(
173 const PortIterator & s1,
174 const PortIterator & s2)
176 return (s1.index() == s2.index());
179 friend bool operator!=(
180 const PortIterator & s1,
181 const PortIterator & s2)
187 int32_t index()
const
189 return (native_ == NULL)
191 : TypedPortType<PORT, DataRep, InfoRep>::from_native(native_)->index();
194 RTI_RoutingServiceRoute *native_route_;
195 typename TypedPortType<PORT, DataRep, InfoRep>::native_type *native_;