2008-12-10 05:42:49 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dircontainer.h"
|
|
|
|
|
2008-12-21 22:17:09 +01:00
|
|
|
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
DirContainer::DirContainer()
|
|
|
|
{
|
2008-12-22 17:03:03 +01:00
|
|
|
is_root = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::Iterator DirContainer::GetRoot()
|
|
|
|
{
|
|
|
|
if( !is_root )
|
|
|
|
return table.end();
|
|
|
|
|
|
|
|
return table.begin() + root_index;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::Iterator DirContainer::Begin()
|
|
|
|
{
|
|
|
|
return table.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::Iterator DirContainer::End()
|
|
|
|
{
|
|
|
|
return table.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::SizeType DirContainer::Size()
|
|
|
|
{
|
|
|
|
return table.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DirContainer::Empty()
|
|
|
|
{
|
|
|
|
return table.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-22 17:03:03 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
void DirContainer::PushBack(const Item & item)
|
|
|
|
{
|
|
|
|
bool rebuild_indexes = false;
|
|
|
|
|
|
|
|
if( table.size() == table.capacity() )
|
|
|
|
rebuild_indexes = true;
|
|
|
|
|
2008-12-22 17:03:03 +01:00
|
|
|
|
|
|
|
if( item.parent_id == -1 )
|
|
|
|
{
|
|
|
|
if( is_root )
|
|
|
|
log << log1 << "DirCont: more than one root dir - skipped, id: " << item.id << logend;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
is_root = true;
|
|
|
|
root_index = table.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
table.push_back(item);
|
2008-12-31 14:36:46 +01:00
|
|
|
log << log2 << "DirCont: added dir, url: " << item.url << ", id: " << item.id << ", parent_id: " << item.parent_id << logend;
|
2008-12-22 17:03:03 +01:00
|
|
|
|
2008-12-10 05:42:49 +01:00
|
|
|
|
|
|
|
if( rebuild_indexes )
|
|
|
|
RebuildIndexes();
|
|
|
|
else
|
|
|
|
AddIndexes( --table.end() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DirContainer::Clear()
|
|
|
|
{
|
|
|
|
table.clear();
|
|
|
|
table_id.clear();
|
|
|
|
table_parent.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::Iterator DirContainer::FindId(long id)
|
|
|
|
{
|
|
|
|
TableId::iterator i = table_id.find(id);
|
|
|
|
|
|
|
|
if( i == table_id.end() )
|
|
|
|
return table.end();
|
|
|
|
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DirContainer::AddIndexes(Iterator item)
|
|
|
|
{
|
|
|
|
table_id.insert( std::make_pair(item->id, item) );
|
|
|
|
table_parent.insert( std::make_pair(item->parent_id, item) );
|
|
|
|
|
2008-12-31 14:36:46 +01:00
|
|
|
log << log2 << "DirCont: added indexes to dir, id: " << item->id << ", parent_id: " << item->parent_id << logend;
|
2008-12-10 05:42:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DirContainer::RebuildIndexes()
|
|
|
|
{
|
|
|
|
Iterator i;
|
|
|
|
|
|
|
|
log << log2 << "DirCont: rebuilding indexes" << logend;
|
|
|
|
|
|
|
|
table_id.clear();
|
|
|
|
table_parent.clear();
|
|
|
|
|
|
|
|
for(i=table.begin() ; i!=table.end() ; ++i)
|
|
|
|
AddIndexes( i );
|
|
|
|
|
|
|
|
log << log2 << "DirCont: indexes rebuilt, table.size: " << table.size() << ", table_id.size: " << table_id.size() << ", table_parent.size: " << table_parent.size() << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::ParentIterator DirContainer::ParentBegin()
|
|
|
|
{
|
|
|
|
return table_parent.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::ParentIterator DirContainer::ParentEnd()
|
|
|
|
{
|
|
|
|
return table_parent.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::ParentSizeType DirContainer::ParentSize()
|
|
|
|
{
|
|
|
|
return table_parent.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DirContainer::ParentEmpty()
|
|
|
|
{
|
|
|
|
return table_parent.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::ParentIterator DirContainer::FindFirstParent(long parent)
|
|
|
|
{
|
|
|
|
ParentIterator i = table_parent.lower_bound(parent);
|
|
|
|
|
|
|
|
if( i == table_parent.end() || i->first != parent )
|
|
|
|
return table_parent.end();
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DirContainer::ParentIterator DirContainer::NextParent(ParentIterator i)
|
|
|
|
{
|
|
|
|
if( i == table_parent.end() )
|
|
|
|
return table_parent.end();
|
|
|
|
|
|
|
|
long parent = i->first;
|
|
|
|
++i;
|
|
|
|
|
|
|
|
if( i == table_parent.end() || i->first != parent )
|
|
|
|
return table_parent.end();
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|