📄 functionlookup.cpp
字号:
/*************************************************************************** functionlookup.cpp - description ------------------- copyright : (C) 2000 by Matt Grover email : mgrover@amygdala.org ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/using namespace std;#include <iostream.h>#include <string>#include <typeinfo>#include "functionlookup.h"FunctionLookup::FunctionLookup(){}FunctionLookup::~FunctionLookup(){ unsigned int i; // Delete the data arrays and param arrays. // Any neurons using these should have been // deleted by now. for (i=0; i<lookup.size(); i++) { delete [] lookup[i].data; delete [] lookup[i].params; } lookup.clear();}float* FunctionLookup::GetLookupTable(Neuron* reqNrn, int tableIdx, int tableSize, int stepSize){ int i, j; int numTableParams = 0; float* tableParams = 0; bool fndMatch = false, contSearch = false; tableData tmpElement; string nrnName; nrnName = typeid(*reqNrn).name(); // Use nrnId, tableIdx, size, stepsize and tableparms (make call to reqNrn // for these) to determine if a table exists for this type of neuron. If // so, then return a pointer to it, otherwise make a call to reqNrn to // fill the table, store it in lookup[i].data, and then return a pointer. for (i=0; i<signed(lookup.size()); i++) { contSearch = true; tmpElement = lookup[i]; if ( tmpElement.nrnType == nrnName ) { if ( (contSearch) && (tableIdx == tmpElement.index) ) { contSearch = true; } else { contSearch = false; } if ( (contSearch) && (tableSize == tmpElement.size) ) { contSearch = true; } else { contSearch = false; } if ( (contSearch) && (stepSize == tmpElement.stepSize) ) { contSearch = true; } else { contSearch = false; } tableParams = reqNrn->GetTableParams(tableIdx, numTableParams); if (tableParams) { if ( (contSearch) && (numTableParams == tmpElement.numParams) ) { for (j=0; j<numTableParams; j++) { if (tableParams[j] != tmpElement.params[j]) { contSearch = false; break; } } } else { contSearch = false; } } else { // this is a problem -- do something to handle it here! fndMatch = false; break; } // If all the tests passed, then we're through if (contSearch) { fndMatch = true; break; } } } // Fill the lookup table and store it if no match was found. // The data and params arrays are allocated by the neuron, but // FunctionLookup is responsible for deleting them because they // are shared by many neurons. if (!fndMatch) { tmpElement.index = tableIdx; tmpElement.nrnType = nrnName; tmpElement.size = tableSize; tmpElement.stepSize = stepSize; if (!numTableParams) { tableParams = reqNrn->GetTableParams(tableIdx, numTableParams); } tmpElement.numParams = numTableParams; tmpElement.params = tableParams; tmpElement.data = reqNrn->InitializeLookupTable(tableIdx); //cout << "Inserting a table...\n"; lookup.insert(lookup.begin(), tmpElement); i = 0; } return lookup[i].data;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -