|
#include <stdafx.h>
#include "MetaModelUtilities.h"
using namespace std;
RootFinder::RootMap RootFinder::findRootOf(const smart_ptr<Inheritable> &i)
{
typedef list<smart_ptr<Inheritable> >::const_iterator Iterator;
RootMap result;
if(i->getParents().empty()) {
list<smart_ptr<Inheritable> > tmp;
tmp.push_back(i);
result.insert(make_pair(0, tmp));
} else {
for(Iterator x = i->getParents().begin(); x != i->getParents().end(); ++x) {
RootMap tmp = findRootOf(*x);
for(RootMap::iterator aRoot = tmp.begin(); aRoot != tmp.end(); ++aRoot) {
result.insert(make_pair(aRoot->first+1, aRoot->second));
}
}
}
return result;
}
typedef list<smart_ptr<Inheritable> > PoEList;
bool IsRelativeOf::operator()(const smart_ptr<Inheritable> &r1, const smart_ptr<Inheritable> &r2) const
{
return isParentOf(r1, r2) || isExtendorOf(r1, r2);
}
bool IsRelativeOf::isParentOf(const smart_ptr<Inheritable> &parent, const smart_ptr<Inheritable> &child)
{
if(parent->equals(*child)) {
return true;
}
for(PoEList::const_iterator candidate = child->getParents().begin(); candidate != child->getParents().end(); ++candidate) {
if(isParentOf(parent, *candidate)) {
return true;
}
}
return false;
}
bool IsRelativeOf::isExtendorOf(const smart_ptr<Inheritable> &child, const smart_ptr<Inheritable> &parent)
{
if(parent->equals(*child)) {
return true;
}
for(PoEList::const_iterator candidate = parent->getExtendors().begin(); candidate != parent->getExtendors().end(); ++candidate) {
if(isExtendorOf(child, *candidate)) {
return true;
}
}
return false;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.