table.cpp

来自「一段修改C语言的代码」· C++ 代码 · 共 133 行

CPP
133
字号
#include <assert.h>#include <vector>#include <string>using namespace std;#include "Table.h"/***************************************************Table************************************************************/Table::Table():    m_tab(){}Table::~Table(){}int Table::inserer(const char *nom, const char *type, newfloat valeur){    int pos;    Case elt;        if (getPosition(nom) != -1)        return -1;    pos = m_tab.size();    elt.nom = nom;    elt.type = type;    elt.valeur.d0 = valeur.d0;    elt.valeur.d1 = valeur.d1;    m_tab.push_back(elt);    return pos;}int Table::getPosition(const char *nom) const{    int pos = 0;    vectorCase::const_iterator p = m_tab.begin();        while ((p != m_tab.end()) && (p->nom != nom))    {        p++;        pos ++;    }    if (p == m_tab.end())        return -1;    else        return pos;        }const char * Table::getNom(unsigned int pos) const{    assert((pos >= 0) && (pos <= m_tab.size()-1));    return m_tab[pos].nom.c_str();}newfloat Table::getValeur(unsigned int pos) const{    assert((pos >= 0) && (pos <= m_tab.size()-1));    return m_tab[pos].valeur;}const char * Table::getType(unsigned int pos) const{    assert((pos >= 0) && (pos <= m_tab.size()-1));    return m_tab[pos].type.c_str();}   void Table::setValeur(unsigned int pos, newfloat elt){    assert((pos >= 0) && (pos <= m_tab.size()-1));    m_tab[pos].valeur = elt;}void Table::clear(){	m_tab.clear();}/********************************************************************************************************************//****************************************************Func************************************************************/Func::Func():    m_func(){}Func::~Func(){}int Func::inserer(const FuncStr f){	int pos;	const char * nom = f.nom.c_str();	if (getPosition(nom) != -1)		return -1;	pos = m_func.size();    	m_func.push_back(f);	return pos;}int Func::getPosition(const char *nom) const{	int pos = 0;	Function::const_iterator p = m_func.begin();    	while ((p != m_func.end()) && (p->nom != nom))	{		p++;		pos ++;	}	if (p == m_func.end())		return -1;	else		return pos;}/********************************************************************************************************************/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?