当前位置: 首页>>代码示例>>C++>>正文


C++ path::relative_path方法代码示例

本文整理汇总了C++中boost::filesystem::path::relative_path方法的典型用法代码示例。如果您正苦于以下问题:C++ path::relative_path方法的具体用法?C++ path::relative_path怎么用?C++ path::relative_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在boost::filesystem::path的用法示例。


在下文中一共展示了path::relative_path方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: naive_uncomplete

boost::filesystem::path naive_uncomplete(boost::filesystem::path const path, 
    boost::filesystem::path const base) {
    if (path.has_root_path()){
        if (path.root_path() != base.root_path()) {
            return path;
        } else {
            return naive_uncomplete(path.relative_path(), base.relative_path());
        }
    } else {
        if (base.has_root_path()) {
            throw "cannot uncomplete a path relative path from a rooted base";
        } else {
            typedef boost::filesystem::path::const_iterator path_iterator;
            path_iterator path_it = path.begin();
            path_iterator base_it = base.begin();
            while ( path_it != path.end() && base_it != base.end() ) {
                if (*path_it != *base_it) break;
                ++path_it; ++base_it;
            }
            boost::filesystem::path result;
            for (; base_it != base.end(); ++base_it) {
                result /= "..";
            }
            for (; path_it != path.end(); ++path_it) {
                result /= *path_it;
            }
            return result;
        }
    }
}
开发者ID:Gohla,项目名称:Diversia,代码行数:30,代码来源:ResourceManager.cpp

示例2: iterate

/**
 * Iterate over a directory.
 *
 * @param dir Directory to iterate over.
 */
void Dir_Parse::iterate(fs::path dir) {
	fs::directory_iterator end_iter;
	vector<fs::path> dirs;

	#ifdef DEBUG
	cout << endl << "==== " << string(dir.relative_path().c_str()).substr(cut_path) << " ===="  << endl;
	#endif

	for (fs::directory_iterator dir_itr(dir); dir_itr != end_iter; ++dir_itr) {
		try {
			// Ignore hidden directories.
			if (dir_itr->path().filename().c_str()[0] != '.') {
				if (fs::is_directory(dir_itr->status())) {
					// Directory
					#ifdef DEBUG
					cout << dir_itr->path().filename() << " - Directory" << endl;
					#endif

					dirs.push_back(dir_itr->path());
				} else if (fs::is_regular_file(dir_itr->status())) {
					// File
					vector<string> datasheet;
					vector<string> tags = get_tags(dir_itr->path());

					datasheet.push_back(string(dir_itr->path().c_str()));
					datasheet.push_back(boost::algorithm::join(tags, ","));

					datasheets.push_back(datasheet);

					#ifdef DEBUG
					cout << trim_path(dir_itr->path()) << endl;
					cout << dir_itr->path().filename() << " - File" << endl;

					for (size_t i = 0; i < tags.size(); ++i) {
						cout << tags[i];

						if (i < tags.size() - 1) {
							cout << ", ";
						} else {
							cout << endl << endl;
						}
					}
					#endif
				}
				#ifdef DEBUG
				else {
					// Other
					cout << dir_itr->path().filename() << ": WTF is this?!" << endl;
				}
				#endif
			}
		} catch (const exception &e) {
			cout << dir_itr->path().filename() << ": " << e.what() << endl;
		}
	}

	for (size_t i = 0; i < dirs.size(); ++i) {
		iterate(dirs[i]);
	}
}
开发者ID:nathanpc,项目名称:sheets,代码行数:65,代码来源:dir_parse.cpp

示例3: LoadBlobWithParent

CryDevice::BlobWithParent CryDevice::LoadBlobWithParent(const bf::path &path) {
  optional<unique_ref<DirBlobRef>> parentBlob = none;
  optional<unique_ref<FsBlobRef>> currentBlobOpt = _fsBlobStore->load(_rootKey);
  if (currentBlobOpt == none) {
    LOG(ERROR) << "Could not load root blob. Is the base directory accessible?";
    throw FuseErrnoException(EIO);
  }
  unique_ref<FsBlobRef> currentBlob = std::move(*currentBlobOpt);

  for (const bf::path &component : path.relative_path()) {
    auto currentDir = dynamic_pointer_move<DirBlobRef>(currentBlob);
    if (currentDir == none) {
      throw FuseErrnoException(ENOTDIR); // Path component is not a dir
    }

    auto childOpt = (*currentDir)->GetChild(component.c_str());
    if (childOpt == boost::none) {
      throw FuseErrnoException(ENOENT); // Child entry in directory not found
    }
    Key childKey = childOpt->key();
    auto nextBlob = _fsBlobStore->load(childKey);
    if (nextBlob == none) {
      throw FuseErrnoException(ENOENT); // Blob for directory entry not found
    }
    parentBlob = std::move(*currentDir);
    currentBlob = std::move(*nextBlob);
  }

  return BlobWithParent{std::move(currentBlob), std::move(parentBlob)};

  //TODO (I think this is resolved, but I should test it)
  //     Running the python script, waiting for "Create files in sequential order...", then going into dir ~/tmp/cryfs-mount-.../Bonnie.../ and calling "ls"
  //     crashes cryfs with a sigsegv.
  //     Possible reason: Many parallel changes to a directory blob are a race condition. Need something like ParallelAccessStore!
}
开发者ID:cryfs,项目名称:cryfs,代码行数:35,代码来源:CryDevice.cpp

