import the first version of cmslu
git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@460 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
161
core/dircontainer.cpp
Executable file
161
core/dircontainer.cpp
Executable file
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
Reference in New Issue
Block a user