Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

seSearchIterator.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (c) 2004 Accent Geographic. All rights reserved.
00003  *  See the license file for licensing information.
00004  *  Created 2004/01/01
00005  */
00006 

00008 

00010 
00011 // $Id: seSearchIterator.h,v 1.4 2004/05/28 18:50:31 wmacchi Exp $
00012 
00013 #ifndef _seSearchIterator_h
00014 #define _seSearchIterator_h
00015 
00021 #include <stack>
00022 
00023 #include "seIterator.h"
00024 #include "seObject.h"
00025 
00026 namespace sedris {
00027 
00028 
00053 class seSearchIterator
00054 {
00055 public:
00056 
00058     seSearchIterator() : _filter(SE_DRM_CLS_NULL) {}
00059 
00061     virtual ~seSearchIterator() {}
00062 
00070     void start( seObject &start_obj, SE_DRM_Class filter )
00071     {
00072         if (filter == SE_DRM_CLS_NULL || SE_ValidDRMClass(filter) == SE_FALSE)
00073             throw seException(seException::INACTIONABLE_FAILURE,
00074                     "seSearchIterator needs a valid DRM filter class "
00075                     "(not SE_DRM_CLS_NULL)");
00076 
00077         while (!_iter_stack.empty())
00078             _iter_stack.pop();
00079 
00080         _filter = filter;
00081         if (mayHaveIt(start_obj))
00082             push_hierarchy(start_obj);
00083     }
00084 
00092     bool getNext( seObject &ret_obj )
00093     {
00094         bool done_pop = false;
00095         seObject obj, link_obj;
00096 
00097         while (!_iter_stack.empty())
00098         {
00099             seIterator tmp = _iter_stack.top();
00100 
00101             while (_iter_stack.top().getNext(obj, link_obj))
00102             {
00103                 // If we are not coming from a "pop", then we need to push
00104                 // the current object's hierarchy on the stack if it may
00105                 // have the object we are looking for.
00106                 if (!done_pop && mayHaveIt(obj))
00107                 {
00108                     // restore the iterator so that we re-get the object
00109                     // later when we pop all the way up
00110                     _iter_stack.top() = tmp;
00111                     push_hierarchy(obj);
00112                     done_pop = false;
00113                     continue;
00114                 }
00115 
00116                 if (obj.isA(_filter))
00117                 {
00118                     ret_obj = obj;
00119                     return true;
00120                 }
00121                 else if (link_obj.isValid() && link_obj.isA(_filter))
00122                 {
00123                     ret_obj = link_obj;
00124                     return true;
00125                 }
00126 
00127                 // save the current iterator position
00128                 tmp = _iter_stack.top();
00129                 done_pop = false;
00130             }
00131 
00132             // if we didn't find one, then we pop the stack to check at
00133             // the next higher level
00134             _iter_stack.pop();
00135             done_pop = true;
00136         }
00137 
00138         // if we get to here, then we didn't find any objects
00139         return false;
00140     }
00141 
00142 protected:
00143 
00145     bool mayHaveIt( seObject &obj )
00146     {
00147         if (SE_ShortestAggPath[obj.getDRMClass()][_filter] > -1
00148             && obj.hasComponents())
00149             return true;
00150         else
00151             return false;
00152     }
00153 
00155     void push_hierarchy( seObject &root_obj )
00156     {
00157         seIterator iter;
00158         seObject obj, link_obj;
00159 
00160         root_obj.getComponentIterator(iter);
00161         _iter_stack.push(iter);
00162         while (iter.getNext(obj, link_obj))
00163         {
00164             // If the current object could have a match below, then we
00165             // go ahead and push its hierarchy on the stack.
00166             // If it can't, then we advance the current top iterator's
00167             // position so that we don't look at the object again.
00168             if (obj.isA(_filter) || mayHaveIt(obj))
00169             {
00170                 if (link_obj.isValid() && (link_obj.isA(_filter)
00171                                             || mayHaveIt(link_obj)))
00172                     push_hierarchy(link_obj);
00173 
00174                 push_hierarchy(obj);
00175                 break;
00176             }
00177             else
00178             {
00179                 if (link_obj.isValid() && (link_obj.isA(_filter)
00180                                             || mayHaveIt(link_obj)))
00181                     push_hierarchy(link_obj);
00182 
00183                 _iter_stack.top().getNext(obj);
00184             }
00185         }
00186     }
00187 
00189     std::stack<seIterator> _iter_stack;
00190 
00192     SE_DRM_Class _filter;
00193 };
00194 
00195 
00198 } // namespace sedris
00199 
00200 #endif // _seSearchIterator_h

SEDRIS Transmittal Access C++ API 4.0.0 beta - 14 Jul 2004
Copyright © 2004 SEDRIS Docs by Doxygen 1.3.2