Debian Codegraph @

3rdparty/xspublic/xstypes/xsrange.h

raw
1
2 // Copyright (c) 2003-2019 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 #ifndef XSRANGE_H
34 #define XSRANGE_H
35
36 #include "xstypesconfig.h"
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 #ifndef __cplusplus
42 #define XSRANGE_INITIALIZER { 0, -1 }
43 #endif
44
45 struct XsRange;
46
47 XSTYPES_DLL_API int XsRange_count(const struct XsRange* thisPtr);
48 XSTYPES_DLL_API int XsRange_contains(const struct XsRange* thisPtr, int i);
49 XSTYPES_DLL_API int XsRange_interval(const struct XsRange* thisPtr);
50 XSTYPES_DLL_API void XsRange_setRange(struct XsRange* thisPtr, int f, int l);
51 XSTYPES_DLL_API int XsRange_empty(const struct XsRange* thisPtr);
52
53 #ifdef __cplusplus
54 } // extern "C"
55 #endif
56
57 struct XsRange {
58 #ifdef __cplusplus
59 //! \brief Constructs a range starting at \a f and ending at \a l. Default values are 0 and -1 respectively.
60 inline explicit XsRange(int f = 0, int l = -1)
61 : m_first(f)
62 , m_last(l)
63 {}
64
65 //! \brief Constructs a range based upon \a other
66 inline XsRange(const XsRange& other)
67 : m_first(other.m_first)
68 , m_last(other.m_last)
69 {}
70
71 //! \brief Assigns the range \a other to this
72 inline XsRange& operator = (const XsRange& other)
73 {
74 m_first = other.m_first;
75 m_last = other.m_last;
76 return *this;
77 }
78
79 //! \brief \copybrief XsRange_count
80 inline int count() const
81 {
82 return XsRange_count(this);
83 }
84
85 //! \brief \copybrief XsRange_interval
86 inline int interval() const
87 {
88 return XsRange_interval(this);
89 }
90
91 //! \brief \copybrief XsRange_contains
92 inline bool contains(int i) const
93 {
94 return 0 != XsRange_contains(this, i);
95 }
96
97 //! \brief Set the range to \a f - \a l
98 inline void setRange(int f, int l)
99 {
100 m_first = f;
101 m_last = l;
102 }
103
104 //! \brief \copybrief XsRange_empty
105 inline bool empty() const
106 {
107 return 0 != XsRange_empty(this);
108 }
109
110 //! \brief Return the \e first value of the range
111 inline int first() const
112 {
113 return m_first;
114 }
115
116 //! \brief Return the \e last value of the range
117 inline int last() const
118 {
119 return m_last;
120 }
121
122 //! \brief Return true if this is equal to other
123 bool operator == (const XsRange& other) const
124 {
125 return m_first == other.m_first && m_last == other.m_last;
126 }
127
128 //! \brief Return true if start of this is less than start of other
129 bool operator < (const XsRange& other) const
130 {
131 return m_first < other.m_first;
132 }
133
134 private:
135 #endif
136
137 int m_first; //!< Storage for the lower end of the range
138 int m_last; //!< Storage for the upper end of the range
139 };
140
141 typedef struct XsRange XsRange;
142
143 #if defined(__cplusplus) && !defined(XSENS_NO_STL)
144 #include <ostream>
145
146 template<typename _CharT, typename _Traits>
147 std::basic_ostream<_CharT, _Traits>& operator<<(std::basic_ostream<_CharT, _Traits>& o, XsRange const& xs)
148 {
149 return (o << "(" << xs.first() << ", " << xs.last() << "]");
150 }
151 #endif
152
153 #endif