示例#1
0
bool Root::loadFrom(std::string name) {
    auto xml =
        Kriti::ResourceRegistry::get<Kriti::XMLResource>("conv/" + name);

    if(!xml) return false;

    auto objects = xml->doc().first_element_by_path("/conversation/objects");

    // First pass to create objects.
    for(auto c = objects.first_child(); c ; c = c.next_sibling()) {
        int id = c.attribute("id").as_int();
        if(!std::strcmp(c.name(), "node")) {
            m_nodeMap[id] = boost::make_shared<Node>();
        }
        else if(!std::strcmp(c.name(), "context")) {
            m_contextMap[id] = boost::make_shared<Context>();
        }
        else if(!std::strcmp(c.name(), "link")) {
            m_linkMap[id] = boost::make_shared<Link>();
        }
        else {
            Message3(Game, Debug, "Unknown object type " << c.name());
        }
    }

    // Second pass to parse objects.
    for(auto c = objects.first_child(); c ; c = c.next_sibling()) {
        int id = c.attribute("id").as_int();
        if(!std::strcmp(c.name(), "node")) {
            loadNode(id, c);
        }
        else if(!std::strcmp(c.name(), "context")) {
            loadContext(id, c);
        }
        else if(!std::strcmp(c.name(), "link")) {
            loadLink(id, c);
        }
        else {
            Message3(Game, Debug, "Unknown object type " << c.name());
        }
    }

    if(!m_rootNode) {
        Message3(Game, Error, "Couldn't load conversation \"" << name
            << "\": no root node");
        return false;
    }

    return true;
}
示例#2
0
	bool XMLFileParser::Read(XMLContainer & container, DirectoryMode mode)
	{
		pugi::xml_document XMLDocument;
		pugi::xml_parse_result result;
		
		SerializedData data;
		data.data = ReadBinaryFile(m_File.GetLocalPath(), data.size, mode);
		result = XMLDocument.load_buffer_inplace_own(data.data, data.size);

		Logger::GetInstance()->Log(result,
			star::string_cast<tstring>(result.description()), STARENGINE_LOG_TAG);
		if (result)
		{
			auto root = XMLDocument.first_child();
			if(root != NULL)
			{
				container.SetName(star::string_cast<tstring>(root.name()));
				AddAttributes(container, root);

				auto child = root.first_child();
				if(child != NULL)
				{
					do 
					{
						AddChild(container, child);
						child = child.next_sibling();
					} while (child != NULL);
				}
			}
		}
		return result;
	}
示例#3
0
game_object& game_object::remove_if(const predicate_t &pred) {
    for (auto* child = first_child(); child != null;) {
        auto* del = child;
        child = child->next_sibling();
        if (pred(*del)) {
            if (del == first_child()) {
                _first_child = del->next_sibling();
            }
            
            del->_parent = nullptr;
            del->_next_sibling = del->_pre_sibling = null;
            del->release();
        }
    }
    return *this;
}
示例#4
0
文件: lwlib.c 项目: cpitclaudel/emacs
Widget
lw_raise_all_pop_up_widgets (void)
{
  widget_info* info;
  widget_instance* instance;
  Widget result = NULL;

  for (info = all_widget_info; info; info = info->next)
    for (instance = info->instances; instance; instance = instance->next)
      if (instance->pop_up_p)
	{
	  Widget widget = instance->widget;
	  if (widget)
	    {
	      if (XtIsManaged (widget)
#ifdef USE_MOTIF
		  /* What a complete load of crap!!!!
		     When a dialogShell is on the screen, it is not managed!
		   */
		  || (lw_motif_widget_p (instance->widget) &&
		      XtIsManaged (first_child (widget)))
#endif
		  )
		{
		  if (!result)
		    result = widget;
		  XMapRaised (XtDisplay (widget), XtWindow (widget));
		}
	    }
	}
  return result;
}
void c_dup(struct child *c) {
	c = first_child(c);
	do {
		printf("[%d] 0x%08lx -> ", c->pid, (long unsigned int)c);
	} while( (c=c->next) );
	printf("\n");
};
示例#6
0
void    GLUI_RadioGroup::draw_group( int translate )
{
  GLUI_DRAWINGSENTINAL_IDIOM
  GLUI_RadioButton *button;
  this->int_val = int_val;

  glMatrixMode(GL_MODELVIEW );

  button = (GLUI_RadioButton*) first_child();
  while( button != NULL ) {
    glPushMatrix();
    if (translate) {
      button->translate_to_origin();
    }
    else {
      glTranslatef(button->x_abs-x_abs,
                   button->y_abs-y_abs,0.0);
    }

    if ( button->int_val ) 
      button->draw_checked();
    else 
      button->draw_unchecked();
    
    glPopMatrix();

    button = (GLUI_RadioButton*) button->next();
  }
}
示例#7
0
void    GLUI_Rollout::close( void )
{
  if ( NOT glui )
    return;

  if ( NOT is_open )
    return;
  is_open = false;
  
  GLUI_DRAWINGSENTINAL_IDIOM

  if ( child_head != NULL ) {
    ((GLUI_Control*) child_head)->hide_internal( true );
  }

  /* Move all children into a private list of hidden children */
  collapsed_node.child_head = first_child();
  collapsed_node.child_tail = last_child();
  child_head = NULL;
  child_tail = NULL;

  this->h = rollout_height_pixels;

  glui->refresh();
}
示例#8
0
	//! Prefix increment of the iterator.
	iterator& operator++()
	{
		if (!m_valid) return *this;
		if (m_v == m_cst->root() and m_visited) {
			m_valid = false;
			return *this;
		}
		value_type w;
		if (!m_visited) { // go down, if possible
			if (m_cst->is_leaf(m_v)) {
				w = m_cst->sibling(m_v);  // determine sibling of leaf v
				if (w == m_cst->root()) { // if there exists no right sibling of the leaf v
										  //					w = m_cst->parent(m_v);
					w		  = parent();
					m_visited = true; // go up
				}
			} else { // v is not a leaf => go down the tree
				w = first_child();
			}
		} else { //
			w = m_cst->sibling(m_v);
			if (w == m_cst->root()) { // if there exists no right sibling
				w = parent();
			} else {
				m_visited = false;
			}
		}
		m_v = w;
		return *this;
	}
