📄 functionlookup.cpp
字号:
/*************************************************************************** functionlookup.cpp - description ------------------- copyright : (C) 2004 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. * * * ***************************************************************************/#include "functionlookup.h"#include "logging.h"#include <iostream>using namespace std;using namespace Amygdala;Table::Table(TableProperties& properties): AmygdalaClass(), tblData(0){ tblSize = properties.GetTableSize(); props = properties.Copy();}Table::Table(const Table& tbl): AmygdalaClass(){ tblSize = tbl.tblSize; props = tbl.props->Copy(); tblData = tbl.tblData;}Table::~Table(){ delete props;}float* Table::MakeTableData(){ tblData = new float[tblSize]; return tblData;}TableProperties::~TableProperties(){ timeParams.clear(); floatParams.clear();}TableProperties* TableProperties::Copy() const{ TableProperties* t = new TableProperties(*this); return t;}TableProperties::TableProperties(const TableProperties& props): AmygdalaClass(), tblSize(props.tblSize), clientClassName(props.clientClassName){ timeParams = props.timeParams; floatParams = props.floatParams;}void TableProperties::AddParam(AmTimeInt value){ timeParams.push_back(value);}void TableProperties::AddParam(float value){ floatParams.push_back(value);}bool TableProperties::operator==(const TableProperties& rhs) const{ if (clientClassName != rhs.clientClassName) { return false; } else if (tblSize != rhs.tblSize) { return false; } if (timeParams.size() == rhs.timeParams.size()) { for (unsigned int i=0; i<timeParams.size(); ++i) { if (timeParams[i] != rhs.timeParams[i]) { return false; } } } else { return false; } if (floatParams.size() == rhs.floatParams.size()) { for (unsigned int i=0; i<floatParams.size(); ++i) { if (floatParams[i] != rhs.floatParams[i]) { return false; } } } else { return false; } return true;}bool TableProperties::operator<(const TableProperties& rhs) const{ if (clientClassName != rhs.clientClassName) { return clientClassName < rhs.clientClassName; } else if (tblSize != rhs.tblSize) { return tblSize < rhs.tblSize; } if (timeParams.size() == rhs.timeParams.size()) { for (unsigned int i=0; i<timeParams.size(); ++i) { if (timeParams[i] != rhs.timeParams[i]) { //cout << "returning timeParams " << (bool)(timeParams[i] < rhs.timeParams[i]) << endl; //cout << timeParams[i] << " " << rhs.timeParams[i] << endl; LOGGER(6, "returning timeParams " << (bool)(timeParams[i] < rhs.timeParams[i])) return timeParams[i] < rhs.timeParams[i]; } } } else if (timeParams.size() < rhs.timeParams.size()) { return true; } if (floatParams.size() == rhs.floatParams.size()) { for (unsigned int i=0; i<floatParams.size(); ++i) { if (floatParams[i] != rhs.floatParams[i]) { //cout << "returning floatParams " << (bool)(floatParams[i] < rhs.floatParams[i]) << endl; //cout << floatParams[i] << " " << rhs.floatParams[i] << endl; LOGGER(6, "returning floatParams " << (bool)(floatParams[i] < rhs.floatParams[i])) return floatParams[i] < rhs.floatParams[i]; } } } else { return floatParams.size() < rhs.floatParams.size(); } return false;}FunctionLookup::FunctionLookup(){}FunctionLookup::~FunctionLookup(){ // delete the table data map<Table, float*>::iterator itr = lookups.begin(); while (itr != lookups.end()) { float* ptr = itr->second; delete [] ptr; itr++; }}const Table& FunctionLookup::GetTable(TableProperties& tableProps) const{ Table tmpTbl(tableProps); map<Table, float*>::const_iterator getItr = lookups.find(tmpTbl); if (getItr == lookups.end()) { throw TableNotFoundException(); } else { return getItr->first; }}bool FunctionLookup::TableExists(TableProperties& tableProps) const{ Table tmpTbl(tableProps); map<Table, float*>::const_iterator getItr = lookups.find(tmpTbl); if (getItr == lookups.end()) { return false; } else { return true; }}/*float* FunctionLookup::GetLookupTable(TableProperties& tableProps){ Table tmpTbl(tableProps); map<Table, float*>::const_iterator getItr = lookups.find(tmpTbl); if (getItr == lookups.end()) { return 0; } else { return getItr->second; }}*/float* FunctionLookup::MakeLookupTable(TableProperties& tableProps){ LOGGER(6, "Making lookup table") Table newTbl(tableProps); map<Table, float*>::const_iterator getItr = lookups.find(newTbl); if (getItr == lookups.end()) { LOGGER(6, "Making table data") float* tbl = newTbl.MakeTableData(); LOGGER(6, "Adding tbl to lookups map") lookups[newTbl] = tbl; LOGGER(6, "Returning tbl") return tbl; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -