#ifndef MT1Q2B_H #define MT1Q2B_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; Scope(Name n, Filename f, Type t, StartLine sl, EndLine el, Complexity c, ChildType ct) : _name(n), _file(f), _type(t), _start(sl), _end(el), _complexity(c), _childType(ct) {} Scope() {} 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; } static bool match(const Scope* pS1, const Scope* pS2); static bool more(const Scope* pS1, const Scope* pS2); private: Name _name = "unknown"; Filename _file = "unknown"; Type _type = "unknown"; StartLine _start = 0; EndLine _end = 0; Complexity _complexity = 0; ChildType _childType; }; inline bool Scope::match(const Scope* pS1, const Scope* pS2) { Scope s1Test = *pS1; Scope s2Test = *pS2; Scope::Size sizeTolerance = 2; bool sizeMatch = (s1Test.size() < s2Test.size() + sizeTolerance) && (s1Test.size() > s2Test.size() - sizeTolerance); Scope::Complexity complexityTolerance = 1; bool complexityMatch = (s1Test.complexity() < s2Test.complexity() + complexityTolerance) && (s1Test.complexity() > s2Test.complexity() - complexityTolerance); bool numberChildrenMatch = s1Test.numberChildren() == s2Test.numberChildren(); bool childTypeMatch = true; if (numberChildrenMatch) { for (size_t i = 0; i < s1Test.numberChildren(); ++i) { if (s1Test.childType()[i] != s2Test.childType()[i]) { childTypeMatch = false; break; } } } else { childTypeMatch = false; } return childTypeMatch && complexityMatch /*&& sizeMatch*/; } inline bool Scope::more(const Scope* pS1, const Scope* pS2) { Scope s1Test = *pS1; Scope s2Test = *pS2; return s1Test.complexity() > s2Test.complexity(); } #endif