Exemplo n.º 1
0
 inline utree operator/(utree const& a, utree const& b)
 {
     utree r = utree::visit(a, b, arithmetic_function_divides);
     if (r.which() == utree_type::invalid_type)
     {
         BOOST_THROW_EXCEPTION(bad_type_exception
           ("division performed on non-arithmetic utree types",
            a.which(), b.which()));
     }
     return r;
 }
Exemplo n.º 2
0
 inline utree operator<<(utree const& a, utree const& b)
 {
     utree r = utree::visit(a, b, integral_function_shift_left);
     if (r.which() == utree_type::invalid_type)
     {
         BOOST_THROW_EXCEPTION(bad_type_exception
           ("left shift performed on non-integral utree types",
            a.which(), b.which()));
     }
     return r;
 }
Exemplo n.º 3
0
    void operator() (utree const& ut) const {
        
        using spirit::utree_type;

        switch (ut.which()) {
            case utree_type::reference_type:
                return (*this)(ut.deref());

            case utree_type::range_type:
            case utree_type::list_type:
                if (annotations[ut.tag()].second == json_object) {
                    print_object(ut);
                    return;
                }
                else if (annotations[ut.tag()].second == json_array) {
                    print_array(ut);
                    return;
                }
                else if (annotations[ut.tag()].second == json_pair) {
                    print_member_pair(ut);
                    return;
                }

                default:
                    break;
        }

        utree::visit(ut, *this);
    }
Exemplo n.º 4
0
typename detail::get_impl<T>::type
get(utree const& x)
{
    if (x.which() != detail::get_utree_type<T>::value)
        throw boost::bad_get();

    return detail::get_impl<T>::call(x);
}
Exemplo n.º 5
0
    void operator() (utree const& ut){
        
        using spirit::utree_type;
        typedef utree::const_iterator iterator;
        
        int id = cur_id;
        n_id++;
        
        switch (ut.which()) {
            case utree_type::reference_type:
                out << prefix << id << " [label=\"[reference]\"];\n"; 
                out << prefix << id << " -> " << prefix << cur_id << ";\n";
                (*this)(ut.deref());
                return;

            case utree_type::range_type:
            case utree_type::list_type:
            {    
                iterator it, end;
                
                int start_id = n_id;
                
                if (annotations[ut.tag()].second == json_object) {
                    out << prefix << id << " [label=\"[object]\"];\n"; 
                    it    = ut.front().begin();
                    end   = ut.front().end();
                    n_id += ut.front().size();
                } else {
                    if (annotations[ut.tag()].second == json_array) {
                        out << prefix << id << " [label=\"[array]\"];\n"; 
                    } else if (annotations[ut.tag()].second == json_pair) {
                        out << prefix << id << " [label=\"[pair]\"];\n"; 
                    } else {
                        BOOST_ASSERT(false);
                        return;
                    }
                    it    = ut.begin();
                    end   = ut.end();
                    n_id += ut.size();
                }
                
                for (int i=0; it != end; ++it, ++i) {
                    
                    cur_id = start_id+i; 
                    out << prefix << id << " -> " << prefix << cur_id << ";\n";
                    (*this)(*it);   
                }
                
                return;
            }    
            default:
                break;
        }

        utree::visit(ut, *this);
    }
Exemplo n.º 6
0
 inline utree operator-(utree const& a)
 {
     utree r = utree::visit(a, arithmetic_function_negate);
     if (r.which() == utree_type::invalid_type)
     {
         BOOST_THROW_EXCEPTION(bad_type_exception
           ("negation performed on non-arithmetic utree type",
            a.which()));
     }
     return r;
 }
Exemplo n.º 7
0
 static type call (utree const& ut, parse_tree<Tag> const& pt) {
   using fusion::at_c;
   switch (ut.which()) {
     case utree_type::reference_type:
       return call(ut.deref());
     case utree_type::range_type:
     case utree_type::list_type:
       return at_c<1>(pt.annotations()[ut.tag()]);
     default:
       return -1; 
   }
 }
