Untitled
unknown
plain_text
a year ago
2.7 kB
2
Indexable
/** * \file allapotgep.cpp * * Ebben a fájlban kell megvalósítania az Allapotgep osztály * metódusait, valamint mindazon további osztályokat, melyek szükségesek * a feladat megvalósításához. * * Ezt a fájlt be kell adni (fel kell tölteni) a megoldással. */ #include <iostream> #include <fstream> #include <string.h> #include "allapotgep.h" #include "memtrace.h" /** * Konfig fájl beolvasása. Ha a fájl nem létezik/nem lehet megnyitni eldobja a NEPTUN-kódot. * Újra felépíti az állapotgépet, a korábbit törli ha volt. Kezdő állapotba áll. * @param fajlnév - fájl neve * @return - * @exception fájl megnyitási hiba esetén NEPTUN_KÓD */ void Allapotgep::konfigural(const char* fajlnev) { allapotok = NULL; mx = NULL; std::ifstream File(fajlnev); if (File.fail()) throw "GTD6KM"; char meret[10]; File.getline(meret, sizeof(meret)); this->N = meret[0] - '0'; this->allapotok = new Allapot[N]; char allbuff[20+1]; char* buff = new char[N*5]; char* part; for (size_t i = 0; i < N; i++) { File.getline(allbuff, sizeof(allbuff)); part = strtok(allbuff, " "); bool t = (part[0] == 'I') ? true : false; char* n = strtok(NULL, " "); allapotok[i].SetAllapot(t, n); } akt = 0; mx = new char**[N]; for (size_t i = 0; i < N; i++) { mx[i] = new char*[N]; for (size_t o = 0; o < N; o++) mx[i][o] = new char[4+1]; } for (size_t i = 0; i < N; i++) { File.getline(buff, N*5); part = strtok(buff, " "); strcpy(mx[i][0], part); for (size_t o = 1; o < N; o++) { part = strtok(NULL, " "); strcpy(mx[i][o], part); } } delete[] buff; File.close(); } const char* Allapotgep::aktualisallapot() { return allapotok[akt].GetNev(); } bool Allapotgep::elfogad() { return allapotok[akt].GetAll(); } void Allapotgep::atmenet(Bazis b) { int i = akt; for (size_t o = 0; o < N; o++) { if(strchr(mx[i][o], cast(b)) != NULL) { akt = o; } } } bool Allapotgep::feldolgoz(const Bazis *b, int n) { for (int i = 0; i < n; i++) { atmenet(b[i]); } return allapotok[akt].GetAll(); } void Allapotgep::alaphelyzet() { akt = 0; } Allapotgep::~Allapotgep() { if (allapotok != NULL) delete[] allapotok; if (mx != NULL) { for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < N; ++j) delete[] mx[i][j]; delete[] mx[i]; } delete[] mx; } }
Editor is loading...
Leave a Comment