OpenSplice ISO C++ 2 DCPS  v6.x
ISO C++ 2 OpenSplice Data Distribution Service Data-Centric Publish-Subscribe API
find.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 
22 
27 #ifndef OSPL_DDS_PUB_DETAIL_FIND_HPP_
28 #define OSPL_DDS_PUB_DETAIL_FIND_HPP_
29 
30 #include <string>
31 
32 #include <dds/pub/DataWriter.hpp>
33 #include <dds/pub/Publisher.hpp>
34 #include <org/opensplice/pub/PublisherDelegate.hpp>
35 #include <org/opensplice/pub/AnyDataWriterDelegate.hpp>
36 
42 namespace dds
43 {
44 namespace pub
45 {
46 
47 template <typename WRITER, typename FwdIterator>
48 uint32_t
49 find(const dds::pub::Publisher& pub, const std::string& topic_name,
50  FwdIterator begin, int32_t max_size)
51 {
52  ISOCPP_REPORT_STACK_DDS_BEGIN(pub);
53  if(max_size > 0) {
54  org::opensplice::pub::AnyDataWriterDelegate::ref_type writer_base = pub.delegate()->find_datawriter(topic_name);
55  if (writer_base) {
56  /* Cast base writer to typed delegate: */
57  typename WRITER::DELEGATE_REF_T writer_typed =
58  OSPL_CXX11_STD_MODULE::dynamic_pointer_cast<typename WRITER::DELEGATE_T>(writer_base);
59  WRITER dw(writer_typed);
60  if(dw != dds::core::null)
61  {
62  *begin = dw;
63  return 1;
64  }
65  }
66  }
67  return 0;
68 }
69 
70 
71 template <typename WRITER, typename BinIterator>
72 uint32_t
73 find(const dds::pub::Publisher& pub,
74  const std::string& topic_name,
75  BinIterator begin)
76 {
77  ISOCPP_REPORT_STACK_DDS_BEGIN(pub);
78  org::opensplice::pub::AnyDataWriterDelegate::ref_type writer_base = pub.delegate()->find_datawriter(topic_name);
79  if (writer_base) {
80  /* Cast base writer to typed delegate: */
81  typename WRITER::DELEGATE_REF_T writer_typed =
82  OSPL_CXX11_STD_MODULE::dynamic_pointer_cast<typename WRITER::DELEGATE_T>(writer_base);
83  WRITER dw(writer_typed);
84  if(dw != dds::core::null)
85  {
86  *begin = dw;
87  return 1;
88  }
89  }
90  return 0;
91 }
92 
93 
94 }
95 }
96 
99 #endif /* OSPL_DDS_PUB_DETAIL_FIND_HPP_ */
Definition: array.hpp:23
uint32_t find(const dds::pub::Publisher &pub, const std::string &topic_name, FwdIterator begin, uint32_t max_size)
The Publisher acts on the behalf of one or several DataWriter objects that belong to it...
Definition: Publisher.hpp:55