示例4: it

 void
 TeaSafe::removeDeletedParentFromCache(boost::filesystem::path const &path)
 {
     auto it(m_folderCache.find(path.relative_path().string()));
     if (it != m_folderCache.end()) {
         m_folderCache.erase(it);
     }
 }
开发者ID:airk42,项目名称:teasafe,代码行数:8,代码来源:TeaSafe.cpp

示例5: MakePathRelative

 boost::filesystem::path MultiresImagePlugin::MakePathRelative(boost::filesystem::path path, boost::filesystem::path base)
 {
   // Borrowed from: https://svn.boost.org/trac/boost/ticket/1976#comment:2
   if (path.has_root_path())
   {
     if (path.root_path() != base.root_path())
     {
       return path;
     }
     else
     {
       return MakePathRelative(path.relative_path(), base.relative_path());
     }
   }
   else
   {
     if (base.has_root_path())
     {
       ROS_WARN("Cannot uncomplete a path relative path from a rooted base.");
       return path;
     }
     else
     {
       typedef boost::filesystem::path::const_iterator path_iterator;
       path_iterator path_it = path.begin();
       path_iterator base_it = base.begin();
       while (path_it != path.end() && base_it != base.end())
       {
         if (*path_it != *base_it)
           break;
         ++path_it;
         ++base_it;
       }
       boost::filesystem::path result;
       for (; base_it != base.end(); ++base_it)
       {
         result /= "..";
       }
       for (; path_it != path.end(); ++path_it)
       {
         result /= *path_it;
       }
       return result;
     }
   }
 }
开发者ID:malban,项目名称:mapviz,代码行数:46,代码来源:multires_image_plugin.cpp

示例6: genImgsList

/**
 * Function to return list of images in a directory (searched recursively).
 * The output paths are w.r.t. the path imgsDir
 */
void genImgsList(const fs::path& imgsDir, vector<fs::path>& list) {
  if(!fs::exists(imgsDir) || !fs::is_directory(imgsDir)) return;
  vector<string> imgsExts = {".jpg", ".png", ".jpeg", ".JPEG", ".PNG", ".JPG"};

  fs::recursive_directory_iterator it(imgsDir);
  fs::recursive_directory_iterator endit;
  while(it != endit) {
    if(fs::is_regular_file(*it) && 
        find(imgsExts.begin(), imgsExts.end(), 
          it->path().extension()) != imgsExts.end())
      // write out paths but clip out the initial relative path from current dir 
      list.push_back(fs::path(it->path().relative_path().string().
            substr(imgsDir.relative_path().string().length())));
    ++it;
  }
  LOG(INFO) << "Found " << list.size() << " image file(s) in " << imgsDir;
}
开发者ID:rohitgirdhar,项目名称:ComputeFeatures,代码行数:21,代码来源:utils.hpp

示例7: GetSubShaderTypeFromFile

SUBSHADERTYPE AssetManager::GetSubShaderTypeFromFile(boost::filesystem::path path)
{
  std::string subshaderfile = path.relative_path().stem().string();
  subshaderfile = subshaderfile.substr(subshaderfile.find("_") + 1);

  std::transform(subshaderfile.begin(), subshaderfile.end(), subshaderfile.begin(), ::tolower);

  SUBSHADERTYPE sstype;
  if (subshaderfile == VSfilstr)
    sstype = VERTEX_SHADER;
  else if (subshaderfile == PSfilstr)
    sstype = PIXEL_SHADER;
  else if (subshaderfile == CSfilstr)
	sstype = COMPUTE_SHADER;
  else if (subshaderfile == GSfilstr)
	sstype = GEOMETRY_SHADER;

  return sstype;
}
开发者ID:Reticulatas,项目名称:MochaEngineFinal,代码行数:19,代码来源:AssetManager.cpp

示例8: it

    void
    CoreFS::removeFolderFromCache(::boost::filesystem::path const &path)
    {

        auto strPath = path.relative_path().string();
        // need to reset root path if root, otherwise
        // we'll continue to use 'cached' version
        if(strPath == "/") {
            removeAllChildFoldersToo(path, m_rootFolder);
            m_rootFolder = std::make_shared<CompoundFolder>(m_io, m_io->rootBlock, "root");
            return;
        }

        // else belongs to cache
        auto it(m_folderCache.find(strPath));
        if (it != m_folderCache.end()) {
            removeAllChildFoldersToo(path, it->second);
            m_folderCache.erase(it);
        }
    }
开发者ID:benhj,项目名称:KnoxCrypt,代码行数:20,代码来源:CoreFS.cpp


注:本文中的boost::filesystem::path::relative_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。