Iterator.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------------------
00002 // Copyright (c) 2001-2008 by PDFTron Systems Inc. All Rights Reserved.
00003 // Consult legal.txt regarding legal and license information.
00004 //---------------------------------------------------------------------------------------
00005 #ifndef   H_CPPCommonIterator
00006 #define   H_CPPCommonIterator
00007 
00008 #include <C/Common/TRN_Types.h>
00009 #include <C/Common/TRN_Iterator.h>
00010 
00011 
00012 namespace pdftron {
00013         namespace Common {
00014 
00018 template <class T>
00019 class Iterator
00020 {
00021 public:
00022         inline Iterator() : mp_impl(0) {}
00023         inline ~Iterator() {
00024                 REX(TRN_IteratorDestroy(mp_impl));
00025         }
00026 
00030         inline void Next() {
00031                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00032                 REX(TRN_IteratorNext(mp_impl));
00033         }
00034 
00038         inline T& Current() {
00039                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00040                 TRN_ItrData result;     
00041                 REX(TRN_IteratorCurrent(mp_impl,&result));
00042                 return *((T*)result);
00043         }
00044 
00049         inline bool HasNext() {
00050                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00051                 TRN_Bool result;
00052                 REX(TRN_IteratorHasNext(mp_impl,&result));
00053                 return TBToB(result);
00054         }
00055         
00059         inline Iterator(const Iterator& c) : mp_impl(0) {
00060                 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
00061         }
00062 
00066         inline Iterator<T>& operator=(const Iterator<T>& other) {
00067                 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
00068                 return *this;
00069         }
00070 
00072         inline Iterator(TRN_Iterator impl) : mp_impl(impl) {}
00073         TRN_Iterator mp_impl;
00075 };
00076 
00077 
00081 template <>
00082 class Iterator<int>
00083 {
00084 public:
00085         inline Iterator() : mp_impl(0)
00086         {}
00087         inline Iterator(TRN_Iterator impl) : mp_impl(impl)
00088         {
00089         }
00090         inline ~Iterator()
00091         {
00092                 REX(TRN_IteratorDestroy(mp_impl));
00093         }
00094 
00095         inline void Next()
00096         {
00097                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00098                 REX(TRN_IteratorNext(mp_impl));
00099         }
00100 
00101         inline int Current()
00102         {
00103                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00104                 TRN_ItrData result;
00105                 REX(TRN_IteratorCurrent(mp_impl,&result));
00106                 return *((int*)result);
00107         }
00108 
00109         inline bool HasNext()
00110         {
00111                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00112                 TRN_Bool result;
00113                 REX(TRN_IteratorHasNext(mp_impl,&result));
00114                 return TBToB(result);
00115         }
00116         inline Iterator<int>& operator=(const Iterator<int>& other)
00117         {
00118                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00119                 BASE_ASSERT(other.mp_impl,"Cannot Call Assignment Operator With a Null Iterator");
00120                 REX(TRN_IteratorAssign(other.mp_impl,&mp_impl));
00121                 return *this;
00122         }
00123 
00124         inline Iterator(const Iterator<int>& c)
00125         {
00126                 BASE_ASSERT(mp_impl,"Cannot Call Member Function on Null Iterator");
00127                 BASE_ASSERT(c.mp_impl,"Cannot Call Copy Constructor With a Null Iterator");
00128                 REX(TRN_IteratorAssign(c.mp_impl,&mp_impl));
00129         }
00130 
00132         TRN_Iterator mp_impl;
00134 };
00135 
00136 
00137         };      // namespace Common
00138 };      // namespace pdftron
00139 
00140 #endif

© 2002-2008 PDFTron Systems Inc.