162 lines
2.7 KiB
C++
162 lines
2.7 KiB
C++
|
/*
|
||
|
* 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"
|
||
|
|
||
|
// !! tutaj ostatecznie ustawic wartosc np okolo 100
|
||
|
// chwilowo do testow ustawione 2
|
||
|
DirContainer::DirContainer()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
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();
|
||
|
}
|
||
|
|
||
|
|
||
|
void DirContainer::PushBack(const Item & item)
|
||
|
{
|
||
|
bool rebuild_indexes = false;
|
||
|
|
||
|
if( table.size() == table.capacity() )
|
||
|
rebuild_indexes = true;
|
||
|
|
||
|
table.push_back(item);
|
||
|
log << log2 << "DirCont: added item, id: " << item.id << ", parent_id: " << item.parent_id << logend;
|
||
|
|
||
|
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) );
|
||
|
|
||
|
log << log2 << "DirCont: added indexes to item, id: " << item->id << ", parent_id: " << item->parent_id << logend;
|
||
|
}
|
||
|
|
||
|
|
||
|
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;
|
||
|
}
|