#include "fiko/parametre/depo.hpp" #include #include "fiko/parametre/birim.hpp" namespace fiko::parametre { void ParametreDeposu::ayarla(const std::string& ad, const std::string& ifade, const std::string& birim) { if (Parametre* p = bul(ad)) { p->ifade = ifade; if (!birim.empty()) p->birim = birim; return; } parametreler_.push_back(Parametre{ad, ifade, birim, 0, false, ""}); } void ParametreDeposu::sil(const std::string& ad) { std::erase_if(parametreler_, [&](const Parametre& p) { return p.ad == ad; }); } Parametre* ParametreDeposu::bul(const std::string& ad) { for (auto& p : parametreler_) if (p.ad == ad) return &p; return nullptr; } const Parametre* ParametreDeposu::bul(const std::string& ad) const { for (auto& p : parametreler_) if (p.ad == ad) return &p; return nullptr; } bool ParametreDeposu::deger(const std::string& ad, f64& cikti) const { const Parametre* p = bul(ad); if (!p || !p->cozuldu) return false; cikti = p->deger; return true; } bool ParametreDeposu::degerBirimle(const std::string& ad, const std::string& hedefBirim, f64& cikti) const { const Parametre* p = bul(ad); if (!p || !p->cozuldu) return false; const CevirSonuc c = birimeCevir(p->deger, p->birim, hedefBirim); if (!c.basarili) return false; cikti = c.deger; return true; } bool ParametreDeposu::cozumle() { std::map cozulmus; for (auto& p : parametreler_) { p.cozuldu = false; p.hata.clear(); } // İlerleme oldukça tur at (topolojik): bağımlılıkları çözülmüş olanları çöz. bool ilerleme = true; while (ilerleme) { ilerleme = false; for (auto& p : parametreler_) { if (p.cozuldu || !p.hata.empty()) continue; bool hazir = true, hataliRef = false; for (const auto& d : bagimliliklar(p.ifade)) { if (cozulmus.count(d)) continue; // bağımlılık zaten çözülü if (!bul(d)) { // hiç var olmayan parametreye referans p.hata = "bilinmeyen parametre: " + d; hataliRef = true; break; } hazir = false; // var ama henüz çözülmedi → sonraki tur bekle } if (hataliRef) { ilerleme = true; continue; } if (!hazir) continue; const IfadeSonuc s = hesapla(p.ifade, cozulmus); if (!s.basarili) { p.hata = s.hata; } else { p.deger = s.deger; p.cozuldu = true; cozulmus[p.ad] = s.deger; } ilerleme = true; } } // Kalan çözülmemiş + hatasız = döngüsel bağımlılık (ya da hatalı-parametreye zincir). bool tumu = true; for (auto& p : parametreler_) { if (!p.cozuldu && p.hata.empty()) p.hata = "döngüsel bağımlılık / çözülemeyen referans"; if (!p.cozuldu) tumu = false; } return tumu; } } // namespace fiko::parametre