Exemplo n.º 8
0
utree expression::eval_node(utree const& node)
{
    //std::cout << node << " " << node.which() << " " << get_node_type(node) << "\n";
    
    if (node.which() == spirit::utree_type::list_type) {
        switch(get_node_type(node)) {
            case CARTO_EXP_PLUS:
                BOOST_ASSERT(node.size()==2);
                return eval_add( eval_node(node.front()), eval_node(node.back()) );
            case CARTO_EXP_MINUS:
                BOOST_ASSERT(node.size()==2);
                return eval_sub( eval_node(node.front()), eval_node(node.back()) );
            case CARTO_EXP_TIMES:
                BOOST_ASSERT(node.size()==2);
                return eval_mult( eval_node(node.front()), eval_node(node.back()) );
            case CARTO_EXP_DIVIDE:
                BOOST_ASSERT(node.size()==2);
                return eval_div( eval_node(node.front()), eval_node(node.back()) );
            case CARTO_EXP_NEG:
                BOOST_ASSERT(node.size()==1);
                return eval_mult( utree(-1.0), eval_node(node.back()) );
            case CARTO_EXP_FUNCTION:
                return eval_function(node);
            case CARTO_EXP_COLOR:
                BOOST_ASSERT(node.size()==4);
                return node;
            //case exp_var:
            //    return eval_var(node);
            default:
            {
                std::stringstream out;
                out << "Invalid expression node type: " << get_node_type(node);
                throw carto_error(out.str(), get_location(node));
            }
        }
    } else if (get_node_type(node) == CARTO_EXP_VAR) {
        return eval_var(node);
    }
    //} else {    
    //    std::cout << "Shouldn't be here!\n";
    //    std::cout << "Node: " << node << "\n";
    //    std::cout << "Node which: " << node.which() << "\n";
    //    std::cout << "Node type: " << get_node_type(node) << "\n";
    //    if (node.which() == spirit::utree_type::list_type)
    //        std::cout << "Node size: " << node.size() << "\n";
    //}
    
    return node;
}
Exemplo n.º 9
0
std::string filter_printer::operator() (utree const& ut)
{
    using spirit::utree_type;
    
    std::string out;
    
    if (ut.tag() == 0) {
        if (ut.which() == utree_type::list_type) {
            utree::const_iterator it = ut.begin(), end = ut.end();
            for (; it != end; ++it) 
                out += (*this)(*it);
        } else {
            out += as<std::string>(ut);
        }
        
        return out;
    }
    
    int const node_type = annotations[ut.tag()].second;
    
    typedef utree::const_iterator iter;
    iter it = ut.begin(),
        end = ut.end();
    
    if (node_type == filter_var || node_type == filter_var_attr) {
            
        utree value = parse_var(ut);
        
        if (node_type == filter_var_attr) 
            out += "[" + (*this)(value) + "]";
        else
            out += (*this)(value);
    } else if (node_type == filter_and) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        std::string b = (*this)(*it);
        
        if (a == "" || b == "")
            out += (a=="") ? a : b;
        else
            out += "(" + a + " and " + b + ")";

    } else if (node_type ==  filter_or) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        std::string b = (*this)(*it);
        
        if (a == "" || b == "")
            out += (a=="") ? a : b;
        else
            out += "(" + a + " or " + b + ")";
            
    } else if (node_type == filter_not) {
        BOOST_ASSERT(ut.size()==1);
        
        std::string a = (*this)(*it);
        
        if (a != "")
            out += "(not " + a + ")";
    } else if (node_type == filter_match) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        std::string b = (*this)(*it);
        
        out += a + ".match('" + b + "')";
        
    } else if (node_type == filter_replace) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        std::string b = (*this)(*it); it++;
        std::string c = (*this)(*it);
        
        out += a + ".replace('" + b + ", " + c + "')";
        
    } else if (node_type == filter_attribute) {
        //BOOST_ASSERT(ut.size()==1);
        out += "[" + (*this)(*it) + "]";
        
    } else if (node_type == filter_expression) {
        
    } else if (node_type == filter_eq) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        
        if (a == "[zoom]") {
            int b = round(parse_zoom_value(*it));
            rule.set_min_scale(zoom_ranges[b+1]);
            rule.set_max_scale(zoom_ranges[b]);
        } else {
            std::string b = (*this)(*it);
            out += "(" + a + " = " + b + ")";
        }
        
    } else if (node_type == filter_neq) {
        BOOST_ASSERT(ut.size()==2);

        std::string a = (*this)(*it); it++;

        if (a == "[zoom]") {
            std::string err = "Not equal is not currently supported for zoom levels (at "
                              + get_location(ut).get_string() + ")"; 
            throw config_error(err);
        } else {
            std::string b = (*this)(*it);
            out += "(" + a + " = " + b + ")";
        }
    } else if (node_type ==  filter_le) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        
        if (a == "[zoom]") {
            int b = round(parse_zoom_value(*it));
            rule.set_min_scale(zoom_ranges[b]);
        } else {
            std::string b = (*this)(*it);
            out += "(" + a + " = " + b + ")";
        }
        
    } else if (node_type ==  filter_lt) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        
        if (a == "[zoom]") {
            int b = round(parse_zoom_value(*it));
            rule.set_min_scale(zoom_ranges[b-1]);
        } else {
            std::string b = (*this)(*it);
            out += "(" + a + " = " + b + ")";
        }
        
    } else if (node_type ==  filter_ge) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        
        if (a == "[zoom]") {
            int b = round(parse_zoom_value(*it));
            rule.set_max_scale(zoom_ranges[b]);
        } else {
            std::string b = (*this)(*it);
            out += "(" + a + " = " + b + ")";
        }
        
    } else if (node_type == filter_gt) {
        BOOST_ASSERT(ut.size()==2);
        
        std::string a = (*this)(*it); it++;
        
        if (a == "[zoom]") {
            int b = round(parse_zoom_value(*it));
            rule.set_max_scale(zoom_ranges[b+1]);
        } else {
            std::string b = (*this)(*it);
            out += "(" + a + " = " + b + ")";
        }
        
    }
    
    return out;
}
Exemplo n.º 10
0
    void operator() (utree const& ut){
        
        using spirit::utree_type;
        typedef utree::const_iterator iterator;
        
        int id = cur_id;
        n_id++;
        
        switch (ut.which()) {
            case utree_type::reference_type:
                out << prefix << id << " [label=\"[reference]\"];\n"; 
                out << prefix << id << " -> " << prefix << cur_id << ";\n";
                (*this)(ut.deref());
                return;

            case utree_type::range_type:
            case utree_type::list_type:
            {    
                iterator it, end;
                
                int start_id = n_id;
                carto_node_type nope_type = annotations[ut.tag()].second;

                /*if (annotations[ut.tag()].second == json_object) {
                    out << prefix << id << " [label=\"[object]\"];\n"; 
                    it    = ut.front().begin();
                    end   = ut.front().end();
                    n_id += ut.front().size();
                }*/
                
                out << prefix << id << " [label=\"[";
                switch(node_type) {
                    case CARTO_UNDEFINED:
                        out << "";
                        break;
                    case CARTO_VARIABLE:
                        out << "variable";
                        break;
                    case CARTO_MIXIN:
                        OUT << "mixin";
                        break;
                    case CARTO_STYLE:
                        out << "style";
                        break;
                    case CARTO_FUNCTION:
                        out << "function";
                        break;
                    case CARTO_ATTRIBUTE:
                        out << "attribute";
                        break;
                    case CARTO_COLOR:
                        out << "color";
                        break;
                    case CARTO_FILTER:
                        out << "filter";
                        break;
                    default:
                        std::cout << node_type << std::endl;
                        BOOST_ASSERT(false);
                        //return;
                }
                out << "]\"];\n";
                
                it    = ut.begin();
                end   = ut.end();
                n_id += ut.size();
                
                if (node_type == CARTO_FILTER) {
                    for (int i=0; it != end; ++it, ++i) {
                    
                        cur_id = start_id+i;
                        out << prefix << id << " -> " << prefix << cur_id << ";\n";
                    
                        out << prefix << cur_id << " [label=\"";
                        generate_filter(*it,annotations,style_env(),out);
                        out << "\"];\n";
                    }
                    
                } else {                
                    for (int i=0; it != end; ++it, ++i) {
                    
                        cur_id = start_id+i; 
                        out << prefix << id << " -> " << prefix << cur_id << ";\n";
                        (*this)(*it);   
                    }
                }
                
                return;
            }    
            default:
                break;
        }
        
        utree::visit(ut, *this);
    }
