00001
00002
00003
00004
00005 #ifndef H_CPPCommonIterator
00006 #define H_CPPCommonIterator
00007
00008 #include <Common/Common.h>
00009 #include <C/Common/TRN_Types.h>
00010 #include <C/Common/TRN_Iterator.h>
00011
00012
00013 namespace pdftron {
00014 namespace Common {
00015
00019 template <class T>
00020 class Iterator
00021 {
00022 public:
00023 inline Iterator() : mp_impl(0) {}
00024 inline ~Iterator() {
00025 REX(TRN_IteratorDestroy(mp_impl));
00026 }
00027
00031 inline void Destroy()
00032 {
00033 REX(TRN_IteratorDestroy(mp_impl));
00034 mp_impl = 0;
00035 }
00036
00041 inline void Next() {
00042 BASE_ASSERT(mp_impl, "Null Iterator");
00043 REX(TRN_IteratorNext(mp_impl));
00044 }
00045
00050 inline T& Current() {
00051 BASE_ASSERT(mp_impl, "Null Iterator");
00052 TRN_ItrData result;
00053 REX(TRN_IteratorCurrent(mp_impl,&result));
00054 return *((T*)result);
00055 }
00056
00061 inline bool HasNext() {
00062 BASE_ASSERT(mp_impl, "Null Iterator");
00063 TRN_Bool result;
00064 REX(TRN_IteratorHasNext(mp_impl,&result));
00065 return TBToB(result);
00066 }
00067
00071 inline Iterator(const Iterator& c) : mp_impl(0) {
00072 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
00073 }
00074
00078 inline Iterator<T>& operator=(const Iterator<T>& other) {
00079 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
00080 return *this;
00081 }
00082
00084 #ifndef SWIGHIDDEN
00085 inline Iterator(TRN_Iterator impl) : mp_impl(impl) {}
00086 TRN_Iterator mp_impl;
00087 #endif
00089 };
00090
00094 template <>
00095 class Iterator<int>
00096 {
00097 public:
00098 inline Iterator() : mp_impl(0)
00099 {}
00100 inline Iterator(TRN_Iterator impl) : mp_impl(impl)
00101 {
00102 }
00103 inline ~Iterator()
00104 {
00105 REX(TRN_IteratorDestroy(mp_impl));
00106 mp_impl = 0;
00107 }
00108
00112 inline void Destroy()
00113 {
00114 REX(TRN_IteratorDestroy(mp_impl));
00115 mp_impl = 0;
00116 }
00117
00118 inline void Next()
00119 {
00120 BASE_ASSERT(mp_impl, "Null Iterator");
00121 REX(TRN_IteratorNext(mp_impl));
00122 }
00123
00124 inline int Current()
00125 {
00126 BASE_ASSERT(mp_impl, "Null Iterator");
00127 TRN_ItrData result;
00128 REX(TRN_IteratorCurrent(mp_impl,&result));
00129 return *((int*)result);
00130 }
00131
00132 inline bool HasNext()
00133 {
00134 BASE_ASSERT(mp_impl, "Null Iterator");
00135 TRN_Bool result;
00136 REX(TRN_IteratorHasNext(mp_impl,&result));
00137 return TBToB(result);
00138 }
00139
00140 inline Iterator<int>& operator=(const Iterator<int>& other)
00141 {
00142 BASE_ASSERT(other.mp_impl, "Null Iterator");
00143 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
00144 return *this;
00145 }
00146
00147 inline Iterator(const Iterator<int>& c)
00148 : mp_impl(0)
00149 {
00150 BASE_ASSERT(c.mp_impl, "Null Iterator");
00151 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
00152 }
00153
00155 #ifndef SWIGHIDDEN
00156 TRN_Iterator mp_impl;
00157 #endif
00159 };
00160
00161
00162 };
00163 };
00164
00165 #endif