SpikeStream Application Library  0.2
NetworksBuilder.cpp
Go to the documentation of this file.
00001 //SpikeStream includes
00002 #include "Globals.h"
00003 #include "NetworksBuilder.h"
00004 #include "SpikeStreamException.h"
00005 using namespace spikestream;
00006 
00007 
00009 NetworksBuilder::NetworksBuilder(){
00010         networkDao = NULL;
00011         archiveDao = NULL;
00012 }
00013 
00014 
00016 NetworksBuilder::~NetworksBuilder(){
00017 }
00018 
00019 
00020 /*----------------------------------------------------------*/
00021 /*-----                PRIVATE METHODS                 -----*/
00022 /*----------------------------------------------------------*/
00023 
00025 void NetworksBuilder::addTraining(unsigned int neuronID, QString trainingStr, bool output){
00026         //Create arry of appropriate length
00027         int arrLen;
00028         if(trainingStr.length() % 8 == 0)
00029                 arrLen = trainingStr.length() / 8;
00030         else
00031                 arrLen = trainingStr.length() / 8 + 1;
00032         unsigned char byteArr[arrLen];
00033 
00034         //Initialize array
00035         for(int i=0; i<arrLen; ++i)
00036                 byteArr[i] = 0;
00037 
00038         //Set bits corresponding to 1's in byte string
00039         for(int i=0; i<trainingStr.length(); ++i){
00040                 if(trainingStr[i] == '1')
00041                         byteArr[i/8] |= 1<<(i % 8);
00042         }
00043 
00044         //Add training to database
00045         networkDao->addWeightlessNeuronTrainingPattern(neuronID, byteArr, output, arrLen);
00046 }
00047 
00048 
00050 void NetworksBuilder::addConnectionGroup(unsigned int networkID, ConnectionGroup& connGrp){
00051         DBInfo netDBInfo = Globals::getNetworkDao()->getDBInfo();
00052         NetworkDaoThread netDaoThread(netDBInfo);
00053         netDaoThread.prepareAddConnectionGroup(networkID, &connGrp);
00054         runThread(netDaoThread);
00055 }
00056 
00057 
00059 void NetworksBuilder::runThread(NetworkDaoThread& thread){
00060         thread.start();
00061         thread.wait();
00062         if(thread.isError()){
00063                 throw SpikeStreamException(thread.getErrorMessage());
00064         }
00065 }
00066 
00067 
00069 void NetworksBuilder::clearError(){
00070         error = false;
00071         errorMessage = "";
00072 }
00073 
00074 
00076 void NetworksBuilder::setError(const QString &errMsg){
00077         errorMessage = errMsg;
00078         error = true;
00079 }
00080 
 All Classes Files Functions Variables Typedefs Friends Defines