// // refract/IsExpandableVisitor.cc // librefract // // Created by Jiri Kratochvil on 21/05/15. // Copyright (c) 2015 Apiary Inc. All rights reserved. // #include "Element.h" #include "IsExpandableVisitor.h" namespace refract { namespace { struct CheckElement { bool checkElement(const IElement* e) const { std::string type; if (e) { type = e->element(); } return !isReserved(type) || type == "ref" ; } }; template struct IsExpandable : public CheckElement { bool operator()(const T* e) const { if (checkElement(e)) { return true; } return false; } }; template struct IsExpandable : public CheckElement { bool operator()(const T* e) const { if (checkElement(e)) { return true; } for (std::vector::const_iterator i = e->value.begin() ; i != e->value.end() ; ++i ) { IsExpandableVisitor v; VisitBy(*(*i), v); if (v.get()) { return true; } } return false; } }; template struct IsExpandable : public CheckElement { bool operator()(const T* e) const { if (checkElement(e)) { return true; } if (e->value.first) { IsExpandableVisitor v; VisitBy(*e->value.first, v); if (v.get()) { return true; } } if (e->value.second) { IsExpandableVisitor v; VisitBy(*e->value.second, v); if (v.get()) { return true; } } return false; } }; template struct IsExpandable : public CheckElement { bool operator()(const T* e) const { if (checkElement(e)) { return true; } for (std::vector::const_iterator i = e->value.begin() ; i != e->value.end() ; ++i ) { IsExpandableVisitor v; VisitBy(*(*i), v); if (v.get()) { return true; } } return false; } }; } // anonymous namespace IsExpandableVisitor::IsExpandableVisitor() : result(false) {} template void IsExpandableVisitor::operator()(const T& e) { result = IsExpandable()(&e); } template<> void IsExpandableVisitor::operator()(const IElement& e) { VisitBy(e, *this); } // Explicit instantioning of templates to avoid Linker Error template void IsExpandableVisitor::operator()(const NullElement&); template void IsExpandableVisitor::operator()(const StringElement&); template void IsExpandableVisitor::operator()(const NumberElement&); template void IsExpandableVisitor::operator()(const BooleanElement&); template void IsExpandableVisitor::operator()(const ArrayElement&); template void IsExpandableVisitor::operator()(const EnumElement&); template void IsExpandableVisitor::operator()(const MemberElement&); template void IsExpandableVisitor::operator()(const ObjectElement&); template void IsExpandableVisitor::operator()(const ExtendElement&); template void IsExpandableVisitor::operator()(const OptionElement&); template void IsExpandableVisitor::operator()(const SelectElement&); bool IsExpandableVisitor::get() const { return result; } }; // namespace refract