OCILIB (C and C++ Driver for Oracle)  4.7.6
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
CollectionIterator.hpp
1 /*
2  * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI)
3  *
4  * Website: http://www.ocilib.net
5  *
6  * Copyright (c) 2007-2023 Vincent ROGIER <vince.rogier@ocilib.net>
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 #pragma once
22 
23 #include "ocilibcpp/types.hpp"
24 
25 // ReSharper disable CppClangTidyCertOop54Cpp
26 
27 namespace ocilib
28 {
29 
30 template<class T>
31 CollectionIterator<T>::CollectionIterator() : _elem()
32 {
33 
34 }
35 
36 template<class T>
37 CollectionIterator<T>::CollectionIterator(CollectionType *collection, unsigned int pos) : _elem(collection, pos)
38 {
39 
40 }
41 
42 template<class T>
43 CollectionIterator<T>::CollectionIterator(const CollectionIterator& other) : _elem(other._elem)
44 {
45 
46 }
47 
48 template<class T>
49 CollectionIterator<T>& CollectionIterator<T>::operator = (const CollectionIterator& other)
50 {
51  if (this != &other)
52  {
53  _elem._pos = other._elem._pos;
54  _elem._coll = other._elem._coll;
55  }
56 
57  return *this;
58 }
59 
60 template<class T>
61 CollectionIterator<T>& CollectionIterator<T>::operator += (difference_type value)
62 {
63  _elem._pos += static_cast<unsigned int>(value);
64  return *this;
65 }
66 
67 template<class T>
68 CollectionIterator<T>& CollectionIterator<T>::operator -= (difference_type value)
69 {
70  _elem._pos -= static_cast<unsigned int>(value);
71  return *this;
72 }
73 
74 template<class T>
75 T& CollectionIterator<T>::operator*()
76 {
77  return _elem;
78 }
79 
80 template<class T>
81 T* CollectionIterator<T>::operator->()
82 {
83  return &_elem;
84 }
85 
86 template<class T>
87 CollectionIterator<T>& CollectionIterator<T>::operator--()
88 {
89  --_elem._pos;
90  return *this;
91 }
92 
93 template<class T>
94 CollectionIterator<T>& CollectionIterator<T>::operator++()
95 {
96  ++*(const_cast<unsigned int*>(&_elem._pos));
97  return *this;
98 }
99 
100 template<class T>
101 CollectionIterator<T> CollectionIterator<T>::operator++(int)
102 {
103  CollectionIterator res(_elem._coll, _elem._pos);
104  ++(*this);
105  return res;
106 }
107 
108 template<class T>
109 CollectionIterator<T> CollectionIterator<T>::operator--(int)
110 {
111  CollectionIterator res(_elem);
112  --(*this);
113  return res;
114 }
115 
116 template<class T>
117 CollectionIterator<T> CollectionIterator<T>::operator + (difference_type value)
118 {
119  return CollectionIterator(_elem._coll, _elem._pos + static_cast<unsigned int>(value));
120 }
121 
122 template<class T>
123 CollectionIterator<T> CollectionIterator<T>::operator - (difference_type value)
124 {
125  return CollectionIterator(_elem._coll, _elem._pos - static_cast<unsigned int>(value));
126 }
127 
128 template<class T>
129 typename CollectionIterator<T>::difference_type CollectionIterator<T>::operator - (const CollectionIterator & other)
130 {
131  return static_cast<difference_type>(_elem._pos - other._elem._pos);
132 }
133 
134 template<class T>
135 bool CollectionIterator<T>::operator == (const CollectionIterator& other)
136 {
137  return _elem._pos == other._elem._pos && (static_cast<OCI_Coll *>(*_elem._coll)) == (static_cast<OCI_Coll *>(*other._elem._coll));
138 }
139 
140 template<class T>
141 bool CollectionIterator<T>::operator != (const CollectionIterator& other)
142 {
143  return !(*this == other);
144 }
145 
146 template<class T>
147 bool CollectionIterator<T>::operator > (const CollectionIterator& other)
148 {
149  return _elem._pos > other._elem._pos;
150 }
151 
152 template<class T>
153 bool CollectionIterator<T>::operator < (const CollectionIterator& other)
154 {
155  return _elem._pos < other._elem._pos;
156 }
157 
158 template<class T>
159 bool CollectionIterator<T>::operator >= (const CollectionIterator& other)
160 {
161  return _elem._pos >= other._elem._pos;
162 }
163 
164 template<class T>
165 bool CollectionIterator<T>::operator <= (const CollectionIterator& other)
166 {
167  return _elem._pos <= other._elem._pos;
168 }
169 
170 }
struct OCI_Coll OCI_Coll
Oracle Collections (VARRAYs and Nested Tables) representation.
Definition: types.h:319
OCILIB ++ Namespace.