예제 #1
0
OP_STATUS
WebFeedStorage::LocalLoad(const uni_char *file_name)
{
	OP_STATUS oom = OpStatus::OK;

	OpFile feed_file;
	OpStringC file_name_str(file_name);
	oom = feed_file.Construct(file_name_str.CStr(), OPFILE_WEBFEEDS_FOLDER);
	if (OpStatus::IsError(oom))
		return oom;

	UnicodeFileInputStream in_stream;
	RETURN_IF_ERROR(in_stream.Construct(&feed_file, URL_XML_CONTENT, TRUE));

	XMLParser *parser;
	URL dummy;
	RETURN_IF_ERROR(XMLParser::Make(parser, NULL, g_main_message_handler, this, dummy));
	OpStackAutoPtr<XMLParser> protected_parser(parser);

	// Set up XML configuration for parsing web feed storage:
	XMLParser::Configuration configuration;
	configuration.load_external_entities = XMLParser::LOADEXTERNALENTITIES_NO;
	configuration.max_tokens_per_call = 0;  // unlimited
#if defined(_DEBUG) && defined(XML_ERRORS)
	configuration.generate_error_report = TRUE;
#endif

	parser->SetConfiguration(configuration);

	int buf_len = 2048;

	BOOL more = in_stream.has_more_data();
	while (OpStatus::IsSuccess(oom) && more && !parser->IsFailed())
	{
		uni_char *buf = in_stream.get_block(buf_len);
		more = in_stream.has_more_data();

		OP_ASSERT(buf_len % sizeof(uni_char) == 0);
		buf_len /= sizeof(uni_char);

		OP_ASSERT(buf);
		if (!buf)
			return OpStatus::ERR;
		
		oom = parser->Parse(buf, buf_len, more);
		OP_ASSERT(!parser->IsFailed());
#if defined(_DEBUG) && defined XML_ERRORS
		if (parser->IsFailed())
		{
			XMLRange range;
			const char *error, *url, *fragment;
		
			range = parser->GetErrorPosition();
			parser->GetErrorDescription(error, url, fragment);
		}
#endif // defined(_DEBUG) && defined(XML_ERRORS)
	}

	return OpStatus::OK;
}
예제 #2
0
파일: atlas.cpp 프로젝트: mhough/DSI-Studio
bool atlas::load_from_file(const char* file_name)
{
    {
        gz_nifti nii;
        if(!nii.load_from_file(file_name))
            return false;
        nii >> I;
        transform.clear();
        transform.resize(16);
        transform[15] = 1.0;
        nii.get_image_transformation(transform.begin());
        math::matrix_inverse(transform.begin(),math::dim<4,4>());
    }
    std::string file_name_str(file_name);
    std::string text_file_name;

    if (file_name_str.length() > 3 &&
            file_name_str[file_name_str.length()-3] == '.' &&
            file_name_str[file_name_str.length()-2] == 'g' &&
            file_name_str[file_name_str.length()-1] == 'z')
        text_file_name = std::string(file_name_str.begin(),file_name_str.end()-6);
    else
        text_file_name = std::string(file_name_str.begin(),file_name_str.end()-3);
    text_file_name += "txt";
    if(image::geometry<3>(141,172,110) == I.geometry())
    {
        std::ifstream in(text_file_name.c_str());
        if(!in)
            return false;

        std::map<std::string,std::set<unsigned int> > regions;
        std::string line;
        for(int i = 0;std::getline(in,line);++i)
        {
            std::istringstream read_line(line);
            int num;
            read_line >> num;
            std::string region;
            while (read_line >> region)
            {
                if(region == "*")
                    continue;
                regions[region].insert(i);
            }
            index2label.resize(i+1);
        }

        std::map<std::string,std::set<unsigned int> >::iterator iter = regions.begin();
        std::map<std::string,std::set<unsigned int> >::iterator end = regions.end();
        for (int i = 0;iter != end;++iter,++i)
        {
            labels.push_back(iter->first);
            label2index.push_back(std::vector<unsigned int>(iter->second.begin(),iter->second.end()));
            for(int j = 0;j < label2index.back().size();++j)
                index2label[label2index[i][j]].push_back(i);
        }
    }