winix/core/plugindata.cpp

126 lines
1.6 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#include "plugindata.h"
#include "plugin.h"
#include "log.h"
void PluginData::Assign(size_t index, PluginDataBase * data)
{
if( index >= table.size() )
Resize(index+1);
table[index] = data;
}
void PluginData::Assign(PluginDataBase * data)
{
if( plugin.current_plugin == -1 )
{
log << log1 << "PD: Assign(PluginDataBase*) should be called only from plugins" << logend;
return;
}
Assign(plugin.current_plugin, data);
}
PluginDataBase * PluginData::Get(size_t index)
{
if( index >= table.size() )
Resize(index+1);
return table[index];
}
PluginDataBase * PluginData::Get()
{
if( plugin.current_plugin == -1 )
{
log << log1 << "PD: Get() should be called only from plugins" << logend;
return 0;
}
return Get(plugin.current_plugin);
}
void PluginData::DeleteAll()
{
if( table.empty() )
return;
plugin.Call(WINIX_SESSION_REMOVE);
for(size_t i=0 ; i<table.size() ; ++i)
table[i] = 0;
}
PluginData::PluginData()
{
}
PluginData::PluginData(const PluginData & p)
{
operator=(p);
}
PluginData & PluginData::operator=(const PluginData & p)
{
// we don't copy all pointers - only resize the table
// pointers will be set to zero
Resize(p.Size());
return *this;
}
PluginData::~PluginData()
{
DeleteAll();
}
size_t PluginData::Size() const
{
return table.size();
}
void PluginData::Resize(size_t new_size)
{
size_t old_size = table.size();
if( old_size == new_size )
return;
table.resize(new_size);
for(size_t i = old_size ; i<new_size ; ++i)
table[i] = 0;
}