Example #1
0
wxTreeItemId CConfigTree::FindNextItemId(wxTreeItemId treeItemId, const wxString& text,
    bool checkFirst, bool matchCase, bool matchWord)
{
    wxString ctext(text);
    if (!matchCase) {
        ctext.MakeLower();
    }

    wxTreeItemId found;
    wxTreeItemId id;
    wxTreeItemId currentId = treeItemId;
    CConfigItem *item = NULL;
    wxTreeItemIdValue dummy;

    while (currentId.IsOk()) {
        if (checkFirst) {
            CTreeItemData *data = (CTreeItemData *)GetItemData(currentId);
            if (data) {
                if ((item = data->GetConfigItem()) != NULL) {
                    wxString name = item->GetName();
                    wxString brief = item->GetBriefDescription();
                    wxString desc = item->GetDescription();

                    if (!matchCase) {
                        name.MakeLower();
                        brief.MakeLower();
                        desc.MakeLower();
                    }
                    if (CUtils::FindString(name, ctext, matchWord) ||
                        CUtils::FindString(brief, ctext, matchWord) ||
                        CUtils::FindString(desc, ctext, matchWord)) {
                        found = currentId;
                        break;
                    }
                }
            }
        }
        checkFirst = true;

        id = GetFirstChild(currentId, dummy);
        if (!id.IsOk()) {
            id = GetNextSibling(currentId);
            if (!id.IsOk()) {
                wxTreeItemId parentId = currentId;
                do {
                    parentId = GetItemParent(parentId);
                    if (!parentId.IsOk()) {
                        break;
                    }
                    id = GetNextSibling(parentId);
                } while (!id.IsOk());
            }
        }
        currentId = id;
    }
    return found;
}
Example #2
0
score() {
    int scor, maxsco, obj, i;

    scor=maxsco=0;
    for(obj=treasr; obj<=objt; ++obj) {
	if( place(obj)>0 ) {
	    maxsco=maxsco+20;
	    if( place(obj)==3 && prop(obj)==0 ) {    /* сокровище b доме */
		scor=scor+20;
	    } else if( (prop(obj)&0377)!=inipro ) {   /* сокровище видел */
		scor=scor+5;
	    }
	}
    }
    rspeak(32);
    mscore(scor,maxsco);

    obj = 1;
    for(i=1; i<=plcl; ++i)  if( cval(i) && scor>=cval(i) ) obj = i;
    mes(ctext(obj));
}
void InputParser::run(int                   &snapshotTime,
                      int                   &routingUpdateTime,
                      std::list<HostInfo>   &hosts,
                      std::list<RouterInfo> &routers,
                      std::list<LinkInfo>   &links,
                      std::list<FlowInfo>   &flows,
                      PlotOptions           &plotOptions)
{
    pugi::xml_document doc;
        // create an xml_document to load the file

    pugi::xml_parse_result result = doc.load_file(inputNetwork.c_str());

    std::cout << "**************************************************"
              << std::endl
              << "Starting to parse input file: "
              << inputNetwork
              << "."
              << "**************************************************"
              << std::endl << std::endl;

    std::cout << "Load result: "  << result.description() << std::endl;
    
    pugi::xml_node network = doc.child("Network");

    std::cout << network.name() << "-------------" << std::endl;

    // network elements

    // snapshot time
    snapshotTime = network.child("snapshotTime").text().as_int();
    std::cout << "snapshot time:             "
              << snapshotTime
              << std::endl;

    // routing table update time
    routingUpdateTime = network.child("routingTableUpdateTime").text().as_int();
    std::cout << "routing table update time: "
              << routingUpdateTime
              << std::endl;

    // network hosts
    std::cout << "network hosts: " << std::endl;
    pugi::xml_node networkHosts = network.child("networkHosts");

    pugi::xml_attribute separateHostGraphs = networkHosts.attribute("separateGraphs");
    plotOptions.separateHostGraphs = separateHostGraphs.as_bool();

    for (pugi::xml_node host = networkHosts.first_child();
         host; host = host.next_sibling())
    {
        pugi::xml_attribute id = host.attribute("id");
        std::cout << "    " << host.name() << ": "
             << id.name() << "=" << id.value() << std::endl;

        // print
        pugi::xml_attribute print_att = host.attribute("print");
        if (print_att.as_int()) {
            std::cout << "Host "
                      << id.as_int()
                      << " set to print\n";
        }
        else {
            std::cout << "Host "
                      << id.as_int()
                      << " not set to print\n";
        }



        HostInfo info(print_att.as_int(), id.as_int());
        hosts.push_back(info);
    }

    // network routers
    std::cout << "network routers: " << std::endl;
    pugi::xml_node networkRouters = network.child("networkRouters");
    for (pugi::xml_node router = networkRouters.first_child();
         router; router = router.next_sibling())
    {
        pugi::xml_attribute id = router.attribute("id");
        std::cout << "    " << router.name() << ": "
             << id.name() << "=" << id.value() << std::endl;

        RouterInfo info(id.as_int());
        routers.push_back(info);
    }

    // network links
    std::cout << "network links: " << std::endl;
    pugi::xml_node networkLinks = network.child("networkLinks");

    pugi::xml_attribute separateLinkGraphs = networkLinks.attribute("separateGraphs");
    plotOptions.separateLinkGraphs = separateLinkGraphs.as_bool();

    for (pugi::xml_node link = networkLinks.first_child();
         link; link = link.next_sibling())
    {
        // link id
        pugi::xml_attribute id_att = link.attribute("id");
        std::cout << "    " << link.name() << ": "
             << id_att.name() << "=" << id_att.value() << std::endl;

        // print
        pugi::xml_attribute print_att = link.attribute("print");
        if (print_att.as_int()) {
            std::cout << "Link "
                      << id_att.as_int()
                      << " set to print\n";
        }
        else {
            std::cout << "Link "
                      << id_att.as_int()
                      << " not set to print\n";
        }


        // link rate
        pugi::xml_node rate_node = link.child("linkRate");
        std::cout << "          " << rate_node.name()
                  << "=" << rate_node.child_value() << std::endl;

        // link delay
        pugi::xml_node delay_node = link.child("linkDelay");
        std::cout << "          " << delay_node.name()
                  << "=" << delay_node.child_value() << std::endl;

        // buffer size
        pugi::xml_node size_node = link.child("bufferSize");
        std::cout << "          " << size_node.name()
                  << "=" << size_node.child_value() << std::endl;

        // node 1
        pugi::xml_node node1_node = link.child("node1");
        pugi::xml_attribute node1_type = node1_node.attribute("type");
        std::cout << "          " << node1_node.name() << ":" << std::endl;
        std::cout << "              " << node1_type.name()
                  << "=" << node1_type.value() << std::endl;
        std::cout << "              id"
                  << "=" << node1_node.child_value() << std::endl;

        // node 2
        pugi::xml_node node2_node = link.child("node2");
        pugi::xml_attribute node2_type = node2_node.attribute("type");
        std::cout << "          " << node2_node.name() << ":" << std::endl;
        std::cout << "              " << node2_type.name()
                  << "=" << node2_type.value() << std::endl;
        std::cout << "              id"
                  << "=" << node2_node.child_value() << std::endl;

        LinkInfo info(
                print_att.as_int(),
                id_att.as_int(),
                atoi(rate_node.child_value()),
                atoi(delay_node.child_value()),
                atof(size_node.child_value()),
                node1_type.as_int(),
                atoi(node1_node.child_value()),
                node2_type.as_int(),
                atoi(node2_node.child_value()));

        links.push_back(info);
    }

    // network flows
    std::cout << "network flows: " << std::endl;
    pugi::xml_node networkFlows = network.child("networkFlows");

    pugi::xml_attribute separateFlowGraphs = networkFlows.attribute("separateGraphs");
    plotOptions.separateFlowGraphs = separateFlowGraphs.as_bool();

    for (pugi::xml_node flow = networkFlows.first_child();
         flow; flow = flow.next_sibling())
    {
        // flow id
        pugi::xml_attribute id_att = flow.attribute("id");
        std::cout << "    " << flow.name() << ": "
             << id_att.name() << "=" << id_att.value() << std::endl;

        // print
        pugi::xml_attribute print_att = flow.attribute("print");
        if (print_att.as_int()) {
            std::cout << "Flow "
                      << id_att.as_int()
                      << " set to print\n";
        }
        else {
            std::cout << "Flow "
                      << id_att.as_int()
                      << " not set to print\n";
        }

        // congestion control algorithm
        pugi::xml_node congestion = flow.child("congestionAlgorithmType");
        CongestionAlgorithmType congestionAlgorithmType;
        std::string ctext(congestion.text().get());
        if (ctext.compare("slow") == 0) {
            congestionAlgorithmType = SLOW;
        }
        else if (ctext.compare("tahoe") == 0) {
            congestionAlgorithmType = TAHOE;
        }
        else if (ctext.compare("reno") == 0) {
            congestionAlgorithmType = RENO;
        }
        else if (ctext.compare("cubic") == 0) {
            congestionAlgorithmType = CUBIC;
        }
        else if (ctext.compare("vegas") == 0) {
            congestionAlgorithmType = VEGAS;
        }
        else {
            std::cout << "Invalid congestion control algorithm: "
                      << ctext
                      << ".\n"
                      << "Options are: reno, vegas\n";
        }

        // source host
        pugi::xml_node src_node = flow.child("source");
        std::cout << "          " << src_node.name()
                  << "=" << src_node.child_value() << std::endl;

        // destination host
        pugi::xml_node dst_node = flow.child("destination");
        std::cout << "          " << dst_node.name()
                  << "=" << dst_node.child_value() << std::endl;

        // flow size
        pugi::xml_node size_node = flow.child("flowSize");
        std::cout << "          " << size_node.name()
                  << "=" << size_node.child_value() << std::endl;

        // flow start time
        pugi::xml_node time_node = flow.child("flowStartTime");
        std::cout << "          " << time_node.name()
                  << "=" << time_node.child_value() << std::endl;

        FlowInfo info(
                print_att.as_int(),
                id_att.as_int(),
                atoi(src_node.child_value()),
                atoi(dst_node.child_value()),
                atof(size_node.child_value()),
                atof(time_node.child_value()),
                congestionAlgorithmType);

        flows.push_back(info);
    }

    std::cout << "**************************************************"
              << std::endl
              << "Done parsing input file: "
              << inputNetwork
              << "."
              << "**************************************************"
              << std::endl << std::endl;
}
Example #4
0
int bamreset(::libmaus2::util::ArgInfo const & arginfo)
{
	if ( isatty(STDIN_FILENO) )
	{
		::libmaus2::exception::LibMausException se;
		se.getStream() << "Refusing to read binary data from terminal, please redirect standard input to pipe or file." << std::endl;
		se.finish();
		throw se;
	}

	if ( isatty(STDOUT_FILENO) )
	{
		::libmaus2::exception::LibMausException se;
		se.getStream() << "Refusing write binary data to terminal, please redirect standard output to pipe or file." << std::endl;
		se.finish();
		throw se;
	}
	
	int const level = libmaus2::bambam::BamBlockWriterBaseFactory::checkCompressionLevel(arginfo.getValue<int>("level",getDefaultLevel()));
	int const verbose = arginfo.getValue<int>("verbose",getDefaultVerbose());
	int const resetsortorder = arginfo.getValue<int>("resetsortorder",getDefaultResetSortOrder());
	
	::libmaus2::bambam::BamDecoder dec(std::cin,false);
	::libmaus2::bambam::BamHeader const & header = dec.getHeader();

	std::string headertext = header.text;

	// no replacement header file given
	if ( ! arginfo.hasArg("resetheadertext") )
	{
		// remove SQ lines
		std::vector<libmaus2::bambam::HeaderLine> allheaderlines = libmaus2::bambam::HeaderLine::extractLines(headertext);

		std::ostringstream upheadstr;
		for ( uint64_t i = 0; i < allheaderlines.size(); ++i )
			if ( allheaderlines[i].type != "SQ" )
				upheadstr << allheaderlines[i].line << std::endl;

		headertext = upheadstr.str();
	}
	// replace header given in file
	else
	{
		std::string const headerfilename = arginfo.getUnparsedValue("resetheadertext","");
		uint64_t const headerlen = libmaus2::util::GetFileSize::getFileSize(headerfilename);
		libmaus2::aio::CheckedInputStream CIS(headerfilename);
		libmaus2::autoarray::AutoArray<char> ctext(headerlen,false);
		CIS.read(ctext.begin(),headerlen);
		headertext = std::string(ctext.begin(),ctext.end());		
	}

	// add PG line to header
	headertext = libmaus2::bambam::ProgramHeaderLineSet::addProgramLine(
		headertext,
		"bamreset", // ID
		"bamreset", // PN
		arginfo.commandline, // CL
		::libmaus2::bambam::ProgramHeaderLineSet(headertext).getLastIdInChain(), // PP
		std::string(PACKAGE_VERSION) // VN			
	);
	
	// construct new header
	libmaus2::bambam::BamHeader uphead(headertext);
	if ( resetsortorder )
		uphead.changeSortOrder("unknown");

	/*
	 * start index/md5 callbacks
	 */
	std::string const tmpfilenamebase = arginfo.getValue<std::string>("tmpfile",arginfo.getDefaultTmpFileName());
	std::string const tmpfileindex = tmpfilenamebase + "_index";
	::libmaus2::util::TempFileRemovalContainer::addTempFile(tmpfileindex);
	uint32_t const excludeflags = libmaus2::bambam::BamFlagBase::stringToFlags(
		arginfo.getValue<std::string>("exclude",getDefaultExcludeFlags()));

	std::string md5filename;
	std::string indexfilename;

	std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > cbs;
	::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Pmd5cb;
	if ( arginfo.getValue<unsigned int>("md5",getDefaultMD5()) )
	{
		if ( arginfo.hasArg("md5filename") &&  arginfo.getUnparsedValue("md5filename","") != "" )
			md5filename = arginfo.getUnparsedValue("md5filename","");
		else
			std::cerr << "[V] no filename for md5 given, not creating hash" << std::endl;

		if ( md5filename.size() )
		{
			::libmaus2::lz::BgzfDeflateOutputCallbackMD5::unique_ptr_type Tmd5cb(new ::libmaus2::lz::BgzfDeflateOutputCallbackMD5);
			Pmd5cb = UNIQUE_PTR_MOVE(Tmd5cb);
			cbs.push_back(Pmd5cb.get());
		}
	}
	libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Pindex;
	if ( arginfo.getValue<unsigned int>("index",getDefaultIndex()) )
	{
		if ( arginfo.hasArg("indexfilename") &&  arginfo.getUnparsedValue("indexfilename","") != "" )
			indexfilename = arginfo.getUnparsedValue("indexfilename","");
		else
			std::cerr << "[V] no filename for index given, not creating index" << std::endl;

		if ( indexfilename.size() )
		{
			libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex::unique_ptr_type Tindex(new libmaus2::bambam::BgzfDeflateOutputCallbackBamIndex(tmpfileindex));
			Pindex = UNIQUE_PTR_MOVE(Tindex);
			cbs.push_back(Pindex.get());
		}
	}
	std::vector< ::libmaus2::lz::BgzfDeflateOutputCallback * > * Pcbs = 0;
	if ( cbs.size() )
		Pcbs = &cbs;
	/*
	 * end md5/index callbacks
	 */

	::libmaus2::bambam::BamWriter::unique_ptr_type writer(new ::libmaus2::bambam::BamWriter(std::cout,uphead,level,Pcbs));
 	libmaus2::timing::RealTimeClock rtc; rtc.start();
 	
	libmaus2::bambam::BamAlignment & algn = dec.getAlignment();
	uint64_t c = 0;

	bool const resetaux = arginfo.getValue<int>("resetaux",getDefaultResetAux());
	libmaus2::bambam::BamAuxFilterVector::unique_ptr_type const prgfilter(libmaus2::bambam::BamAuxFilterVector::parseAuxFilterList(arginfo));
	libmaus2::bambam::BamAuxFilterVector const * rgfilter = prgfilter.get();

	while ( dec.readAlignment() )
	{
		bool const keep = resetAlignment(algn,resetaux /* reset aux */,excludeflags,rgfilter);
		
		if ( keep )
			algn.serialise(writer->getStream());

		if ( verbose && (++c & (1024*1024-1)) == 0 )
 			std::cerr << "[V] " << c/(1024*1024) << " " << (c / rtc.getElapsedSeconds()) << std::endl;
	}
	
	writer.reset();

	if ( Pmd5cb )
	{
		Pmd5cb->saveDigestAsFile(md5filename);
	}
	if ( Pindex )
	{
		Pindex->flush(std::string(indexfilename));
	}

	return EXIT_SUCCESS;
}
Example #5
0
    void CIFTREE_extract(std::ifstream & inFile, std::vector<Her::CIFTREE_idxEntry> jumpList, std::string outdir) {
        //// DECOMPRESS

        std::vector<uint8_t> outData;
        std::ostringstream outName;
        std::string outSuffix;
        std::ofstream outFile;

        std::map<std::string, std::string> extlist;

        int nWidth = (int)std::log10(jumpList.size())+1; // for zero-padding

        // we want the CIFLIST first, regardless of position in the tree, and
        // get the proper file extensions
        for (auto & i : jumpList) {
            if (i.fileName != "CIFLIST") {
                continue;
            }

            outData = ctext(i, inFile);

            std::string listfile((char*)outData.data(), outData.size());

            extlist = getexts(listfile);

            break; // we've gone through CIFLIST, nothing more to do here.
        }

        // now to actually process these files
        for (auto &i : jumpList) {
            outData = ctext(i, inFile);

            // handle TGA files if necessary
            if (i.fileType == 2) { // PLAIN (image)
                // XXX DECAL type probably doesn't hit this; should it?
                outData = Her::make_TGA(outData, i.xorigin, i.yorigin, i.imgWidth, i.imgHeight);
            }

            // figure out the extension
            try {
                outSuffix = extlist.at(i.fileName);
            } catch(std::exception & err) {
                std::cerr << "C++ ERROR: \n" << err.what() << "\n";
                std::cerr << "(Additional info:)\nTried \"" << i.fileName << "\" (" << i.fileName.size() << ")\n";
                throw 42;
            }

            // create path to save to
            outName << std::setw(nWidth) << std::setfill('0') << i.fileNo;
            outName << "_" << std::string(i.fileName.c_str()); // kill the null padding
            outName << outSuffix; // not using outSuffix to makeoutfile 'cos it currently segfaults, seemingly on path.stem, or something it does?

            // create filehandle and save
            outFile.open(Her::makeoutfile(outName.str(), outdir), std::ios::binary | std::ios::out);
            outFile.write((char*)(outData.data()), outData.size());
            outFile.close();

            // empty other variables
            outName.clear(); outName.str("");
            outData.clear();
        }
    }