struct child *find_child(struct child *current, pid_t pid) {
	current = first_child(current);
	while( current )
		if( current->pid == pid ) return current;
		else if( current->next ) current = current->next;
		else break;
	return NULL;
};
示例#10
0
文件: bp.cpp 项目: rkonow/topk
i64 naive_child(bp *b, i64 s, i64 d)
{
    i64 t,i;
    t = first_child(b,s);
    for (i = 1; i < d; i++) {
        if (t == -1) break;
        t = next_sibling(b,t);
    }
    return t;
}
示例#11
0
TEST_F(DocumentParseTest, element_with_child)
{
  Node *node;
  doc = Document::parse("<hello><world /></hello>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();
  node = top_element->first_child();
  ASSERT_EQ("hello", top_element->name());
  CHECK_ELEMENT_NAME(node, "world");
}
示例#12
0
TEST_F(DocumentParseTest, element_with_char_ref_hex)
{
  Node *node;

  doc = Document::parse("<a>&#x4d;</a>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_TEXT_NODE(node, "M");
}
示例#13
0
TEST_F(DocumentParseTest, element_with_text)
{
  Node *node;

  doc = Document::parse("<hello>world</hello>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_TEXT_NODE(node, "world");
}
示例#14
0
文件: bp.cpp 项目: rkonow/topk
i64 naive_degree(bp *b, i64 s)
{
    i64 t,d;
    d = 0;
    t = first_child(b,s);
    while (t >= 0) {
        d++;
        t = next_sibling(b,t);
    }
    return d;
}
示例#15
0
int main(void)
{
	CCAN_LIST_HEAD(h);

	children(&h);
	first_child(&h);
	last_child(&h);
	check_children(&h);
	print_children(&h);
	return 0;
}
示例#16
0
TEST_F(DocumentParseTest, element_with_nonalpha_text)
{
  Node *node;

  doc = Document::parse("<a>one, 2</a>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_TEXT_NODE(node, "one, 2");
}
示例#17
0
TEST_F(DocumentParseTest, comment)
{
  Node *node;

  doc = Document::parse("<a><!--alert--></a>", &error);
  CHECK_PARSE_ERROR(error);

  auto top_element = get_top_element();

  node = top_element->first_child();
  ASSERT_EQ(NODE_TYPE_COMMENT, node->type());
}
示例#18
0
文件: json.cpp 项目: QianErGe/acl
const char* json_node::operator[](const char* tag)
{
	json_node* iter = first_child();
	while (iter)
	{
		const char* ptr = iter->tag_name();
		if (ptr != NULL && strcasecmp(ptr, tag) == 0)
			return iter->get_text();
		iter = next_child();
	}

	return NULL;
}
示例#19
0
TEST_F(DocumentParseTest, element_with_grandchild)
{
  Node *node;

  doc = Document::parse("<hello><world><cool /></world></hello>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_ELEMENT_NAME(node, "world");

  node = node->first_child();
  CHECK_ELEMENT_NAME(node, "cool");
}
示例#20
0
TEST_F(DocumentParseTest, element_with_two_children_whitespace)
{
  Node *node;

  doc = Document::parse("<hello>\r\n\t<world />\n  <cool />\n</hello>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_ELEMENT_NAME(node, "world");

  node = node->next_sibling();
  CHECK_ELEMENT_NAME(node, "cool");
}
示例#21
0
文件: bp.cpp 项目: rkonow/topk
///////////////////////////////////////////
//  child(bp *b, i64 s, i64 d)
//    returns the d-th child of s  (1 <= d <= degree(s))
//            -1 if no such node
///////////////////////////////////////////
i64 child(bp *b, i64 s, i64 d)
{
    i64 r;
    if (b->opt & OPT_DEGREE) {
        //return find_open(b,fast_degree(b,s,b->n,d));
        if (d==1) return first_child(b,s);
        r = fast_degree(b,s,b->n,d-1)+1;
        if (inspect(b,r) == CP) return -1;
        return r;
    } else {
        return naive_child(b,s,d);
    }

}
示例#22
0
TEST_F(DocumentParseTest, element_with_two_children_first_empty)
{
  Node *node;

  doc = Document::parse("<a><b></b><c/></a>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_ELEMENT_NAME(node, "b");

  node = node->next_sibling();
  CHECK_ELEMENT_NAME(node, "c");
}
示例#23
0
T node_value(const_inspection_branch_t branch, T node_t::*member) {
    const forest_node_t& node(*branch);
    bool                 is_array_root(node.get_flag(is_array_root_k));

    if (is_array_root) {
        inspection_forest_t::const_child_iterator first_child(adobe::child_begin(branch));
        inspection_forest_t::const_child_iterator last_child(adobe::child_end(branch));

        if (first_child != last_child)
            return node_value<T>(first_child.base(), member);
    }

    return node.*member;
}
示例#24
0
TEST_F(DocumentParseTest, element_with_mixed_content)
{
  Node *node;

  doc = Document::parse("<hello><one />b</hello>", &error);
  CHECK_PARSE_ERROR(error);

  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_ELEMENT_NAME(node, "one");

  node = node->next_sibling();
  CHECK_TEXT_NODE(node, "b");
}
示例#25
0
文件: XML.cpp 项目: Sonophoto/Soar-SC
  void XML_Element::set_string(const String &s) {
    if(!good()) {
      std::cerr << "Bad XML_Element_c attempted set_string(...)\n";
      throw XML_Element_Ungood();
    }

    TiXmlNode * const node = first_child();

    if(!node)
      m_handle.ToNode()->LinkEndChild(new TiXmlText(s.c_str()));
    else if(node->ToText()) {
      TiXmlText replacement(s.c_str());
      m_handle.ToNode()->ReplaceChild(node, replacement);
    }
    else {
      std::cerr << "XML_Element_c attempted set_string(...) on non-leaf node\n";
      throw XML_Element_Nonleaf();
    }
  }
示例#26
0
void    GLUI_RadioGroup::draw()
{
  if ( NOT can_draw() )
    return;
  GLUI_DRAWINGSENTINAL_IDIOM
  GLUI_RadioButton *button;
  this->int_val = int_val;

  glMatrixMode(GL_MODELVIEW );

  button = (GLUI_RadioButton*) first_child();
  while( button != NULL ) {
    if ( button->int_val )
      button->draw_checked();
    else
      button->draw_unchecked();
    button = (GLUI_RadioButton*) button->next();
  }

}
void    GLUI_RadioGroup::draw_group( int translate )
{
  GLUI_RadioButton *button;
  int               state, orig;

  if ( NOT can_draw() )
    return;

  orig = set_to_glut_window();

  if ( translate )
    state = glui->set_front_draw_buffer();

  this->int_val = int_val;

  glMatrixMode(GL_MODELVIEW );

  button = (GLUI_RadioButton*) first_child();
  while( button != NULL ) {
    
    if ( translate ) {
      glPushMatrix();
      button->translate_to_origin();
    }

    if ( button->int_val ) 
      button->draw_checked();
    else 
      button->draw_unchecked();
    
    if ( translate )
      glPopMatrix();

    button = (GLUI_RadioButton*) button->next();
  }

  if ( translate )
    glui->restore_draw_buffer(state);

  restore_window(orig);
}
示例#28
0
void    GLUI_RadioGroup::set_selected( int int_val )
{
  GLUI_RadioButton *button;

  this->int_val = int_val;

  button = (GLUI_RadioButton*) first_child();
  while( button != NULL ) {
    if ( int_val == -1 ) {       /*** All buttons in group are deselected ***/
      button->set_int_val(0);
    }
    else if ( int_val == button->user_id ) { /*** This is selected button ***/
      button->set_int_val(1);
    }
    else {                               /*** This is NOT selected button ***/
      button->set_int_val(0);

    }
    button = (GLUI_RadioButton*) button->next();
  }
  glutPostRedisplay();
}
示例#29
0
TEST_F(DocumentParseTest, element_with_entities)
{
  Node *node;

  doc = Document::parse("<a>&lt;&gt;&amp;&quot;&apos;</a>", &error);
  CHECK_PARSE_ERROR(error);
  auto top_element = get_top_element();

  node = top_element->first_child();
  CHECK_TEXT_NODE(node, "<");

  node = node->next_sibling();
  CHECK_TEXT_NODE(node, ">");

  node = node->next_sibling();
  CHECK_TEXT_NODE(node, "&");

  node = node->next_sibling();
  CHECK_TEXT_NODE(node, "\"");

  node = node->next_sibling();
  CHECK_TEXT_NODE(node, "'");
}
示例#30
0
bool readXml(std::istream &in, StateDefinition &state)
{
	pugi::xml_document doc;

	in.seekg(0, std::ios::end);
	auto fileSize = in.tellg();
	in.seekg(0, std::ios::beg);

	std::unique_ptr<char[]> fileData(new char[fileSize]);
	in.read(fileData.get(), fileSize);
	if (!in)
	{
		std::cerr << "Failed to read " << fileSize << "bytes from input file\n";
		return false;
	}

	boost::uuids::detail::sha1 sha;
	sha.reset();
	sha.process_bytes(fileData.get(), fileSize);
	unsigned int hashValue[5];
	sha.get_digest(hashValue);

	for (int i = 0; i < 5; i++)
	{
		unsigned int v = hashValue[i];
		for (int j = 0; j < 4; j++)
		{
			// FIXME: Probably need to do the reverse for big endian?
			char stringBuf[3];
			unsigned int byteHex = v & 0xff000000;
			byteHex >>= 24;
			snprintf(stringBuf, sizeof(stringBuf), "%02x", byteHex);
			state.hashString += stringBuf;
			v <<= 8;
		}
	}

	auto ret = doc.load_buffer(fileData.get(), fileSize);
	if (!ret)
	{
		std::cerr << "Failed to parse file:" << ret.description() << "\n";
		return false;
	}

	auto rootNode = doc.first_child();
	while (rootNode)
	{
		if (std::string(rootNode.name()) == "openapoc_gamestate")
		{
			auto objectNode = rootNode.first_child();
			while (objectNode)
			{
				if (std::string(objectNode.name()) == "object")
				{
					SerializeObject obj("");
					auto externalAttr = objectNode.attribute("external");
					if (!externalAttr.empty())
					{
						std::string externalValue = externalAttr.as_string();
						if (externalValue == "true")
						{
							obj.external = true;
						}
						else
						{
							std::cerr << "Unknown object external attribute \"" << externalValue
							          << "\"\n";
						}
					}
					auto memberNode = objectNode.first_child();
					while (memberNode)
					{
						if (std::string(memberNode.name()) == "member")
						{
							std::string memberName = memberNode.text().as_string();
							NodeType type = NodeType::Normal;
							auto typeAttr = memberNode.attribute("type");
							if (!typeAttr.empty())
							{
								std::string typeName = typeAttr.as_string();
								if (typeName == "Normal")
									type = NodeType::Normal;
								else if (typeName == "Section")
									type = NodeType::Section;
								else if (typeName == "SectionMap")
									type = NodeType::SectionMap;
								else
									std::cerr << "Unknown member type attribute \"" << typeName
									          << "\"\n";
							}
							SerializeNode member(memberName);
							member.type = type;
							obj.members.push_back(std::make_pair(member.name, member));
						}
						else if (std::string(memberNode.name()) == "name")
						{
							obj.name = memberNode.text().as_string();
						}
						memberNode = memberNode.next_sibling();
					}
					state.objects.push_back(obj);
				}
				else if (std::string(objectNode.name()) == "enum")
				{
					SerializeEnum sEnum;
					auto valueNode = objectNode.first_child();
					while (valueNode)
					{
						if (std::string(valueNode.name()) == "value")
						{
							sEnum.values.push_back(valueNode.text().as_string());
						}
						else if (std::string(valueNode.name()) == "name")
						{
							sEnum.name = valueNode.text().as_string();
						}
						valueNode = valueNode.next_sibling();
					}
					state.enums.push_back(sEnum);
				}
				objectNode = objectNode.next_sibling();
			}
		}
		rootNode = rootNode.next_sibling();
	}

	return true;
}