datapacket_p.cpp
Go to the documentation of this file.
1 
2 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions, and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions, and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 //
15 // 3. Neither the names of the copyright holders nor the names of their contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
26 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
28 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
29 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
30 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
31 //
32 
33 
34 // Copyright (c) 2003-2021 Xsens Technologies B.V. or subsidiaries worldwide.
35 // All rights reserved.
36 //
37 // Redistribution and use in source and binary forms, with or without modification,
38 // are permitted provided that the following conditions are met:
39 //
40 // 1. Redistributions of source code must retain the above copyright notice,
41 // this list of conditions, and the following disclaimer.
42 //
43 // 2. Redistributions in binary form must reproduce the above copyright notice,
44 // this list of conditions, and the following disclaimer in the documentation
45 // and/or other materials provided with the distribution.
46 //
47 // 3. Neither the names of the copyright holders nor the names of their contributors
48 // may be used to endorse or promote products derived from this software without
49 // specific prior written permission.
50 //
51 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
52 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
53 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 // THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 // SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
56 // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR
58 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
59 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.THE LAWS OF THE NETHERLANDS
60 // SHALL BE EXCLUSIVELY APPLICABLE AND ANY DISPUTES SHALL BE FINALLY SETTLED UNDER THE RULES
61 // OF ARBITRATION OF THE INTERNATIONAL CHAMBER OF COMMERCE IN THE HAGUE BY ONE OR MORE
62 // ARBITRATORS APPOINTED IN ACCORDANCE WITH SAID RULES.
63 //
64 
65 #include "datapacket_p.h"
66 
74 volatile std::atomic_int DataPacketPrivate::m_created(0);
75 volatile std::atomic_int DataPacketPrivate::m_destroyed(0);
76 
79  : MapType() // start with clean map
80  , m_refCount(1) // this is a new object so the ref count is 1
81 {
82  ++m_created;
83  *this = p; // does NOT manipulate the ref count
84 }
85 
87 DataPacketPrivate::~DataPacketPrivate()
88 {
89  ++m_destroyed;
90  try
91  {
92  clear();
93  }
94  catch (...)
95  {
96  }
97 }
98 
104 DataPacketPrivate& DataPacketPrivate::operator = (const DataPacketPrivate& p)
105 {
106  if (this != &p)
107  {
108  clear();
109  for (auto i : p)
110  insert(i.first, i.second->clone());
111  }
112  return *this;
113 }
114 
116 void DataPacketPrivate::clear()
117 {
118  for (auto it : *this)
119  delete it.second;
120  MapType::clear();
121 }
122 
130 MapType::const_iterator DataPacketPrivate::find(XsDataIdentifier id) const
131 {
132  return MapType::find(id & XDI_FullTypeMask);
133 }
134 
142 MapType::iterator DataPacketPrivate::insert(XsDataIdentifier id, XsDataPacket_Private::Variant* var)
143 {
144  id = id & XDI_FullTypeMask;
145  auto it = MapType::lower_bound(id);
146  if (it != end() && it->first == id)
147  {
148  delete it->second;
149  it->second = var;
150  return it;
151  }
152  else
153  return MapType::insert(it, std::make_pair(id & XDI_FullTypeMask, var));
154 }
155 
157 void DataPacketPrivate::erase(XsDataIdentifier id)
158 {
159  auto it = find(id);
160  if (it != end())
161  erase(it);
162 }
163 
165 void DataPacketPrivate::erase(MapType::const_iterator const& it)
166 {
167  delete it->second;
168  MapType::erase(it);
169 }
170 
178 void DataPacketPrivate::merge(DataPacketPrivate const& other, bool overwrite)
179 {
180  if (overwrite)
181  for (auto i : other)
182  insert(i.first, i.second->clone());
183  else
184  {
185  for (auto i : other)
186  {
187  auto j = find(i.first);
188  if (j == end())
189  insert(i.first, i.second->clone());
190  }
191  }
192 }
193 
195 int DataPacketPrivate::creationDiff()
196 {
197  return m_created.load() - m_destroyed.load();
198 }
199 
XDI_FullTypeMask
@ XDI_FullTypeMask
Mask to get the type of data, without the data format.
Definition: xsdataidentifier.h:88
XsDataIdentifier
XsDataIdentifier
Defines the data identifiers.
Definition: xsdataidentifier.h:84
DataPacketPrivate
struct XSNOEXPORT DataPacketPrivate
Definition: xsdatapacket.h:101
datapacket_p.h


xsens_mti_driver
Author(s):
autogenerated on Sun Sep 3 2023 02:43:20