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
00032 inline void Next() {
00033 BASE_ASSERT(mp_impl,"Null Iterator");
00034 REX(TRN_IteratorNext(mp_impl));
00035 }
00036
00041 inline T& Current() {
00042 BASE_ASSERT(mp_impl,"Null Iterator");
00043 TRN_ItrData result;
00044 REX(TRN_IteratorCurrent(mp_impl,&result));
00045 return *((T*)result);
00046 }
00047
00052 inline bool HasNext() {
00053 BASE_ASSERT(mp_impl,"Null Iterator");
00054 TRN_Bool result;
00055 REX(TRN_IteratorHasNext(mp_impl,&result));
00056 return TBToB(result);
00057 }
00058
00062 inline Iterator(const Iterator& c) : mp_impl(0) {
00063 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
00064 }
00065
00069 inline Iterator<T>& operator=(const Iterator<T>& other) {
00070 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
00071 return *this;
00072 }
00073
00075 inline Iterator(TRN_Iterator impl) : mp_impl(impl) {}
00076 TRN_Iterator mp_impl;
00078 };
00079
00080
00084 template <>
00085 class Iterator<int>
00086 {
00087 public:
00088 inline Iterator() : mp_impl(0)
00089 {}
00090 inline Iterator(TRN_Iterator impl) : mp_impl(impl)
00091 {
00092 }
00093 inline ~Iterator()
00094 {
00095 REX(TRN_IteratorDestroy(mp_impl));
00096 }
00097
00098 inline void Next()
00099 {
00100 BASE_ASSERT(mp_impl,"Null Iterator");
00101 REX(TRN_IteratorNext(mp_impl));
00102 }
00103
00104 inline int Current()
00105 {
00106 BASE_ASSERT(mp_impl,"Null Iterator");
00107 TRN_ItrData result;
00108 REX(TRN_IteratorCurrent(mp_impl,&result));
00109 return *((int*)result);
00110 }
00111
00112 inline bool HasNext()
00113 {
00114 BASE_ASSERT(mp_impl,"Null Iterator");
00115 TRN_Bool result;
00116 REX(TRN_IteratorHasNext(mp_impl,&result));
00117 return TBToB(result);
00118 }
00119 inline Iterator<int>& operator=(const Iterator<int>& other)
00120 {
00121 BASE_ASSERT(mp_impl && other.mp_impl,"Null Iterator");
00122 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
00123 return *this;
00124 }
00125
00126 inline Iterator(const Iterator<int>& c)
00127 {
00128 BASE_ASSERT(mp_impl && c.mp_impl,"Null Iterator");
00129 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
00130 }
00131
00133 TRN_Iterator mp_impl;
00135 };
00136
00137
00138 };
00139 };
00140
00141 #endif