OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
SamplesHolder.hpp
Go to the documentation of this file.
1 /*
2  * Vortex OpenSplice
3  *
4  * This software and documentation are Copyright 2006 to 2021 ADLINK
5  * Technology Limited, its affiliated companies and licensors. All rights
6  * reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 #ifndef OSPL_DDS_SUB_DETAIL_SAMPLES_HOLDER_HPP_
22 #define OSPL_DDS_SUB_DETAIL_SAMPLES_HOLDER_HPP_
23 
29 
35 namespace dds
36 {
37 namespace sub
38 {
39 namespace detail
40 {
41 template <typename T>
42 class LoanedSamplesHolder : public SamplesHolder
43 {
44 public:
45  LoanedSamplesHolder(dds::sub::LoanedSamples<T>& samples) : samples_(samples), index(0)
46  {
47  }
48 
49  void set_length(uint32_t len) {
50  this->samples_.delegate()->resize(len);
51  }
52 
53  uint32_t get_length() const {
54  return this->index;
55  }
56 
57  SamplesHolder& operator++(int)
58  {
59  this->index++;
60  return *this;
61  }
62 
63  void *data()
64  {
65  return (*this->samples_.delegate())[this->index].delegate().data_ptr();
66  }
67 
68  detail::SampleInfo* info()
69  {
70  return (*this->samples_.delegate())[this->index].delegate().info_ptr();
71  }
72 
73 private:
75  uint32_t index;
76 };
77 
78 
79 
80 template <typename T, typename SamplesFWIterator>
81 class SamplesFWInteratorHolder : public SamplesHolder
82 {
83 public:
84  SamplesFWInteratorHolder(SamplesFWIterator& it) : iterator(it), length(0)
85  {
86  }
87 
88  void set_length(uint32_t len) {
89  this->length = len;
90 
91  }
92 
93  uint32_t get_length() const {
94  return this->length;
95  }
96 
97  SamplesHolder& operator++(int)
98  {
99  ++this->iterator;
100  return *this;
101  }
102 
103  void *data()
104  {
105  return (*iterator).delegate().data_ptr();
106  }
107 
108  detail::SampleInfo* info()
109  {
110  return (*iterator).delegate().info_ptr();
111  }
112 
113 private:
114  SamplesFWIterator& iterator;
115  uint32_t length;
116 
117 };
118 
119 template <typename T, typename SamplesBIIterator>
120 class SamplesBIIteratorHolder : public SamplesHolder
121 {
122 public:
123  SamplesBIIteratorHolder(SamplesBIIterator& it) : iterator(it), length(0)
124  {
125  }
126 
127  void set_length(uint32_t len) {
128  this->length = len;
129  }
130 
131  uint32_t get_length() const {
132  return this->length;
133  }
134 
135  SamplesHolder& operator++(int)
136  {
137  *this->iterator = this->sample;
138  ++this->iterator;
139  return *this;
140  }
141 
142  void *data()
143  {
144  return this->sample.delegate().data_ptr();
145  }
146 
147  detail::SampleInfo* info()
148  {
149  return this->sample.delegate().info_ptr();
150  }
151 
152 private:
153  SamplesBIIterator& iterator;
155  uint32_t length;
156 
157 };
158 
159 }
160 }
161 }
162 
163 
166 #endif /* OSPL_DDS_SUB_DETAIL_SAMPLES_HOLDER_HPP_ */
Definition: array.hpp:23
This class encapsulates and automates the management of loaned samples.
This class encapsulates the data and info meta-data associated with DDS samples.
Definition: Sample.hpp:30