#pragma once #include "PolyglotStackTraceDecoder.h" #include #include namespace whetstone { class LanguageSeamFrameDetector { public: // Returns indices of all frames where isBoundary == true. std::vector detectSeams(const std::vector& frames) const { std::vector seams; for (int i = 0; i < static_cast(frames.size()); ++i) if (frames[i].isBoundary) seams.push_back(i); return seams; } // Index of first seam frame, -1 if none. int primarySeam(const std::vector& frames) const { for (int i = 0; i < static_cast(frames.size()); ++i) if (frames[i].isBoundary) return i; return -1; } int seamCount(const std::vector& frames) const { return static_cast(detectSeams(frames).size()); } // Unique languages in order of first appearance. std::vector frameLanguages(const std::vector& frames) const { std::vector result; for (const auto& f : frames) { bool found = false; for (const auto& l : result) if (l == f.language) { found = true; break; } if (!found) result.push_back(f.language); } return result; } // True if any adjacent pair transitions from fromLang to toLang. bool crossesBoundary(const std::vector& frames, const std::string& fromLang, const std::string& toLang) const { for (std::size_t i = 0; i + 1 < frames.size(); ++i) if (frames[i].language == fromLang && frames[i+1].language == toLang) return true; return false; } }; } // namespace whetstone