00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #define CURPATH_LABELBLOCKSIZE 32
00039
00040 struct CurPathLabelBlock
00041 {
00042 CurPathLabelBlock *prev,*next;
00043 TLabelID labels[CURPATH_LABELBLOCKSIZE];
00044 };
00045
00046 class CurPath;
00047
00048 class CurPathIterator
00049
00050
00051 {
00052 friend CurPath;
00053 CurPathLabelBlock *curblock;
00054 TLabelID *curlabel;
00055
00056 public:
00057
00058 TLabelID GotoNext()
00059
00060
00061 {
00062 if(curlabel==curblock->labels+CURPATH_LABELBLOCKSIZE)
00063 {
00064 curblock=curblock->next;
00065 if(curblock==NULL)
00066 return LABEL_UNDEFINED;
00067 curlabel=curblock->labels;
00068 }
00069 return *(curlabel++);
00070 }
00071
00072 TLabelID GotoPrev()
00073
00074
00075 {
00076 curlabel--;
00077 if(curlabel==curblock->labels-1)
00078 {
00079 curblock=curblock->prev;
00080 if(curblock==NULL)
00081 return LABEL_UNDEFINED;
00082
00083 curlabel=curblock->labels+CURPATH_LABELBLOCKSIZE-1;
00084 }
00085 return *curlabel;
00086 }
00087 };
00088
00089 class CurPath
00090
00091 {
00092 CurPathLabelBlock firstblock;
00093 CurPathLabelBlock *curblock;
00094 TLabelID *curlabel;
00095
00096
00097 #ifdef PROFILE
00098 unsigned curdepth,maxdepth;
00099 #endif
00100
00101 public:
00102 CurPath()
00103 {
00104 firstblock.prev=NULL;
00105 firstblock.next=NULL;
00106 curblock=&firstblock;
00107 curlabel=curblock->labels;
00108
00109 #ifdef PROFILE
00110 curdepth=maxdepth=0;
00111 #endif
00112 }
00113
00114 void AddLabel(TLabelID labelid)
00115
00116 {
00117 #ifdef PROFILE
00118 curdepth++;
00119 if(curdepth>maxdepth)
00120 maxdepth=curdepth;
00121 #endif
00122
00123 if(curlabel==curblock->labels+CURPATH_LABELBLOCKSIZE)
00124
00125
00126
00127 {
00128 if(curblock->next==NULL)
00129 {
00130 curblock->next=new CurPathLabelBlock();
00131 curblock->next->prev=curblock;
00132 curblock->next->next=NULL;
00133 }
00134 curblock=curblock->next;
00135
00136
00137 curlabel=curblock->labels;
00138 }
00139 *curlabel=labelid;
00140 curlabel++;
00141 }
00142
00143 TLabelID RemoveLabel()
00144
00145 {
00146 #ifdef PROFILE
00147 curdepth--;
00148 #endif
00149
00150 curlabel--;
00151 if(curlabel==curblock->labels-1)
00152
00153
00154 {
00155 curblock=curblock->prev;
00156 if(curblock==NULL)
00157 return LABEL_UNDEFINED;
00158
00159 curlabel=curblock->labels+CURPATH_LABELBLOCKSIZE-1;
00160 }
00161 return *curlabel;
00162 }
00163
00164 void InitIterator(CurPathIterator *it)
00165
00166 {
00167 it->curblock=curblock;
00168 it->curlabel=curlabel;
00169 }
00170
00171 #ifdef PROFILE
00172 void PrintProfile()
00173 {
00174 printf("Maximal Depth=%lu\n",maxdepth);
00175 }
00176 #endif
00177 };
00178
00179
00180 extern CurPath curpath;