Loading...
Searching...
No Matches
Iterator.h
Go to the documentation of this file.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5#ifndef PDFTRON_H_CPPCommonIterator
6#define PDFTRON_H_CPPCommonIterator
7
8#include <Common/Common.h>
9#include <C/Common/TRN_Types.h>
10#include <C/Common/TRN_Iterator.h>
11
12
13 namespace pdftron {
14 namespace Common {
15
19 template <class T>
20 class Iterator
21{
22 public:
23 inline Iterator() : mp_impl(0) {}
24 inline ~Iterator() {
25 DREX(mp_impl, TRN_IteratorDestroy(mp_impl));
26 }
27
31 inline void Destroy()
32 {
33 REX(TRN_IteratorDestroy(mp_impl));
34 mp_impl = 0;
35 }
36
41 inline void Next() {
42 BASE_ASSERT(mp_impl, "Null Iterator");
43 REX(TRN_IteratorNext(mp_impl));
44 }
45
50 inline T& Current() {
51 BASE_ASSERT(mp_impl, "Null Iterator");
52 TRN_ItrData result;
53 REX(TRN_IteratorCurrent(mp_impl,&result));
54 return *((T*)result);
55 }
56
61 inline bool HasNext() {
62 BASE_ASSERT(mp_impl, "Null Iterator");
63 TRN_Bool result;
64 REX(TRN_IteratorHasNext(mp_impl,&result));
65 return TBToB(result);
66 }
67
71 inline Iterator(const Iterator& c) : mp_impl(0) {
72 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
73 }
74
78 inline Iterator<T>& operator=(const Iterator<T>& other) {
79 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
80 return *this;
81 }
82
83// @cond PRIVATE_DOC
84#ifndef SWIGHIDDEN
85 inline Iterator(TRN_Iterator impl) : mp_impl(impl) {}
86 TRN_Iterator mp_impl;
87#endif
88// @endcond
89};
90
94 template <>
95 class Iterator<int>
96{
97 public:
98 inline Iterator() : mp_impl(0)
99 {}
100 inline Iterator(TRN_Iterator impl) : mp_impl(impl)
101 {
102 }
103 inline ~Iterator()
104 {
105 DREX(mp_impl, TRN_IteratorDestroy(mp_impl));
106 }
107
111 inline void Destroy()
112 {
113 REX(TRN_IteratorDestroy(mp_impl));
114 mp_impl = 0;
115 }
116
117 inline void Next()
118 {
119 BASE_ASSERT(mp_impl, "Null Iterator");
120 REX(TRN_IteratorNext(mp_impl));
121 }
122
123 inline int Current()
124 {
125 BASE_ASSERT(mp_impl, "Null Iterator");
126 TRN_ItrData result;
127 REX(TRN_IteratorCurrent(mp_impl,&result));
128 return *((int*)result);
129 }
130
131 inline bool HasNext()
132 {
133 BASE_ASSERT(mp_impl, "Null Iterator");
134 TRN_Bool result;
135 REX(TRN_IteratorHasNext(mp_impl,&result));
136 return TBToB(result);
137 }
138
139 inline Iterator<int>& operator=(const Iterator<int>& other)
140 {
141 BASE_ASSERT(other.mp_impl, "Null Iterator");
142 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
143 return *this;
144 }
145
146 inline Iterator(const Iterator<int>& c)
147 : mp_impl(0)
148 {
149 BASE_ASSERT(c.mp_impl, "Null Iterator");
150 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
151 }
152
153// @cond PRIVATE_DOC
154#ifndef SWIGHIDDEN
155 TRN_Iterator mp_impl;
156#endif
157// @endcond
158};
159
160
161 }; // namespace Common
162}; // namespace pdftron
163
164#endif // PDFTRON_H_CPPCommonIterator
Common.h
REX
#define REX(action)
Definition Common.h:13
DREX
#define DREX(impl, destroy_action)
Definition Common.h:14
pdftron::Common::Iterator::~Iterator
~Iterator()
Definition Iterator.h:24
pdftron::Common::Iterator::Iterator
Iterator()
Definition Iterator.h:23
pdftron::Common::Iterator::Next
void Next()
Definition Iterator.h:41
pdftron::Common::Iterator::Iterator
Iterator(const Iterator &c)
Definition Iterator.h:71
pdftron::Common::Iterator::Current
T & Current()
Definition Iterator.h:50
pdftron::Common::Iterator::operator=
Iterator< T > & operator=(const Iterator< T > &other)
Definition Iterator.h:78
pdftron::Common::Iterator::Destroy
void Destroy()
Definition Iterator.h:31
pdftron::Common::Iterator::HasNext
bool HasNext()
Definition Iterator.h:61
pdftron::Common
Definition ByteRange.h:15
pdftron
Definition BasicTypes.h:10