Exemple #1
0
void BNetParser::start_element(const unsigned long line_number, const std::string& name, const dlib::attribute_list& atts)
{
	const char *cname = name.c_str(); // Should be able to just use string == "" according to some guy at StackOverflow
	if (strcmp(cname, "cpt") == 0)
	{
		// start of new node element
		currentNode = new ParsedNode();
		atts.reset();
		atts.move_next();
		std::string nodename = atts.element().value();
		currentNode->name = nodename;
	}
	else if (strcmp(cname, "state") == 0)
	{
		// start of new state element
		atts.reset();
		atts.move_next();
		std::string statename = atts.element().value();
		currentNode->states.push_back(statename);
	}
	else if (strcmp(cname, "parents") == 0)
	{
		// start of new parents element
		waitingForProbs = 0;
		// Prepare to receive parents in "characters" function
	}
	else if (strcmp(cname, "probabilities") == 0)
	{
		// start of new probabilities element
		waitingForProbs = 1;
		// Prepare to receive probabilities in "characters" function
	}
}
 virtual void start_element (
         const unsigned long,
         const std::string& name,
         const dlib::attribute_list& atts) override
 {
     if(name == "image"){
         atts.reset();
         if(atts.move_next()){
             img_name_.emplace_back(atts.element().value());
             location_.emplace_back();
         }
     }else if(name == "box"){
         atts.reset();
         dlib::rectangle rect;
         long h = 0;
         enum {height, left, top, width};
         for(size_t index = 0; atts.move_next(); ++index){
             switch(index){
             case height :{
                 h = std::stol(atts.element().value()) - 1;
                 h = std::max<long>(0, h);
                 break;
             }
             case left :{
                 rect.set_left(std::stol(atts.element().value()));
                 break;
             }
             case top :{
                 rect.set_top(std::stol(atts.element().value()));
                 break;
             }
             case width:{
                 rect.set_right(rect.left() + std::stol(atts.element().value()) - 1);
                 rect.set_right(std::max<long>(0, rect.right()));
                 break;
             }
             default:{
                 break;
             }
             }
         }
         rect.set_bottom(rect.top() + h);
         location_.back().emplace_back(rect);
     }
 }
    virtual void start_element (
        const unsigned long line_number,
        const std::string& name,
        const dlib::attribute_list& atts
    )
    {
        //cout << "on line " << line_number << " we hit the <" << name << "> tag" << endl;

        if( name == xmlLabel )
        {
            isItLabel = true;
        }

        // print all the tag's attributes
        atts.reset();
        while (atts.move_next())
        {
            //cout << "\tattribute: " << atts.element().key() << " = " << atts.element().value() << endl;
        }
    }