winix/plugins/ticket/sessiondata.cpp

103 lines
1.6 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2012, Tomasz Sowa
* All rights reserved.
*
*/
#include "sessiondata.h"
namespace Ticket
{
SessionData::SessionData()
{
fun_rm = 0;
}
SessionData::~SessionData()
{
RemoveFiles(create_space_map);
RemoveFiles(edit_space_map);
}
void SessionData::RemoveFiles(SessionData::SpaceMap & space_map)
{
SpaceMap::iterator i;
if( fun_rm )
{
for(i=space_map.begin() ; i!=space_map.end() ; ++i)
RemoveFiles(i->second);
space_map.clear();
}
}
void SessionData::RemoveFiles(PT::Space & space)
{
for(size_t i=0 ; i<space.spaces.size() ; ++i)
{
PT::Space & sp = *space.spaces[i];
if( sp.name == L"param" )
{
// !! wywalic to do osobnej metody
for(size_t a=0 ; a<sp.spaces.size() ; ++a)
{
PT::Space & subsp = *sp.spaces[a];
if( subsp.name == L"file" )
{
std::wstring * file_id_str = subsp.GetValue(L"itemid");
if( file_id_str )
{
long file_id = Tol(*file_id_str);
fun_rm->RemoveItemById(file_id);
}
}
}
}
}
}
Ticket & SessionData::GetTicket(long id, SessionData::TicketMap & ticket_map, bool * is_new)
{
std::pair<TicketMap::iterator, bool> res = ticket_map.insert( std::make_pair(id, Ticket()) );
if( is_new )
*is_new = res.second;
return res.first->second;
}
PT::Space & SessionData::GetSpace(long id, SpaceMap & space_map, bool * is_new)
{
std::pair<SpaceMap::iterator, bool> res = space_map.insert( std::make_pair(id, PT::Space()) );
if( is_new )
*is_new = res.second;
return res.first->second;
}
} // namespace