📄 functionlookup.h
字号:
/*************************************************************************** functionlookup.h - description ------------------- copyright : (C) 2001, 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. * * * ***************************************************************************/#ifndef FUNCTIONLOOKUP_H#define FUNCTIONLOOKUP_H#include <map>#include <vector>#include <string>#include <amygdala/properties.h>#include <amygdala/amygdalaclass.h>namespace Amygdala { /** @class TableProperties functionlookup.h amygdala/functionlookup.h * A container for values that can be used to identify a particular * lookup table in FunctionLookup. Lookup tables are identified by * a class name and a set of integer and float values that are unique * to that table. The integer and float parameters should generally be * the same values used by the function that generates the table (for example, * time constant values). * @author Matt Grover <mgrover@amygdala.org> */class TableProperties: public AmygdalaClass {public: TableProperties():tblSize(0) {} /** Copy constructor */ TableProperties(const TableProperties& props); virtual ~TableProperties(); virtual bool operator==(const TableProperties& rhs) const; /** Less-than operator needed for map comparisons in FunctionLookup */ virtual bool operator<(const TableProperties& rhs) const; /** Make a new copy of this object */ virtual TableProperties* Copy() const; /** @return Number of elements in the table */ unsigned int GetTableSize() const { return tblSize; } /** Set the table size */ void SetTableSize(unsigned int size) { tblSize = size; } /** Add an integer parameter */ void AddParam(AmTimeInt value); /** Add a float parameter */ void AddParam(float value); /** Set the name of the class that is storing a table in FunctionLookup */ void SetClassName(std::string name) { clientClassName = name; } /** @return The name of a class storing a table in FunctionLookup */ std::string GetClassName() const { return clientClassName; }protected: unsigned int tblSize; std::vector<AmTimeInt> timeParams; std::vector<float> floatParams; std::string clientClassName;private:};class TableComp {public: TableComp() {} ~TableComp() {} bool operator()(const TableProperties* lhs, const TableProperties* rhs) { return (*lhs) < (*rhs); }};class Table: public AmygdalaClass {public: Table(TableProperties& properties); Table(const Table& tbl); ~Table(); float* MakeTableData(); float* GetTableData() const { return tblData; } unsigned int GetSize() const { return tblSize; } inline bool operator<(const Table& rhs) const; inline bool operator==(const Table& rhs) const;protected: TableProperties* props; unsigned int tblSize; float* tblData;};/** @class FunctionLookup functionlookup.h amygdala/functionlookup.h * @brief FunctionLookup is a container class for the lookup tables * @author Matt Grover */class FunctionLookup: public AmygdalaClass {public: FunctionLookup(); ~FunctionLookup(); /** This will check to see * if a table with the given parameters (and some additional * parameters in reqNrn) already exists. If a matching table * does not exist, a new one will be created. * @returns Reference to a lookup table.Throws TableNotFoundException if a table matching * tableProps can not be found. */ const Table& GetTable(TableProperties& tableProps) const; float* GetTableData(TableProperties& tableProps) const { return GetTable(tableProps).GetTableData(); } bool TableExists(TableProperties& tableProps) const; /** Allocate space for a table and add it to the collection. * The calling class is responsible for actually populating the table * with values. * @returns Pointer to the newly allocated table. Returns 0 if the * table could not be created. */ float* MakeLookupTable(TableProperties& tableProps);private: std::map<Table, float*> lookups; // the float in here is the same as Table.tblData;};class TableNotFoundException: public AmygdalaClass {public: TableNotFoundException() {} ~TableNotFoundException() {}};bool Table::operator<(const Table& rhs) const{ return *props < *(rhs.props);}bool Table::operator==(const Table& rhs) const{ return *props == *(rhs.props);}} // namespace Amygdala#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -