00001 00038 #include "Defs.h" 00039 #include "configtree.h" 00040 00041 00042 long configtree::Read(const mutStringRef key, long defval) 00043 { 00044 return config -> Read(key, defval); 00045 } 00046 00047 double configtree::Read(const mutStringRef key, double defval) 00048 { 00049 return config -> Read(key, defval); 00050 } 00051 00052 int configtree::Read(const mutStringRef key, int defval) 00053 { 00054 return (int) config -> Read(key, (long) defval); 00055 } 00056 00057 bool configtree::Read(const mutStringRef key, bool defval) 00058 { 00059 return config -> Read(key, (long) defval); 00060 } 00061 00062 mutString configtree::Read(const mutStringRef key, const mutStringRef defval) 00063 { 00064 return config -> Read(key, defval); 00065 } 00066 00067 void configtree::Write (const mutStringRef key, long value) 00068 { 00069 config -> Write(key, value); 00070 } 00071 00072 void configtree::Write (const mutStringRef key, double value) 00073 { 00074 config -> Write (key, value); 00075 } 00076 00077 void configtree::Write (const mutStringRef key, int value) 00078 { 00079 config -> Write (key, (long) value); 00080 } 00081 00082 void configtree::Write (const mutStringRef key, bool value) 00083 { 00084 config -> Write(key, (long) value); 00085 } 00086 00087 void configtree::Write (const mutStringRef key, const mutStringRef value) 00088 { 00089 config -> Write (key, value); 00090 } 00091 00092 bool configtree::HasGroup(const mutStringRef subdir) const 00093 { 00094 return config->HasGroup(subdir); 00095 } 00096 00097 void configtree::toLeaf(const mutStringRef subdir) 00098 { 00099 DEBUGLOG(config,_T("going to group '%s'"),subdir.c_str()); 00100 wxASSERT(subdir.Find('/') == wxNOT_FOUND); 00101 wxASSERT(subdir != _T("..")); 00102 if (subdir.Find('/') != wxNOT_FOUND || subdir == _T("..")) { 00103 UNREACHABLEC; 00104 return; 00105 } 00106 state newstate; 00107 #ifdef DEBUG 00108 newstate.oldpath = config -> GetPath(); 00109 #endif 00110 DEBUGLOG(config,_T("setting path to '%s'"),(subdir).c_str()); 00111 config -> SetPath(subdir); 00112 newstate.chdepth = 1; 00113 states.push(newstate); 00114 DEBUGLOG(config,_T("current path = '%s', old path = '%s', depth = %d, id = %d, name = '%s'"), 00115 config->GetPath().c_str(), newstate.oldpath.c_str(), newstate.chdepth, 00116 newstate.leafid, newstate.group.c_str()); 00117 } 00118 00119 void configtree::toLeaf(const mutStringRef name, int id) 00120 { 00121 DEBUGLOG(config,_T("going to group '%s' with id %d"),name.c_str(),id); 00122 toLeaf(name); 00123 state newstate = states.top(); 00124 config->SetPath(wxString::Format(_T("%d"),id)); 00125 newstate.chdepth++; 00126 states.pop(); 00127 states.push(newstate); 00128 DEBUGLOG(config,_T("current path = '%s', old path = '%s', depth = %d, id = %d, name = '%s'"), 00129 config->GetPath().c_str(), newstate.oldpath.c_str(), newstate.chdepth, 00130 newstate.leafid, newstate.group.c_str()); 00131 } 00132 00133 int configtree::toFirstLeaf(const mutStringRef name,mutStringRef id) 00134 { 00135 DEBUGLOG(config,_T("going to first leaf of group '%s'"),name.c_str()); 00136 toLeaf(name); 00137 state newstate = states.top(); 00138 bool found = config->GetFirstGroup(id,newstate.leafid); 00139 if (!found) { 00140 id = _T("0"); 00141 newstate.leafid = wxNOT_FOUND; 00142 } 00143 config->SetPath(id); 00144 newstate.chdepth++; 00145 #ifdef DEBUG 00146 newstate.group=name; 00147 #endif 00148 states.pop(); 00149 states.push(newstate); 00150 DEBUGLOG(config, 00151 _T("current path = '%s', old path = '%s', depth = %d, id = %d, name = '%s'"), 00152 config->GetPath().c_str(), newstate.oldpath.c_str(), newstate.chdepth, 00153 newstate.leafid, newstate.group.c_str()); 00154 return newstate.leafid; 00155 } 00156 00157 00158 int configtree::toNextLeaf(const mutStringRef name, mutStringRef id) 00159 { 00160 #ifdef DEBUG 00161 DEBUGLOG(config,_T("going to next leaf of group '%s'"),name.c_str()); 00162 state oldstate=states.top(); 00163 wxASSERT(oldstate.group==name); 00164 DEBUGLOG(config, 00165 _T("current path = '%s', old path = '%s', depth = %d, id = %d, name = '%s'"), 00166 config->GetPath().c_str(), 00167 oldstate.oldpath.c_str(), oldstate.chdepth, 00168 oldstate.leafid, oldstate.group.c_str()); 00169 #endif 00170 toParent(1); 00171 toLeaf(name); 00172 state newstate = states.top(); 00173 #ifdef DEBUG 00174 DEBUGLOG(config, 00175 _T("current path = '%s', new old path = '%s', depth = %d, id = %d, name = '%s'"), 00176 config->GetPath().c_str(), 00177 newstate.oldpath.c_str(), 00178 newstate.chdepth, newstate.leafid, newstate.group.c_str()); 00179 wxASSERT(oldstate.oldpath == newstate.oldpath); 00180 newstate.group = oldstate.group; 00181 #endif 00182 bool found = config->GetNextGroup(id, newstate.leafid); 00183 if (found) { 00184 config->SetPath(id); 00185 newstate.chdepth++; 00186 } else newstate.leafid=wxNOT_FOUND; 00187 states.pop(); 00188 states.push(newstate); 00189 DEBUGLOG(config, 00190 _T("current path = '%s', new old path = '%s', depth = %d, id = %d, name = '%s'"), 00191 config->GetPath().c_str(), 00192 newstate.oldpath.c_str(), 00193 newstate.chdepth, newstate.leafid, 00194 newstate.group.c_str()); 00195 return newstate.leafid; 00196 } 00197 00198 00199 void configtree::toParent(unsigned int count) 00200 { 00201 DEBUGLOG(config,_T("going up %d level groups"),count); 00202 while (count--) { 00203 #ifdef DEBUG 00204 wxASSERT(states.size()); 00205 #endif 00206 if (!states.size()) { 00207 UNREACHABLEC; 00208 return; 00209 } 00210 state oldstate = states.top(); 00211 DEBUGLOG(config,_T("going up for %d levels"),oldstate.chdepth); 00212 while (oldstate.chdepth--) 00213 config -> SetPath(_T("..")); 00214 states.pop(); 00215 #ifdef DEBUG 00216 wxASSERT(config->GetPath() == oldstate.oldpath); 00217 #endif 00218 DEBUGLOG(config, 00219 _T("current path = '%s', old path = '%s', depth = %d, id = %d, name = '%s'"), 00220 config->GetPath().c_str(), 00221 oldstate.oldpath.c_str(), 00222 oldstate.chdepth, oldstate.leafid, 00223 oldstate.group.c_str()); 00224 } 00225 } 00226 00227 mutString configtree::GetPath() 00228 { 00229 return config -> GetPath(); 00230 } 00231 00232 void configtree::SetPath(const mutStringRef path) 00233 { 00234 DEBUGLOG(config,_T("setting path directly to '%s'"),path.c_str()); 00235 config->SetPath(path); 00236 } 00237 00238 00239 00240