Exemplo n.º 11
0
    void operator() (utree const& ut){
        
        using spirit::utree_type;
        typedef utree::const_iterator iterator;
        
        int id = cur_id;
        n_id++;
        
        switch (ut.which()) {
            case utree_type::reference_type:
                out << prefix << id << " [label=\"[reference]\"];\n"; 
                out << prefix << id << " -> " << prefix << cur_id << ";\n";
                (*this)(ut.deref());
                return;

            case utree_type::range_type:
            case utree_type::list_type:
            {    
                iterator it, end;
                
                int start_id = n_id;
                
                /*if (annotations[ut.tag()].second == json_object) {
                    out << prefix << id << " [label=\"[object]\"];\n"; 
                    it    = ut.front().begin();
                    end   = ut.front().end();
                    n_id += ut.front().size();
                }*/
                
                out << prefix << id << " [label=\"[";
                switch(annotations[ut.tag()].second) {
                    case carto_undefined:
                        out << "";
                        break;
                    case carto_variable:
                        out << "variable";
                        break;
                    case carto_mixin:
                        out << "mixin";
                        break;
                    case carto_style:
                        out << "style";
                        break;
                    case carto_function:
                        out << "function";
                        break;
                    case carto_attribute:
                        out << "attribute";
                        break;
                    case carto_color:
                        out << "color";
                        break;
                    case carto_filter:
                        out << "filter";
                        break;
                    default:
                        std::cout << annotations[ut.tag()].second << std::endl;
                        BOOST_ASSERT(false);
                        //return;
                }
                out << "]\"];\n";
                
                it    = ut.begin();
                end   = ut.end();
                n_id += ut.size();
                
                if (annotations[ut.tag()].second == carto_filter) {
                    for (int i=0; it != end; ++it, ++i) {
                    
                        cur_id = start_id+i;
                        out << prefix << id << " -> " << prefix << cur_id << ";\n";
                    
                        out << prefix << cur_id << " [label=\"";
                        generate_filter(*it,annotations,style_env(),out);
                        out << "\"];\n";
                    }
                    
                } else {                
                    for (int i=0; it != end; ++it, ++i) {
                    
                        cur_id = start_id+i; 
                        out << prefix << id << " -> " << prefix << cur_id << ";\n";
                        (*this)(*it);   
                    }
                }
                
                return;
            }    
            default:
                break;
        }
        
        utree::visit(ut, *this);
    }
Exemplo n.º 12
0
 bool empty() const
 {
     return f.which() != utree_type::function_type;
 }