const std::vector<HSSDisplayObject::p> AXRController::selectSimple(const std::vector<HSSDisplayObject::p> & scope)
{
    std::vector<HSSDisplayObject::p> ret;
    unsigned i, size;
    HSSParserNodeType selectorType = this->currentSelectorNode->getType();
    switch (selectorType) {
        case HSSParserNodeTypeSelector:
        {
            //select only elements with matching element name
            HSSSelector::p selector = boost::static_pointer_cast<HSSSelector>(this->currentSelectorNode);
            for (i=0, size=scope.size(); i<size; i++) {
                if(scope[i]->getElementName() == selector->getElementName()){
                    ret.push_back(scope[i]);
                }
            }
            break;
        }
        
        case HSSParserNodeTypeUniversalSelector:
        {
            //the entire scope will be selected
            ret = scope;
            break;
        }
        
        default:
            throw "unexpected selector node type";
            break;
    }
    
    return ret;
}
Esempio n. 2
0
std::vector< std::vector<HSSDisplayObject::p> > AXRController::selectSimple(const std::vector<HSSDisplayObject::p> & scope, HSSDisplayObject::p thisObj, bool negating, bool processing)
{
    std::vector< std::vector<HSSDisplayObject::p> >ret;
    std::vector<HSSDisplayObject::p> currentSelection;
    
    unsigned i, size;
    HSSParserNodeType selectorType = this->currentSelectorNode->getType();
    switch (selectorType) {
        case HSSParserNodeTypeSelector:
        {
            //select only elements with matching element name
            HSSSelector::p selector = boost::static_pointer_cast<HSSSelector>(this->currentSelectorNode);
            for (i=0, size=scope.size(); i<size; i++) {
                bool match = scope[i]->getElementName() == selector->getElementName();
                if((match && !negating) || (!match && negating) ){
                    currentSelection.push_back(scope[i]);
                }
            }
            //we're done negating for now
            negating = false;
            
            this->readNextSelectorNode();
            break;
        }
        
        case HSSParserNodeTypeUniversalSelector:
        {
            if(negating){
                //nothing will be selected
            } else {
                //the entire scope will be selected
                currentSelection = scope;
            }
            //we're done negating for now
            negating = false;
            this->readNextSelectorNode();
            break;
        }
            
        case HSSParserNodeTypeFilter:
        case HSSParserNodeTypeFlag:
        {
            //the entire scope will be selected
            currentSelection = scope;
            break;
        }
            
        case HSSParserNodeTypeThisSelector:
        {
            if(negating){
                throw AXRError::p(new AXRError("AXRController", "Cannot negate the @this object "));
            }
            const HSSDisplayObject::p tobjArr[1] = {thisObj};
            const std::vector<HSSDisplayObject::p>tobjScope(tobjArr, tobjArr+1);
            currentSelection = tobjScope;
            this->readNextSelectorNode();
            //we're done negating for now
            negating = false;
            break;
        }
            
        case HSSParserNodeTypeNegation:
        {
            HSSNegation::p negation = boost::static_pointer_cast<HSSNegation>(this->currentSelectorNode);
            this->readNextSelectorNode();
            return this->selectSimple(scope, thisObj, true, processing);
        }
        
        default:
            throw AXRError::p(new AXRError("AXRController", "Unknown node type "+HSSParserNode::parserNodeStringRepresentation(selectorType)+" in selector"));
    }
    
    ret = this->filterSelection(currentSelection, negating, processing);
    
    return ret;
}