Example #1
0
	xmlNodePtr XmlUtil::children(const xmlNodePtr node,
		const bool elements_only)
	{
		xmlNodePtr result;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		result = node->children;

		if (result == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("no child xml node")));
		}

		if (elements_only)
		{
			skip_non_elements(result);
		}

		return result;
	}
Example #2
0
    void do_open_store(fs::path const& location) {
        if (!fs::exists(location / "format")) {
            BOOST_THROW_EXCEPTION(common_exception()
                    << errinfo_rpc_code(::rpc_error::STORE_NOT_FOUND)
                    << errinfo_message(str(boost::format("Store at %s does not exist") 
                            % location)));
        }

        io::stream<io::file_source> store_format((location / "format").string());
        int format;
        store_format >> format;
        store_format.close();
        if (format != indexer::STORE_FORMAT) {
            BOOST_THROW_EXCEPTION(common_exception()
                    << errinfo_rpc_code(::rpc_error::INVALID_STORE)
                    << errinfo_message(str(boost::format("Store at %s has invalid "
                                "format %d, expecting %d") 
                            % location % format % indexer::STORE_FORMAT)));
        }

        this->index.reset(new indexer::index(location / "index"));
        this->db.reset(new indexer::value_db("localhost", "index.postings"));

        io::stream<io::file_source> store_info((location / "info").string());
        this->format.ParseFromIstream(&store_info);
        store_info.close();

        this->store_root = location;
    }
Example #3
0
	bool XmlUtil::get_bool_property(const xmlNodePtr node,
		const String &property)
	{
		const xmlAttr *attr;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		for (attr = node->properties; attr; attr = attr->next)
		{
			if ((attr->type == XML_ATTRIBUTE_NODE) &&
				(xmlStrcasecmp(attr->name,
					BAD_CAST property.get().c_str()) == 0))
			{
				if (attr->children == 0)
				{
					return false;
				}

				if (xmlStrcmp(attr->children->content,
					BAD_CAST UTF8("true")) == 0)
				{
					return true;
				}

				if (xmlStrcmp(attr->children->content,
					BAD_CAST UTF8("yes")) == 0)
				{
					return true;
				}

				if (xmlStrcmp(attr->children->content,
					BAD_CAST UTF8("false")) == 0)
				{
					return false;
				}

				if (xmlStrcmp(attr->children->content,
					BAD_CAST UTF8("no")) == 0)
				{
					return false;
				}

				return boost::lexical_cast<bool>(
					attr->children->content);
			}
		}

		EL_THROW_EXCEPTION(ItemNotFoundException()
			<< errinfo_message(UTF8("Property not found"))
			<< errinfo_item_name(property)
			<< errinfo_parameter_name((char*)node->name));
	}
Example #4
0
	Variant XmlUtil::get_variant_value(const xmlNodePtr node)
	{
		String type, value;
		xmlNodePtr it;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		it = XmlUtil::children(node, true);

		do
		{
			if (xmlStrcmp(it->name, BAD_CAST UTF8("type")) == 0)
			{
				type = XmlUtil::get_string_value(it);
			}

			if (xmlStrcmp(it->name, BAD_CAST UTF8("value")) == 0)
			{
				value = XmlUtil::get_string_value(it);
			}
		}
		while (XmlUtil::next(it, true));

		return VariantUtil::get_variant(type, value);
	}
Example #5
0
	StringVariantMap XmlUtil::get_string_variant_map(const xmlNodePtr node,
		const String &element)
	{
		StringVariantMap result;
		xmlNodePtr it;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		it = XmlUtil::children(node, true);

		do
		{
			if (xmlStrcmp(it->name, BAD_CAST element.get().c_str())
				== 0)
			{
				result.insert(get_string_variant(it));
			}
		}
		while (XmlUtil::next(it, true));

		return result;
	}
Example #6
0
	bool XmlUtil::has_children(const xmlNodePtr node,
		const bool elements_only)
	{
		xmlNodePtr it;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		it = node->children;

		if (it == 0)
		{
			return false;
		}

		if (elements_only)
		{
			return skip_non_elements(it);
		}

		return true;
	}
