#include "TKLog.h"
#include <string>
-TKCell::TKCell(TKContainer *container, std::string location, std::string name)
-: mContainer(container), mAxon(NULL), mCellCode(NULL), mLocation(location), mName(name)
+TKCell::TKCell(TKContainer *container, std::string location, std::string name, bool canIntarface)
+: mName(name), mLocation(location), mContainer(container), mAxon(NULL), mCellCodeInstance(NULL), mCanInterface(canIntarface)
{
- mAxon = new TKAxon(this);
}
TKCell::~TKCell()
{
- for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
- delete it->second;
- }
- mReceptors.clear();
-
+ if (mCellCodeInstance)
+ {
+ delete mCellCodeInstance;
+ mCellCodeInstance = NULL;
+ }
+
+ for ( TKReceptorMap::iterator it = mReceptors.begin(); it != mReceptors.end(); ++it ) {
+ delete it->second;
+ }
+ mReceptors.clear();
+
+ if (mAxon)
+ {
+ delete mAxon;
+ mAxon = NULL;
+ }
+}
+
+void TKCell::init()
+{
+ if (!mAxon)
+ mAxon = mContainer->axonFactory(this);
}
float TKCell::getAxonValue()
{
if (!mAxon)
return 0.0;
- return mAxon->value;
+ return mAxon->getValue();
}
void TKCell::setAxonValue(float value)
{
if (!mAxon)
return;
- mAxon->value = value;
+ mAxon->setValue(value);
}
bool TKCell::setCellCode(TKCellCode *code, const void *data)
{
- mCellCode = code->createCellCodeInstance(this, data);
- mCellCode->doInit();
-
- return true;
+ mCellCodeInstance = code->createCellCodeInstance(this, data);
+ return mCellCodeInstance != NULL;
}
bool TKCell::connectTo(std::string connectionName, TKCell *targetCell)
{
- TKReceptor *receptor = targetCell->createReceptor(connectionName);
- TKAxonTerminal *terminal = mAxon->addTerminal();
- receptor->setTarget(terminal);
-
- return true;
+ TKReceptor *receptor = targetCell->createReceptor(connectionName);
+ if (receptor)
+ {
+ TKAxonTerminal *terminal = mAxon->addTerminal();
+ receptor->setTarget(terminal);
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
}
TKReceptor* TKCell::createReceptor(std::string name)
TKReceptorMap::iterator it = mReceptors.find(name);
if (it != mReceptors.end())
{
- receptor = it->second;
+ receptor = NULL;
}
else
{
- receptor = new TKReceptor(this);
+ receptor = mContainer->receptorFactory(this);
if (receptor)
{
mReceptors.insert( TKReceptorMap::value_type( name, receptor ) );
}
}
-
+
return receptor;
}