2012-12-08 19:59:05 +00:00
|
|
|
/*
|
|
|
|
* Context.cpp
|
|
|
|
*
|
|
|
|
* Created on: Dec 7, 2012
|
|
|
|
* Author: attero
|
|
|
|
*/
|
|
|
|
|
2012-12-30 13:59:30 +00:00
|
|
|
#include "ContextManager.h"
|
2012-12-08 19:59:05 +00:00
|
|
|
|
2012-12-30 13:59:30 +00:00
|
|
|
ContextManager::ContextManager() {
|
2012-12-30 21:37:10 +00:00
|
|
|
contexts["global"] = new Context("global");
|
2012-12-08 19:59:05 +00:00
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
2012-12-30 13:59:30 +00:00
|
|
|
ContextManager::~ContextManager() {
|
2012-12-08 19:59:05 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 21:37:10 +00:00
|
|
|
Context * ContextManager::create_new_context()
|
2012-12-08 19:59:05 +00:00
|
|
|
{
|
2012-12-30 21:37:10 +00:00
|
|
|
Context * context = new Context("Zdzislaw" + to_string(index));
|
2012-12-08 19:59:05 +00:00
|
|
|
index++;
|
2012-12-30 21:37:10 +00:00
|
|
|
contexts[context->name] = context;
|
|
|
|
return context;
|
2012-12-08 19:59:05 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 21:37:10 +00:00
|
|
|
Context * ContextManager::get_context(std::string name)
|
2012-12-08 19:59:05 +00:00
|
|
|
{
|
2012-12-30 21:37:10 +00:00
|
|
|
return contexts[name];
|
2012-12-08 19:59:05 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 21:37:10 +00:00
|
|
|
Context * ContextManager::context(std::string name)
|
2012-12-08 19:59:05 +00:00
|
|
|
{
|
2012-12-30 21:37:10 +00:00
|
|
|
if(contexts.count(name) != 0) return contexts[name];
|
|
|
|
else return nullptr;
|
2012-12-08 19:59:05 +00:00
|
|
|
}
|
|
|
|
|
2012-12-30 21:37:10 +00:00
|
|
|
void ContextManager::destroy_context(std::string name)
|
2012-12-08 19:59:05 +00:00
|
|
|
{
|
2012-12-30 21:37:10 +00:00
|
|
|
auto iter = contexts.find(name);
|
|
|
|
if(iter != contexts.end())
|
2012-12-09 11:57:51 +00:00
|
|
|
{
|
2012-12-30 21:37:10 +00:00
|
|
|
delete (*iter);
|
|
|
|
contexts.erase(iter);
|
2012-12-09 11:57:51 +00:00
|
|
|
}
|
2012-12-08 19:59:05 +00:00
|
|
|
}
|