//----------------------------------------------------------------------------- bool remove_directory( std::string path ) { boost::system::error_code ec; boost::filesystem::path _path( path ); if( !boost::filesystem::exists( _path, ec ) ) { // if the directory does not exist, bail out std::cerr << ec.message() << std::endl; return false; } // verify that it is a directory if( !boost::filesystem::is_directory( _path, ec ) ) { // path exists but not as a directory. take no action and bail std::cerr << ec.message() << std::endl; return false; } boost::filesystem::remove_all( _path, ec ); if( ec != boost::system::errc::success ) { std::cerr << ec.message() << std::endl; return false; } return true; }
std::string ToolchainItem::colorStr(std::string const& _var) const { if (!library()) return std::string(); if (!valid()) { std::string _path(std::string("invalid_") + _var); if (!pathExists(_path)) { return (_var != "light") ? "#e74c3c" : "#6b2018"; } else { return library()->config().get<std::string>(tbd::ConfigPath("colorset") / tbd::ConfigPath(_path)); } } auto& _cfg = library()->config(); tbd::ConfigPath _toolsetId(elementId().toolset().str()); tbd::ConfigPath _typeId(elementId().typeId().str()); tbd::ConfigPath _path = _toolsetId / _typeId / tbd::ConfigPath(_var); std::cout << _path.dump() << std::endl; if (pathExists(_path.dump())) { return _cfg.get<std::string>(ConfigPath("colorset") /_path); } _path = _toolsetId / tbd::ConfigPath(_var); if (pathExists(_path.dump())) { return _cfg.get<std::string>(ConfigPath("colorset") /_path); } return (_var != "light") ? "#405959" : "#9ed8db"; }
/* * spec_archive() - Archive a spec onto the given XDR stream. */ bool_t spec_archive( char *id, char *path, int verbosity, XDR *xdrs, Tt_status *err ) { _Tt_string _path( path ); _Tt_string _id( id ); *err = TT_OK; if (xdrs->x_op == XDR_ENCODE) { Lstar_spec spec( _id, _path ); *err = spec.read_self(); if (IS_TT_ERR(*err)) { return FALSE; } if (! spec.xdr(xdrs)) { return FALSE; } if (verbosity > 1) { spec.print( stderr ); } } else { return FALSE; } return TRUE; } /* spec_archive() */
void _list_dir_r(const std::string dir, std::vector<std::string>& files) { struct dirent* ent = NULL; DIR *pDir; pDir = opendir(dir.c_str()); if (pDir == NULL) { //被当作目录,但是执行opendir后发现又不是目录,比如软链接就会发生这样的情况。 return; } while (NULL != (ent = readdir(pDir))) { if (ent->d_type == 8) { //file files.push_back(ent->d_name); } else { if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) { continue; } //directory std::string _path(dir); std::string _dirName(ent->d_name); std::string fullDirPath = _path + "/" + _dirName; _list_dir_r(fullDirPath.c_str(), files); } } }
void muzzley::init(HTTPReq& _req) { time_t _rawtime = time(nullptr); struct tm _ptm; char _buffer_date[80]; localtime_r(&_rawtime, &_ptm); strftime(_buffer_date, 80, "%a, %d %b %Y %X %Z", &_ptm); char _buffer_expires[80]; _ptm.tm_hour += 1; strftime(_buffer_expires, 80, "%a, %d %b %Y %X %Z", &_ptm); string _url(_req->url()); if (_url != "") { size_t _b = _url.find("://") + 3; size_t _e = _url.find("/", _b); string _domain(_url.substr(_b, _e - _b)); string _path(_url.substr(_e)); _req->header("Host", _domain); _req->url(_path); } _req->method(muzzley::HTTPGet); _req->header("Connection", "close"); _req->header("User-Agent", "muzzley rest-ful server"); _req->header("Cache-Control", "max-age=3600"); _req->header("Vary", "Accept-Language,Accept-Encoding,X-Access-Token,Authorization,E-Tag"); _req->header("Date", string(_buffer_date)); }
void CachedImage::_saveFile(QByteArray* data) const { auto path = _path(); qDebug() << "Saving image from" << _url << "to" << path; if (_man->maxWidth() && _format != UnknownFormat && _format != GifFormat) { auto pic = QImage::fromData(*data); if (pic.width() > _man->maxWidth()) { pic = pic.scaledToWidth(_man->maxWidth(), Qt::SmoothTransformation); QBuffer buffer(data); buffer.open(QIODevice::WriteOnly | QIODevice::Truncate); pic.save(&buffer, _extension.toLatin1().data()); } } QFile file(path); if (file.open(QIODevice::WriteOnly)) { file.write(*data); file.close(); } else qDebug() << "Cannot open file for writing:" << path; delete data; }
// 根据相对路径获取绝对路径 // 如果relativePath已经是绝对路径,则直接返回 // 否则将返回appPath+relativePath wstring getAbsolutePath(wstring &relativePath, wstring &appPath){ if (relativePath.find(L":") == -1){// 如果指定的路径是相对路径 wstring _path(appPath); _path.append(relativePath); return _path; } return relativePath; }
Image::Image() { std::string _path(""); cv::Mat _image; cv::Mat _roi; std::vector< cv::KeyPoint > _keypoints; cv::Mat _descriptors; std::map< std::string, image_match* > _matches; }
bool RomCommon::RomUIDataSource::LoadLocalResources(std::string filePath) { if(filePath.empty()) { RomCommon::Logger::getInstance()->Log("RomUIDataSource :: Unable to load a UI file - filename is empty", LOG_ERROR); return false; } namespace fs = boost::filesystem; try { // Get the path to folder from the basePath of the resource std::string pathToFile = ResourceManager::getInstance()->GetUIBasePath(); pathToFile.append(filePath); fs::path _path(pathToFile); fs::path _dirPath = _path.parent_path(); for(fs::recursive_directory_iterator dir_end, dir(_dirPath); dir != dir_end; ++dir) { fs::path current(*dir); if(fs::is_regular_file(current) && !fs::is_directory(current)) { std::string name = fs::complete(current).string(); std::string content = ""; name = name.substr(ResourceManager::getInstance()->GetUIBasePath().length()); std::replace(name.begin(), name.end(), '\\', '/'); std::ifstream input(fs::complete(current).string()); if(input.is_open()) { std::stringstream buffer; buffer << input.rdbuf(); content = buffer.str(); input.close(); } else { RomCommon::Logger::getInstance()->Log("RomUIDataSource :: Unable to load a UI file - cannot open file", LOG_ERROR); return false; } this->_loadedResources[name] = content; } } } catch (fs::filesystem_error e) { std::string message = "RomCommon::UI::DataSource => Could not parse ui base file path: "; message.append(e.what()); Logger::getInstance()->Log(message, LOG_ERROR); return false; } return true; }
std::string urdf_traverser::helpers::getDirectory(const std::string& path) { if (urdf_traverser::helpers::isDirectoryPath(path)) return path; // already ends with '/' // does not end with '/' so it must be a file: get the parent boost::filesystem::path _path(path); std::string ret = _path.parent_path().string(); // enforce notation to be a directory as we now know it is one urdf_traverser::helpers::enforceDirectory(ret, false); return ret; }
void FacebookAgent::api(std::string &path, int method, FBInfo ¶ms, FBCallback cb) { requestCallbacks.push_back(cb); PluginParam _path(path.c_str()); PluginParam _method(method); PluginParam _params(params); PluginParam _cbIndex((int)(requestCallbacks.size() - 1)); agentManager->getUserPlugin()->callFuncWithParam("request", &_path, &_method, &_params, &_cbIndex, NULL); }
bool urdf_traverser::helpers::getRelativeDirectory(const std::string& path, const std::string& relTo, std::string& result) { // ROS_INFO_STREAM("Get relative dir of "<<path<<" to "<<relTo); boost::filesystem::path _path(boost::filesystem::absolute(path)); boost::filesystem::path _relTo(boost::filesystem::absolute(relTo)); std::string commonParent; if (!getCommonParentPath(path, relTo, commonParent)) { ROS_ERROR_STREAM("Directories " << path << " and " << relTo << " have no common parent directory."); return false; } // ROS_INFO_STREAM("Common parent: "<<commonParent); // get both directories relative to the common parent directory: std::string relPath; if (!urdf_traverser::helpers::getSubdirPath(commonParent, path, relPath)) { ROS_ERROR_STREAM("The file " << path << " is not in a subdirectory of " << commonParent); return false; } // ROS_INFO_STREAM("Path relative to common: "<<relPath); std::string relToTarget; if (!urdf_traverser::helpers::getSubdirPath(commonParent, relTo, relToTarget)) { ROS_ERROR_STREAM("Relative path " << relTo << " is not a subdirectory of " << commonParent); return false; } // ROS_INFO_STREAM("relTo relative to common: "<<relToTarget); // make sure this is a directory, not a file (remove filename if that's the case) std::string relToDir = getDirectory(relToTarget); // ROS_INFO_STREAM("relTo relative to common: "<<relToDir); // Go up in the hierarchie the number of directories in \e relTo which it takes // to get to the common parent directory int relToLen = numDirectories(relToDir); // ROS_INFO_STREAM("Num dirs in "<<relToTarget<<"("<<relToDir<<"):"<<relToLen); std::stringstream upDirs; for (int i = 0; i < relToLen; ++i) upDirs << ".." << boost::filesystem::path::preferred_separator; // append the relative path from common parent dir to \e path upDirs << relPath; result = upDirs.str(); return true; }
void SPSSImporterTest::spssTester_data() { QTest::addColumn<QString>("filename"); boost::filesystem::path _path(TESTFILE_FOLDER "spssimporter_test/spss_files"); //add files to be tested in a folder "Resources/TestFiles/spssimporter_test/spss_files" for (auto i = boost::filesystem::directory_iterator(_path); i != boost::filesystem::directory_iterator(); i++) { if (!boost::filesystem::is_directory(i->path())) //we eliminate directories { QTest::newRow("spss file test") << QString::fromStdString(i->path().filename().string()); } } }
/* * dearchive_this_path() - Should we extract this <path> from its archive? * * Returns true if *ppaths_to_extract is an empty list. */ bool_t dearchive_this_path( char *path, void *ppaths_to_extract ) { _Tt_string_list_ptr paths; _Tt_string _path( path ); if (ppaths_to_extract == NULL) { return TRUE; } paths = *(_Tt_string_list_ptr *)ppaths_to_extract; if (paths->count() <= 0) { return TRUE; } return is_child_in( _path, paths ); } /* dearchive_this_path() */
////////////////////////////////////////////////////////////////////// // resolve path for job execution host // std::string staging_path_builder::resolve_local(const std::string& path) { boost::filesystem::path _path(path); #if 0 if (_path.empty()) { // throw } #endif if (_path.has_root_directory()) { return path; } boost::filesystem::path x = workdir / _path; x.normalize(); return x.string(); }
FontRenderer* FontRenderer::LoadFromFile(const char *path, SpriteBatch *spriteBatch) { assert(spriteBatch != NULL); FontLetter texLetters[256]; XMLNode *xmlDoc = XMLLoader::LoadFromFile(path); if (xmlDoc == NULL) return NULL; std::string bmpFilename = xmlDoc->GetAttribAsString("bitmap"); if (bmpFilename.empty()) return NULL; Path _path(path); Texture *tex = LoadFontBitmap(_path.GetPath() + bmpFilename); if (tex == NULL) return NULL; if (xmlDoc->GetName() != "alphabet") { delete xmlDoc; return NULL; } for (uint32_t i = 0; i < xmlDoc->GetChildrenCount(); i++) { std::string letter = xmlDoc[i].GetAttribAsString("letter"); std::string bounds = xmlDoc[i].GetAttribAsString("bounds"); sm::Rect<int> boundsValues; if (!ParseBounds(bounds, boundsValues)) return NULL; texLetters[letter[0]].Size = sm::Point<int>(boundsValues.Width, boundsValues.Height); texLetters[letter[0]].Coords = TexPart(tex, boundsValues); } FontRenderer *fontRenderer = new FontRenderer(); fontRenderer->m_spriteBatch = spriteBatch; if (fontRenderer != NULL) { memcpy(fontRenderer ->texLetters, texLetters, sizeof(FontLetter) * 256); } return fontRenderer; }
void CachedImage::saveToFile(const QString& filename) { if (!_available) return; if (filename.isEmpty()) return; auto pathTo = QString("%1/Taaasty/") .arg(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); QDir dirTo; dirTo.mkpath(pathTo); auto to = QString("%1%2%3%4") .arg(pathTo) .arg(filename) .arg(_extension.isEmpty() ? QString() : ".") .arg(_extension); if (QFile::exists(to))// && !QFile::remove(to)) { qDebug() << "File exists" << to; emit Tasty::instance()->error(0, QString("Файл уже существует:\n%1").arg(to)); emit savingError(); return; } if (!QFile::copy(_path(), to)) { qDebug() << "Error copying" << to; emit Tasty::instance()->error(0, QString("Не удалось сохранить изображение в %1").arg(to)); emit savingError(); return; } emit Tasty::instance()->info(QString("Изображение сохранено в %1").arg(to)); emit fileSaved(); }
// resolve path for qsub execution host std::string staging_path_builder::resolve_remote(const std::string& path) { boost::filesystem::path _path(path); std::ostringstream os; os << remotehost << ":"; #if 0 if (_path.empty()) { // throw } #endif if (_path.has_root_directory()) { os << path; } else { boost::filesystem::path x = boost::filesystem::current_path(); x /= _path; x.normalize(); os << x.string(); } return os.str(); }
int numDirectories(const std::string& path) { // ROS_INFO_STREAM("cnt of path "<<path); int cnt = 0; boost::filesystem::path _path(path); boost::filesystem::path::iterator it(_path.begin()); boost::filesystem::path::iterator it_end(_path.end()); for (; it != it_end; ++it) { // ROS_INFO_STREAM(it->string()); // if (it->string()==".") continue; // because "./" leads to a count of 1 too but should be 0 ++cnt; } if (cnt > 0) { // count is always one more, as last directory // is either '.', or it is a file which doesn't count --cnt; } // ROS_INFO_STREAM("Res: "<<cnt); return cnt; }
QUrl CachedImage::source() const { return QUrl::fromLocalFile(_path()); }