Example #7
0
void IndexSearch::wordQuery(const WordQuery& request, rpcz::reply<QueryResult> reply)
{
    implementation& impl = **this;
    try {
        if (!impl.store)
            BOOST_THROW_EXCEPTION(common_exception()
                << errinfo_rpc_code(::rpc_error::INVALID_STORE)
                << errinfo_message("Store is not open"));

        std::cout << "Searching for '" << request.word() << "', k=" << request.maxcorrections() << std::endl;
        auto index = impl.store->index();
        auto db = impl.store->db();
        ::indexer::index::results_t results;
        index->search(request.word(), request.maxcorrections(), true, results);
        bool keys_only = request.options().keysonly();
        QueryResult pb_results;
        pb_results.set_exact_total(results.size());
        for (std::string const& result : results) {
            IndexRecord* record = pb_results.add_values();
            std::cout << "  result: " << result << std::endl;
            record->set_key(result);
            if (!keys_only) {
                std::string const& s = db->get(result);
                record->mutable_value()->ParseFromString(s);
            } else {
                record->mutable_value()->Clear();
            }
        }
        reply.send(pb_results);
    } RPC_REPORT_EXCEPTIONS(reply)
}
Example #8
0
	void XmlUtil::forece_next(xmlNodePtr &node, const bool elements_only)
	{
		if (!next(node, elements_only))
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("no next xml node")));
		}
	}
Example #9
0
GromacsException::GromacsException(const ExceptionInitializer &details)
{
    *this << errinfo_message(ErrorMessage(details.reason_));
    if (details.hasNestedExceptions())
    {
        *this << errinfo_nested_exceptions(details.nested_);
    }
}
Example #10
0
	void ExtFrameBuffer::check_status() const
	{
		GLuint status;

		status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);

		if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
		{
			EL_THROW_EXCEPTION(OpenGlException()
				<< errinfo_message(get_status_str(status))
				<< errinfo_opengl_error(status));
		}
	}
	MappedHardwareWriteMemory::MappedHardwareWriteMemory(
		const HardwareBufferSharedPtr &buffer,
		const BufferTargetType target): m_buffer(buffer),
		m_target(target)
	{
		m_buffer->bind(m_target);
		m_ptr = m_buffer->map(m_target, hbat_write_only);
		m_buffer->unbind(m_target);

		if (m_ptr == nullptr)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("buffer ptr is zero")));
		}
	}
Example #12
0
	XmlReaderSharedPtr XmlReader::get_xml_reader_from_string(
		const String &str)
	{
		XmlReaderSharedPtr result;

		result = boost::make_shared<XmlReader>();

		if (result->init_from_string(str))
		{
			return result;
		}

		EL_THROW_EXCEPTION(IoErrorException()
			<< errinfo_message(UTF8("Error reading the xml string"))
			<< errinfo_string_value(str));
	}
Example #13
0
	XmlReader::XmlReader(const String &file_name)
	{
		std::string name;

		name = utf8_to_string(file_name);

		m_doc = xmlReadFile(name.c_str(), 0, XML_PARSE_NOENT);

		if (m_doc == 0)
		{
			EL_THROW_EXCEPTION(IoErrorException()
				<< errinfo_message(UTF8("Error reading the xml"
					" file"))
				<< boost::errinfo_file_name(file_name));
		}
	}
Example #14
0
	String XmlUtil::get_string_value(const xmlNodePtr node)
	{
		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		if (node->children == 0)
		{
			return String();
		}

		return String((char*)node->children->content);
	}
Example #15
0
	BitSet64 XmlUtil::get_bitset64_value(const xmlNodePtr node)
	{
		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		if (node->children == 0)
		{
			return 0;
		}

		return boost::lexical_cast<BitSet64>(node->children->content);
	}
Example #16
0
	FloatVector XmlUtil::get_float_vector(const xmlNodePtr node)
	{
		FloatVector result;
		StringStream values_str;
		String string;
		std::vector<std::string> values;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		if (node->children == 0)
		{
			return result;
		}

		values_str << node->children->content;
		string = String(values_str.str());

		boost::split(values, string.get(),
			boost::is_any_of(UTF8("\n\t ")),
			boost::token_compress_on);

		BOOST_FOREACH(const std::string &value, values)
		{
			StringStream str;
			float tmp;

			if (value.empty())
			{
				continue;
			}

			str << value;
			str >> tmp;

			result.push_back(tmp);
		}
Example #17
0
	bool XmlUtil::skip_non_elements(xmlNodePtr &node)
	{
		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("it")));
		}

		while (node->type != XML_ELEMENT_NODE)
		{
			node = node->next;

			if (node == 0)
			{
				return false;
			}
		}

		return true;
	}
