| TerraLib 4.1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/kernel/TeViewTreeIterator.h
Go to the documentation of this file.

    00001 /* $Id: TeViewTreeIterator.h 6480 2007-10-22 17:05:59Z juan $
    00002 ** ---------------------------------------------------------------
    00003 ** TeViewTreeIterator -
    00004 **
    00005 */
    00006
    00007 #ifndef TEVIEWTREEITERATOR_H
    00008 #define TEVIEWTREEITERATOR_H
    00009
    00010 /*
    00011 ** ---------------------------------------------------------------
    00012 ** Includes:
    00013 */
    00014
    00015 // TerraLib includes
    00016 #include "TeException.h"
    00017 #include "TeViewNode.h"
    00018
    00019 // STL includes
    00020 #include <vector>
    00021 #include <stack>
    00022
    00023 /*
    00024 ** ---------------------------------------------------------------
    00025 ** Defines:
    00026 */
    00027
    00028 /*
    00029   One stl module included by some TerraLib files define a macro named
    00030   next which conflicts whith the TeViewTreeInterator::next method. So
    00031   we choosed to undefine it.
    00032 */
    00033 #undef next
    00034
    00035
    00036 /*
    00037 ** ---------------------------------------------------------------
    00038 ** Class definition:
    00039 */
    00040
    00041 class TL_DLL TeViewTreeIterator
    00042 {
    00043 public:
    00044   TeViewTreeIterator(TeViewTree* root);
    00045
    00046   void first();
    00047   void firstLeaf();
    00048   void next();
    00049   void nextLeaf();
    00050   void skipChildren();
    00051
    00052 //  void Previous();
    00053
    00054   bool isDone();
    00055
    00056   TeViewNode* currentNode();
    00057   int currentDepth();
    00058
    00059 protected:
    00060 private:
    00061   struct StackElem{
    00062     StackElem(TeViewTree* tr, int i){ tree = tr; ind = i; }
    00063     TeViewTree* tree;
    00064     int ind;
    00065   };
    00066
    00067   std::stack<StackElem> TravStack;
    00068 };
    00069
    00070 class TL_DLL TeViewTreeRevIterator
    00071 {
    00072 public:
    00073   TeViewTreeRevIterator(TeViewTree* root);
    00074
    00075   void first();
    00076   void firstLeaf();
    00077   void next();
    00078   void nextLeaf();
    00079   void skipChildren();
    00080
    00081 //  void Previous();
    00082
    00083   bool isDone();
    00084
    00085   TeViewNode* currentNode();
    00086   int currentDepth();
    00087
    00088 protected:
    00089 private:
    00090   struct StackElem{
    00091     StackElem(TeViewTree* tr, int i){ tree = tr; ind = i; }
    00092     StackElem(TeViewTree* tr){ tree = tr; ind = tr->size(); }
    00093     TeViewTree* tree;
    00094     int ind;
    00095   };
    00096
    00097   std::stack<StackElem> TravStack; // traversal stack
    00098 };
    00099
    00100
    00101 /*
    00102 ** ---------------------------------------------------------------
    00103 ** Inline methods:
    00104 */
    00105
    00106 inline TeViewTreeIterator::TeViewTreeIterator(TeViewTree* root)
    00107 {
    00108   TravStack.push(StackElem(root, -1));
    00109 }
    00110
    00111 inline TeViewTreeRevIterator::TeViewTreeRevIterator(TeViewTree* root)
    00112 {
    00113   TravStack.push(StackElem(root));
    00114 }
    00115
    00116 inline void TeViewTreeIterator::first()
    00117 {
    00118   while(TravStack.size() > 1)
    00119     TravStack.pop();
    00120   TravStack.top().ind = -1;
    00121 }
    00122
    00123 inline void TeViewTreeRevIterator::first()
    00124 {
    00125   while(TravStack.size() > 1)
    00126     TravStack.pop();
    00127   TravStack.top().ind = TravStack.top().tree->size();
    00128 }
    00129
    00130 inline void TeViewTreeIterator::firstLeaf()
    00131 {
    00132   first();
    00133   nextLeaf();
    00134 }
    00135
    00136 inline void TeViewTreeRevIterator::firstLeaf()
    00137 {
    00138   first();
    00139   nextLeaf();
    00140 }
    00141
    00142 inline bool TeViewTreeIterator::isDone()
    00143 {
    00144   if(TravStack.size() > 1) return false;
    00145
    00146   StackElem& elem = TravStack.top();
    00147   if(elem.ind < (int)(elem.tree->size())) return false;
    00148
    00149   return true;
    00150 }
    00151
    00152 inline bool TeViewTreeRevIterator::isDone()
    00153 {
    00154   if(TravStack.size() > 1) return false;
    00155
    00156   StackElem& elem = TravStack.top();
    00157   if(elem.ind >= 0) return false;
    00158
    00159   return true;
    00160 }
    00161
    00162 inline TeViewNode* TeViewTreeIterator::currentNode()
    00163 {
    00164   StackElem& elem = TravStack.top();
    00165   if(elem.ind == -1) return elem.tree;
    00166
    00167   return elem.tree->retrieve(elem.ind);
    00168 }
    00169
    00170 inline TeViewNode* TeViewTreeRevIterator::currentNode()
    00171 {
    00172   StackElem& elem = TravStack.top();
    00173   if(elem.ind == (int)(elem.tree->size())) return elem.tree;
    00174
    00175   return elem.tree->retrieve(elem.ind);
    00176 }
    00177
    00178 inline int TeViewTreeIterator::currentDepth()
    00179 {
    00180   return TravStack.size() - 1;
    00181 }
    00182
    00183 inline int TeViewTreeRevIterator::currentDepth()
    00184 {
    00185   return TravStack.size() - 1;
    00186 }
    00187
    00188
    00189 #ifdef te__next_back__
    00190 #define next te__next_back__
    00191 #undef te__next_back__  // some stl module defines a macro named next that is generating conflics with
    00192 #endif
    00193 #endif

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines