Beispiel #1
0
// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
std::string InputFile::getShortName() {
  if (ParentName == "")
    return getName().lower();
  std::string Res = (getBasename(ParentName) + "(" +
                     getBasename(getName()) + ")").str();
  return StringRef(Res).lower();
}
void MatrixMulArgsParser::showUsage(std::string name) {
    std::cerr << "Usage: " << getBasename(name) << " <option(s)>\n"
        << "Options:\n"
        << "\t-h, --help\t\tShow this help message" << std::endl
        << "\t-l, --left INPUT\tLeft matrix file path" << std::endl
        << "\t-r, --right INPUT\tRight matrix file path" << std::endl
        << "\t-o, --output OUTPUT\tOutput matrix destination file" << std::endl
        << "\t-s, --size INTEGER\tSize of the input matrices [REQUIRED]" << std::endl
        << "\t-rn, --random\t\tGenerate random matrices." << std::endl
        << "\t-a, --algorithm TYPE\tType can have following values: " << std::endl
        << "\t\t\t\t\t 1 - Serial algorithm" << std::endl
        << "\t\t\t\t\t 2 - Parallel algorithm" << std::endl
        << "\nUsage notes:" << std::endl
        << "1. If --random is not present --left and --right options are [REQUIRED] " << std::endl
        << "2. --left and --right options will be ignored if --random option is present" << std::endl
        << "3. Matrix in the input file must have following format: " << std::endl
        << "\t [1, 2, 3, 4;" << std::endl
        << "\t  5, 6, 7, 8;" << std::endl
        << "\t  9, 10, 11, 12;" << std::endl
        << "\t  13, 14, 15, 16]" << std::endl
        << "   All whitespace characters are ignored." << std::endl
        << "   After the right bracket no content is allowed."<<std::endl
        << "   There is no ; at the end of the last row." << std::endl
        << "4. Size of the matrices must be a power of 2" << std::endl
        << "5. Make sure size of the matrices in the files corespond the parameter specified with --size option." << std::endl
        << "6. If --algorithm option is missing both serial and parallel algorithms will be done. Please note that serial version for big matrices can be really slow" << std::endl
        << "7. This version of program supports only integer numbers. Overflow is not handled so make sure numbers are not big!" << std::endl
        << std::endl;
}
Beispiel #3
0
std::string Misc::ResourceHelpers::correctResourcePath(const std::string &topLevelDirectory, const std::string &resPath, const VFS::Manager* vfs)
{
    /* Bethesda at some point converted all their BSA
     * textures from tga to dds for increased load speed, but all
     * texture file name references were kept as .tga.
     */

    std::string prefix1 = topLevelDirectory + '\\';
    std::string prefix2 = topLevelDirectory + '/';

    std::string correctedPath = resPath;
    Misc::StringUtils::lowerCaseInPlace(correctedPath);

    // Apparently, leading separators are allowed
    while (correctedPath.size() && (correctedPath[0] == '/' || correctedPath[0] == '\\'))
        correctedPath.erase(0, 1);

    if(correctedPath.compare(0, prefix1.size(), prefix1.data()) != 0 &&
       correctedPath.compare(0, prefix2.size(), prefix2.data()) != 0)
        correctedPath = prefix1 + correctedPath;

    std::string origExt = correctedPath;

    // since we know all (GOTY edition or less) textures end
    // in .dds, we change the extension
    bool changedToDds = changeExtensionToDds(correctedPath);
    if (vfs->exists(correctedPath))
        return correctedPath;
    // if it turns out that the above wasn't true in all cases (not for vanilla, but maybe mods)
    // verify, and revert if false (this call succeeds quickly, but fails slowly)
    if (changedToDds && vfs->exists(origExt))
        return origExt;

    // fall back to a resource in the top level directory if it exists
    std::string fallback = topLevelDirectory + "\\" + getBasename(correctedPath);
    if (vfs->exists(fallback))
        return fallback;

    if (changedToDds)
    {
        fallback = topLevelDirectory + "\\" + getBasename(origExt);
        if (vfs->exists(fallback))
            return fallback;
    }

    return correctedPath;
}
Beispiel #4
0
/*
    constructor. path is the path of image file.
*/
ExImage::ExImage(const string path)
{
    this->full_path   = path;
    this->win_name    = getBasename();
    this->img_mat     = cv::imread(path, 0);
    //cv::cvtColor(this->img_mat, this->img_mat, CV_BGR2GRAY);
    if (img_mat.empty())
        throw EImageError(
        "Cannot open image or file not exist.", EIMGREAD
        );
}
Beispiel #5
0
void* getVariable( char* user_name, char* dataset_path, char* var_name, char* roi )
{
    PyObject *pScript, *pModule, *pFunc, *pArgs;
	char buffer[250];

    char* script_path = "/Developer/Projects/iRODS/src-3.2/modules/cdms/python/CDMS_DataServices.py";
    char* method_name = "getCDMSVariable";

	PyRun_SimpleString("import sys");
	sprintf( buffer, "sys.path.insert(0, '%s')", getBasename(script_path) );
	PyRun_SimpleString(buffer);


	// Get the pointer of the function you want to call
	pScript = PyString_FromString( getFilename(script_path) );
	pModule = PyImport_Import(pScript);
	Py_DECREF(pScript);
    if (pModule != NULL) {
        pFunc = PyObject_GetAttrString(pModule, method_name );
        /* pFunc is a new reference */

        if (pFunc && PyCallable_Check(pFunc)) {
            pArgs = PyTuple_New( 3 );
            PyTuple_SetItem( pArgs, 0, PyString_FromString( dataset_path ) );
            PyTuple_SetItem( pArgs, 1, PyString_FromString( var_name ) );
            PyTuple_SetItem( pArgs, 2, PyString_FromString( roi ) );
            PyArrayObject *arr = (PyArrayObject*) PyObject_CallObject( pFunc, pArgs );
            Py_DECREF(pArgs);
            if (arr != NULL) {
                return arr;
            }
            else {
            	if( PyErr_Occurred() ) { PyErr_Print(); }
                fprintf(stderr,"Call failed\n");
            }
        }
        else {
            if( PyErr_Occurred() ) { PyErr_Print(); }
            fprintf(stderr, "Cannot find function \"%s\"\n", method_name );
        }
        Py_XDECREF(pFunc);
        Py_DECREF(pModule);
    }
    else {
        PyErr_Print();
        fprintf(stderr, "Failed to load \"%s\"\n", script_path );
    }
    return NULL;
}
bool LocaleBasedItemSorting::operator()(const MPD::Item &a, const MPD::Item &b) const
{
	bool result = false;
	if (a.type == b.type)
	{
		switch (a.type)
		{
			case MPD::itDirectory:
				result = m_cmp(getBasename(a.name), getBasename(b.name));
				break;
			case MPD::itPlaylist:
				result = m_cmp(a.name, b.name);
				break;
			case MPD::itSong:
				switch (m_sort_mode)
				{
					case SortMode::Name:
						result = m_cmp(*a.song, *b.song);
						break;
					case SortMode::ModificationTime:
						result = a.song->getMTime() > b.song->getMTime();
						break;
					case SortMode::CustomFormat:
						result = m_cmp(a.song->toString(Config.browser_sort_format, Config.tags_separator),
						               b.song->toString(Config.browser_sort_format, Config.tags_separator));
						break;
					case SortMode::NoOp:
						throw std::logic_error("can't sort with NoOp sorting mode");
				}
				break;
		}
	}
	else
		result = a.type < b.type;
	return result;
}
Beispiel #7
0
SourceFile::SourceFile(const std::string& fileName, const unsigned int minChars, const bool ignorePrepStuff)
    : m_absFileName(fileName),
      m_FileType(FileType::GetFileType(fileName)),
      m_ignorePrepStuff(ignorePrepStuff)
{
	m_fileName = getBasename();
	TextFile listOfFiles(m_absFileName.c_str());

	std::vector<std::string> lines;
	listOfFiles.readLines(lines);

	int openBlockComments = 0;
	for (int i = 0; i < (int)lines.size(); i++) {
		std::string& line = lines[i];
		std::string tmp;

		tmp.reserve(line.size());

		// Remove block comments
		if (FileType::FILETYPE_C == m_FileType || FileType::FILETYPE_CPP == m_FileType || FileType::FILETYPE_CXX == m_FileType || FileType::FILETYPE_H == m_FileType || FileType::FILETYPE_HPP == m_FileType || FileType::FILETYPE_JAVA == m_FileType || FileType::FILETYPE_CS == m_FileType) {
			int lineSize = (int)line.size();
			for (int j = 0; j < (int)line.size(); j++) {
				if (line[j] == '/' && line[MIN(lineSize - 1, j + 1)] == '*') {
					openBlockComments++;
				}

				if (openBlockComments <= 0) {
					tmp.push_back(line[j]);
				}

				if (line[MAX(0, j - 1)] == '*' && line[j] == '/') {
					openBlockComments--;
				}
			}
		}
		if (FileType::FILETYPE_VB == m_FileType) {
			tmp = line;
		}

		std::string cleaned;
		getCleanLine(tmp, cleaned);

		if (isSourceLine(cleaned, minChars)) {
			m_sourceLines.push_back(new SourceLine(cleaned, i));
		}
	}
	m_lines = (int)m_sourceLines.size();
}
Beispiel #8
0
const char* ckUtil::getExtension(const char* filename)
{
    if (!filename)
    {
        ckThrow(ExceptionInvalidArgument);
    }

    const char* ext = getBasename(filename);

    for ( ; *ext != '\0'; ext++)
    {
        if (*ext == '.')
        {
            return ext + 1;
        }
    }

    return ext;
}
void ColladaBodyLoaderImpl::convertToBody(Body& body)
{
    DaeNode* extNode = parser->findRootLink();

    if (!extNode) {
        SgGroup* scene = parser->createScene(fileName);
        if(scene){
            Link* link = body.createLink();
            link->setName("Root");
            link->setShape(scene);
            link->setMass(1.0);
            link->setInertia(Matrix3::Identity());
            body.setRootLink(link);
            body.setModelName(getBasename(fileName));
        }
        return;
    }

    int jointId = 0;
    links.clear();
    joints.clear();

    bool duplicate;
    Link* link = createLink(body, static_cast<DaeLink*>(extNode)->name, &duplicate);
    link->setName(static_cast<DaeLink*>(extNode)->name);

    body.setRootLink(link);
    // !!! important !!!
    // There is no category in the joint of collada.
    // But joint of the root node must be "FREE-TYPE" or "FIXED-TYPE".
    // Set to "FIXED-TYPE" if the link of the route had been "grounded". (Ex. PA10)
    // I have to set "FREE-TYPE" otherwise. (Ex. HRP4C, SR1, GR001, etc, etc)
    link->setJointType(extNode->transform.translate[2] == 0 ? Link::FIXED_JOINT : Link::FREE_JOINT); 
    body.setModelName(parser->findRootName());
    setPosition(extNode, link);

    buildLinks(extNode, extNode, link, body, jointId);

    body.updateLinkTree();
}
CustomGameStatsMenu::CustomGameStatsMenu() : MenuBase()
{
	// set up window
	SDL_Surface *surf;
	surf = pGFXManager->getUIGraphic(UI_MenuBackground);

	setBackground(surf,false);
	resize(surf->w,surf->h);

	setWindowWidget(&windowWidget);

	int localHouseColor = houseColor[pLocalHouse->getHouseID()];

	windowWidget.addWidget(&mainVBox, Point(24,23),	Point(screen->w - 48, screen->h - 32));

    captionLabel.setText(getBasename(currentGame->getGameInitSettings().getFilename(), true));
    captionLabel.setTextColor(localHouseColor + 3);
    captionLabel.setAlignment(Alignment_HCenter);
    mainVBox.addWidget(&captionLabel, 24);
    mainVBox.addWidget(VSpacer::create(24));

    mainVBox.addWidget(Spacer::create(), 0.05);

    mainVBox.addWidget(&mainHBox, 0.80);

    mainHBox.addWidget(Spacer::create(), 0.4);
    mainHBox.addWidget(&playerStatListVBox, 0.2);

    headerHBox.addWidget(&headerLabelDummy, 130);
    headerHBox.addWidget(Spacer::create(), 10);
    headerLabel1.setText(_("Built Object"));
    headerLabel1.setAlignment(Alignment_HCenter);
    headerLabel1.setTextColor(localHouseColor + 3);
    headerHBox.addWidget(&headerLabel1, 132);
    headerHBox.addWidget(Spacer::create(), 30);
    headerLabel2.setText(_("Destroyed"));
    headerLabel2.setAlignment(Alignment_HCenter);
    headerLabel2.setTextColor(localHouseColor + 3);
    headerHBox.addWidget(&headerLabel2, 132);
    headerLabel3.setText(_("Harvested Spice"));
    headerLabel3.setAlignment(Alignment_HCenter);
    headerLabel3.setTextColor(localHouseColor + 3);
    headerHBox.addWidget(Spacer::create(), 30);
    headerHBox.addWidget(&headerLabel3, 132);

    playerStatListVBox.addWidget(&headerHBox, 25);

    playerStatListVBox.addWidget(VSpacer::create(15));

    int maxBuiltValue = 0;
    int maxDestroyedValue = 0;
    float maxSpiceHarvested = 0.0;

    for(int i=0;i<NUM_HOUSES;i++) {
        House* pHouse = currentGame->getHouse(i);

        if(pHouse != NULL) {
            maxBuiltValue = std::max(maxBuiltValue, pHouse->getBuiltValue());
            maxDestroyedValue = std::max(maxDestroyedValue, pHouse->getDestroyedValue());
            maxSpiceHarvested = std::max(maxSpiceHarvested, pHouse->getHarvestedSpice());
        }
    }

    for(int i=0;i<NUM_HOUSES;i++) {
        HouseStat& curHouseStat = houseStat[i];
        House* pHouse = currentGame->getHouse(i);

        if(pHouse != NULL) {
            int color = houseColor[i];

            curHouseStat.houseName.setText(_("House") + " " + getHouseNameByNumber((HOUSETYPE) i));
            curHouseStat.houseName.setTextColor(color + 3);
            curHouseStat.houseHBox.addWidget(&curHouseStat.houseName, 140);
            curHouseStat.houseHBox.addWidget(Spacer::create(), 15);

            curHouseStat.value1.setText( stringify(pHouse->getBuiltValue()*100));
            curHouseStat.value1.setTextFont(FONT_STD10);
            curHouseStat.value1.setAlignment(Alignment_Right);
            curHouseStat.value1.setTextColor(color + 3);
            curHouseStat.houseHBox.addWidget(&curHouseStat.value1, 50);
            curHouseStat.houseHBox.addWidget(HSpacer::create(2));
            curHouseStat.progressBar1.setProgress( (maxBuiltValue == 0) ? 0.0 : (pHouse->getBuiltValue() * 100.0f / maxBuiltValue));
            curHouseStat.progressBar1.setDrawShadow(true);
            curHouseStat.progressBar1.setColor(color + 1);
            curHouseStat.vBox1.addWidget(Spacer::create(), 0.5);
            curHouseStat.vBox1.addWidget(&curHouseStat.progressBar1, 12);
            curHouseStat.vBox1.addWidget(Spacer::create(), 0.5);
            curHouseStat.houseHBox.addWidget(&curHouseStat.vBox1, 80);

            curHouseStat.houseHBox.addWidget(Spacer::create(), 30);

            curHouseStat.value2.setText( stringify(pHouse->getDestroyedValue()*100));
            curHouseStat.value2.setTextFont(FONT_STD10);
            curHouseStat.value2.setAlignment(Alignment_Right);
            curHouseStat.value2.setTextColor(color + 3);
            curHouseStat.houseHBox.addWidget(&curHouseStat.value2, 50);
            curHouseStat.houseHBox.addWidget(HSpacer::create(2));
            curHouseStat.progressBar2.setProgress( (maxDestroyedValue == 0) ? 0.0 : (pHouse->getDestroyedValue() * 100.0f / maxDestroyedValue));
            curHouseStat.progressBar2.setDrawShadow(true);
            curHouseStat.progressBar2.setColor(color + 1);
            curHouseStat.vBox2.addWidget(Spacer::create(), 0.5);
            curHouseStat.vBox2.addWidget(&curHouseStat.progressBar2, 12);
            curHouseStat.vBox2.addWidget(Spacer::create(), 0.5);
            curHouseStat.houseHBox.addWidget(&curHouseStat.vBox2, 80);

            curHouseStat.houseHBox.addWidget(Spacer::create(), 30);

            curHouseStat.value3.setText( stringify((int) pHouse->getHarvestedSpice()));
            curHouseStat.value3.setTextFont(FONT_STD10);
            curHouseStat.value3.setAlignment(Alignment_Right);
            curHouseStat.value3.setTextColor(color + 3);
            curHouseStat.houseHBox.addWidget(&curHouseStat.value3, 50);
            curHouseStat.houseHBox.addWidget(HSpacer::create(2));
            curHouseStat.progressBar3.setProgress( (maxSpiceHarvested == 0.0) ? 0.0 : (pHouse->getHarvestedSpice() * 100.0f / maxSpiceHarvested));
            curHouseStat.progressBar3.setDrawShadow(true);
            curHouseStat.progressBar3.setColor(color + 1);
            curHouseStat.vBox3.addWidget(Spacer::create(), 0.5);
            curHouseStat.vBox3.addWidget(&curHouseStat.progressBar3, 12);
            curHouseStat.vBox3.addWidget(Spacer::create(), 0.5);
            curHouseStat.houseHBox.addWidget(&curHouseStat.vBox3, 80);

            playerStatListVBox.addWidget(&curHouseStat.houseHBox, 20);

            playerStatListVBox.addWidget(VSpacer::create(15));
        }
    }

    mainHBox.addWidget(Spacer::create(), 0.4);

    mainVBox.addWidget(Spacer::create(), 0.05);

    mainVBox.addWidget(VSpacer::create(20));
	mainVBox.addWidget(&buttonHBox, 24);
	mainVBox.addWidget(VSpacer::create(14), 0.0);

    buttonHBox.addWidget(HSpacer::create(70));
    int totalTime = currentGame->getGameTime()/1000;
    timeLabel.setText(strprintf(_("@DUNE.ENG|22#Time: %d:%02d"), totalTime/3600, (totalTime%3600)/60));
    timeLabel.setTextColor(localHouseColor + 3);
	buttonHBox.addWidget(&timeLabel, 0.2);

	buttonHBox.addWidget(HSpacer::create(20));

	int nbdays = currentGame->getNumberOfDays();
	std::string  phase = currentGame->getDayPhaseString();
	std::string qualif,sepa, daycal, daytext;
	if (nbdays == 1) {
		qualif = (_("st"));
	} else if (nbdays == 2) {
		qualif = (_("nd"));
	} else {
		qualif = (_("th"));;
	}


	daycal= (_("on the"));

	daytext = phase+" "+daycal+" "+ std::to_string(nbdays)+ qualif+sepa;
    dayLabel.setText(daytext);
    dayLabel.setTextColor(localHouseColor + 3);
    if ( currentGame->getGameInitSettings().getGameOptions().daynight ) {
    	buttonHBox.addWidget(&dayLabel, 0.2);
    }

	buttonHBox.addWidget(Spacer::create(), 0.0625);
	buttonHBox.addWidget(Spacer::create(), 0.475);
	buttonHBox.addWidget(Spacer::create(), 0.0625);

    okButton.setText(_("OK"));
    okButton.setTextColor(localHouseColor + 3);
	okButton.setOnClick(std::bind(&CustomGameStatsMenu::onOK, this));
	buttonHBox.addWidget(&okButton, 0.2);
	buttonHBox.addWidget(HSpacer::create(90));
}
Beispiel #11
0
void findExecutablePath()
{
#ifdef _WIN32
    static const int BUFSIZE = 1024;
    TCHAR execFilePath[BUFSIZE];
    if(GetModuleFileName(NULL, execFilePath, BUFSIZE)){
#ifndef UNICODE
        executablePath_ = execFilePath;
#else
        int codepage = _getmbcp();
        const int newSize = WideCharToMultiByte(codepage, 0, execFilePath, -1, NULL, 0, NULL, NULL);
        if(newSize > 0){
            vector<filesystem::path::String> execFilePathMB(newSize + 1);
            newSize = WideCharToMultiByte(codepage, 0, execFilePath, -1, &execFilePathMB[0], newSize + 1, NULL, NULL);
            executablePath_ = execFilePathUtf8;
            ;
        }
#endif // UNICODE
    }
#endif

#ifdef __linux__
    utsname info;
    if(uname(&info) == 0){
        if(strncmp(info.sysname, "Linux", 6) == 0){
            static const int BUFSIZE = 1024;
            char buf[BUFSIZE];
            int n = readlink("/proc/self/exe", buf, BUFSIZE - 1);
            buf[n] = 0;
            executablePath_ = buf;
        }
    }
#endif

#ifdef MACOSX
    char buf[1024];
    uint32_t n = sizeof(buf);
    if(_NSGetExecutablePath(buf, &n) == 0){
        executablePath_ = buf;
    }
        
    filesystem::path path;
    // remove dot from a path like bin/./choreonoid
    makePathCompact(filesystem::path(executablePath_), path);
    //filesystem::path path = filesystem::canonical(filesystem::path(executablePath_));
#else
    filesystem::path path(executablePath_);
#endif

    filesystem::path topPath = path.parent_path().parent_path();
    executableTopDirectory_ = topPath.string();
        
    filesystem::path sharePath = topPath / CNOID_SHARE_SUBDIR;
    if(filesystem::is_directory(sharePath)){
        shareDirectory_ = getNativePathString(sharePath);

    } else if(filesystem::is_directory(sharePath.parent_path())){
        shareDirectory_ = getNativePathString(sharePath.parent_path());

    } else if(topPath.has_parent_path()){ // case of a sub build directory
        sharePath = topPath.parent_path() / "share";
        if(filesystem::is_directory(sharePath)){
            shareDirectory_ = getNativePathString(sharePath);
        }
    }

#ifdef _WIN32
    if(path.extension() == ".exe"){
        executableBasename_ = getBasename(path);
    } else {
        executableBasename_ = getFilename(path);
    }
#else
    executableBasename_ = getFilename(path);
#endif
}