#ifndef MT2Q2B_H #define MT2Q2B_H ///////////////////////////////////////////// // MT2Q2b.h - Scope class #include #include class Scope { public: using Name = std::string; using Filename = std::string; using Type = std::string; using StartLine = size_t; using EndLine = size_t; using Size = size_t; using Complexity = size_t; using NumberChildren = size_t; using ChildType = std::vector; Name& name() { return _name; } Filename& file() { return _file; } Type& type() { return _type; } StartLine& start() { return _start; } EndLine& end() { return _end; } Size size() const { return _end - _start + 1; } Complexity& complexity() { return _complexity; } NumberChildren numberChildren() const { return _childType.size(); } ChildType& childType() { return _childType; } private: Name _name = "unknown"; Filename _file = "unknown"; Type _type = "unknown"; StartLine _start = 0; EndLine _end = 0; Complexity _complexity = 0; ChildType _childType; }; class Compare { public: static bool match(Scope* pS1, Scope* pS2); static bool more(Scope* pS1, Scope* pS2); }; inline bool Compare::match(Scope* pS1, Scope* pS2) { if (pS1->type() != pS2->type()) return false; Scope::Size sizeTolerance = 2; bool sizeMatch = (pS1->size() < pS2->size() + sizeTolerance) && (pS1->size() > pS2->size() - sizeTolerance); Scope::Complexity complexityTolerance = 1; bool complexityMatch = (pS1->complexity() < pS2->complexity() + complexityTolerance) && (pS1->complexity() > pS2->complexity() - complexityTolerance); bool numberChildrenMatch = pS1->numberChildren() == pS2->numberChildren(); bool childTypeMatch = true; if (numberChildrenMatch) { for (size_t i = 0; i < pS1->numberChildren(); ++i) { if (pS1->childType()[i] != pS2->childType()[i]) { childTypeMatch = false; break; } } } else { childTypeMatch = false; } return childTypeMatch && complexityMatch /*&& sizeMatch*/; } inline bool Compare::more(Scope* pS1, Scope* pS2) { return pS1->complexity() > pS2->complexity(); } #endif