refactoring

git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@523 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-11-17 01:04:01 +00:00
parent 2ca44ec361
commit dc5f002de3
17 changed files with 101 additions and 370 deletions

View File

@@ -60,34 +60,6 @@ void Dirs::ReadDirs()
}
bool Dirs::GetRootDir(Item ** item)
{
DirContainer::Iterator root = dir_table.GetRoot();
if( root == dir_table.End() )
return false;
*item = &(*root);
return true;
}
bool Dirs::GetDir(const std::string & name, long parent, Item ** item)
{
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
for( ; i!=dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
if( i->second->url == name )
{
*item = &(*i->second);
return true;
}
return false;
}
bool Dirs::ExtractName(const char * & s, std::string & name)
{
name.clear();
@@ -103,62 +75,6 @@ return !name.empty();
// !! moze lepiej zwracac wskaznik do Item i kiedy nie ma katalogu to zwracac 0 ?
bool Dirs::GetDir(const std::string & path, Item ** item)
{
DirContainer::Iterator root = dir_table.GetRoot();
if( root == dir_table.End() )
// ops, we do not have a root dir
return false;
Item * pitem = &(*root);
std::string name;
const char * s = path.c_str();
while( ExtractName(s, name) )
{
if( !GetDir(name, pitem->id, &pitem) )
return false;
}
*item = pitem;
return true;
}
// !! ten interfejs jes bylejaki
// !! moze lepiej zwracac id i kiedy nie ma katalogu to -1 (przeciez to jest wartosc ktora nie moze pojawic sie w indeksie)
bool Dirs::GetDirId(const std::string & path, long * id)
{
Item * pitem;
if( !GetDir(path, &pitem) )
return false;
*id = pitem->id;
return true;
}
bool Dirs::GetDirId(const std::string & name, long parent, long * id)
{
Item * pitem;
if( !GetDir(name, parent, &pitem) )
return false;
*id = pitem->id;
return true;
}
bool Dirs::IsDir(long id)
@@ -174,20 +90,6 @@ return true;
bool Dirs::GetDirChilds(long parent, std::vector<Item> & childs_table)
{
if( parent != -1 && !IsDir(parent) )
return false;
DirContainer::ParentIterator i = dir_table.FindFirstParent(parent);
for( ; i != dir_table.ParentEnd() ; i = dir_table.NextParent(i) )
childs_table.push_back( *i->second );
return true;
}
bool Dirs::GetDirChilds(long parent, std::vector<Item*> & childs_table)
{
if( parent != -1 && !IsDir(parent) )
@@ -232,55 +134,6 @@ DirContainer::Iterator i;
// with exceptions
Item * Dirs::GetDirT(const std::string & path)
{
Item * pitem;
if( !GetDir(path, &pitem) )
throw Error(Error::incorrect_dir);
return pitem;
}
Item * Dirs::GetDirT(const std::string & name, long parent)
{
Item * pitem;
if( !GetDir(name, parent, &pitem) )
throw Error(Error::incorrect_dir);
return pitem;
}
long Dirs::GetDirIdT(const std::string & path)
{
long id;
if( !GetDirId(path, &id) )
throw Error(Error::incorrect_dir);
return id;
}
long Dirs::GetDirIdT(const std::string & name, long parent)
{
long id;
if( !GetDirId(name, parent, &id) )
throw Error(Error::incorrect_dir);
return id;
}
// !! nowy interfejs
@@ -417,8 +270,7 @@ void Dirs::DeleteDir(long id)
if( db.DelDirById(id) == Error::ok )
dir_table.DelById(id);
if( data.mounts.CurrentMountType() == Mount::thread )
db.RemoveThread(id);
db.RemoveThread(id);
}