Example #18
0
	bool XmlUtil::get_bool_value(const xmlNodePtr node)
	{
		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		if (node->children == 0)
		{
			return false;
		}

		if (xmlStrcmp(node->children->content, BAD_CAST UTF8("true"))
			== 0)
		{
			return true;
		}

		if (xmlStrcmp(node->children->content, BAD_CAST UTF8("yes"))
			== 0)
		{
			return true;
		}

		if (xmlStrcmp(node->children->content, BAD_CAST UTF8("false"))
			== 0)
		{
			return false;
		}

		if (xmlStrcmp(node->children->content, BAD_CAST UTF8("no"))
			== 0)
		{
			return false;
		}

		return boost::lexical_cast<bool>(node->children->content);
	}
Example #19
0
	glm::uvec2 XmlUtil::get_uvec2_value(const xmlNodePtr node)
	{
		StringStream str;
		glm::uvec2 result;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		if (node->children == 0)
		{
			return glm::uvec2();
		}

		str << node->children->content;
		str >> result;

		return result;
	}
Example #20
0
	bool XmlUtil::next(xmlNodePtr &node, const bool elements_only)
	{
		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("it")));
		}

		node = node->next;

		if (node == 0)
		{
			return false;
		}

		if (elements_only)
		{
			return skip_non_elements(node);
		}

		return true;
	}
Example #21
0
void GromacsException::prependContext(const std::string &context)
{
    const ErrorMessage *msg = boost::get_error_info<errinfo_message>(*this);
    GMX_RELEASE_ASSERT(msg != NULL, "Message should always be set");
    *this << errinfo_message(msg->prependContext(context));
}
	void MaterialDescription::load_xml(const xmlNodePtr node)
	{
		xmlNodePtr it;
		Uint32 i;
		SamplerParameterType sampler;

		if (node == 0)
		{
			EL_THROW_EXCEPTION(InvalidParameterException()
				<< errinfo_message(UTF8("parameter is zero"))
				<< errinfo_parameter_name(UTF8("node")));
		}

		if (xmlStrcmp(node->name, BAD_CAST UTF8("material")) != 0)
		{
			return;
		}

		it = XmlUtil::children(node, true);

		do
		{
			for (i = 0; i < m_textures.size(); ++i)
			{
				sampler = static_cast<SamplerParameterType>(i);

				if (xmlStrcmp(it->name, BAD_CAST
					SamplerParameterUtil::get_str(
						sampler).get().c_str()) == 0)
				{
					set_texture(XmlUtil::get_string_value(
						it), sampler);
					set_sRGB(XmlUtil::get_bool_property(it,
						String(UTF8("sRGB"))), sampler);
					set_rectangle(
						XmlUtil::get_bool_property(it,
							String(UTF8(
								"rectangle")),
							false), sampler);
				}
			}

			if (xmlStrcmp(it->name, BAD_CAST UTF8("name")) == 0)
			{
				set_name(XmlUtil::get_string_value(it));
			}

			if (xmlStrcmp(it->name, BAD_CAST UTF8("effect")) == 0)
			{
				set_effect(XmlUtil::get_string_value(it));
			}

			if (xmlStrcmp(it->name, BAD_CAST UTF8("script")) == 0)
			{
				set_script(XmlUtil::get_string_value(it));
			}

			if (xmlStrcmp(it->name,
				BAD_CAST UTF8("texture_matrix_0")) == 0)
			{
				set_texture_matrix(
					XmlUtil::get_mat2x3_value(it), 0);
			}

			if (xmlStrcmp(it->name,
				BAD_CAST UTF8("texture_matrix_1")) == 0)
			{
				set_texture_matrix(
					XmlUtil::get_mat2x3_value(it), 1);
			}

			if (xmlStrcmp(it->name, BAD_CAST UTF8("color")) == 0)
			{
				set_color(XmlUtil::get_vec4_value(it));
			}

			if (xmlStrcmp(it->name,
				BAD_CAST UTF8("dudv_scale_offset")) == 0)
			{
				set_dudv_scale_offset(XmlUtil::get_vec4_value(
					it));
			}

			if (xmlStrcmp(it->name, BAD_CAST UTF8("cast_shadows"))
				== 0)
			{
				set_cast_shadows(XmlUtil::get_bool_value(it));
			}

			if (xmlStrcmp(it->name, BAD_CAST UTF8("culling")) == 0)
			{
				set_culling(XmlUtil::get_bool_value(it));
			}
		}
		while (XmlUtil::next(it, true));
	}