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


C++ FilePath::getUpDir方法代码示例

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


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

示例1: getApplicationDir

FileDir FileDir::getApplicationDir()
{
#ifdef WIN32
  unsigned int pathSize=512;
  ByteArray tmpPath;
  tmpPath.resize( pathSize );
  GetModuleFileName( 0, tmpPath.data(), pathSize);
  FilePath tmp = tmpPath.data();

  tmp = tmp.getUpDir();
  //delete tmpPath;

  return tmp;
#elif defined(__linux__)
  char exe_path[PATH_MAX] = {0};
  char * dir_path;
  sprintf(exe_path, "/proc/%d/exe", getpid());
  readlink(exe_path, exe_path, sizeof(exe_path));
  dir_path = dirname(exe_path);
  return FilePath(dir_path);
#elif defined(__APPLE__)
  char exe_path[PROC_PIDPATHINFO_MAXSIZE];
  int ret = proc_pidpath(getpid(), exe_path, sizeof(exe_path));
  if (ret <= 0)
  {
    THROW("Cannot get application executable file path");
  }
  return FilePath(dirname(exe_path));
#endif

  return FilePath( "." );
}
开发者ID:hellium,项目名称:opencaesar3,代码行数:32,代码来源:oc3_filepath.cpp

示例2: flattenFilename

//! flatten a path and file name for example: "/you/me/../." becomes "/you"
FilePath FilePath::flattenFilename( const FilePath& root ) const
{
  std::string directory = addEndSlash().toString();
  directory = StringHelper::replace( directory, "\\", "/" );
  
  FilePath dir;
  FilePath subdir;

  int lastpos = 0;
  std::string::size_type pos = 0;
  bool lastWasRealDir=false;

  while( ( pos = directory.find( '/', lastpos) ) != std::string::npos )
  {
    subdir = FilePath( directory.substr(lastpos, pos - lastpos + 1) );

    if( subdir.toString() == "../" )
    {
      if (lastWasRealDir)
      {
        dir = dir.getUpDir();
        dir = dir.getUpDir();
        lastWasRealDir=( dir.toString().size()!=0);
      }
      else
      {
        dir = FilePath( dir.toString() + subdir.toString() );
        lastWasRealDir=false;
      }
    }
    else if( subdir.toString() == "/")
    {
      dir = root;
    }
    else if( subdir.toString() != "./" )
    {
      dir = FilePath( dir.toString() + subdir.toString() );
      lastWasRealDir=true;
    }

    lastpos = pos + 1;
  }

  return dir;
}
开发者ID:nickers,项目名称:opencaesar3,代码行数:46,代码来源:oc3_filepath.cpp

示例3: getApplicationDir

FileDir FileDir::getApplicationDir()
{
#ifdef WIN32
  unsigned int pathSize=512;
  ByteArray tmpPath;
  tmpPath.resize( pathSize );
  GetModuleFileName( 0, tmpPath.data(), pathSize);
  FilePath tmp = tmpPath.data();

  tmp = tmp.getUpDir();
  //delete tmpPath;

  return tmp;
#elif defined(__linux__)
  char exe_path[PATH_MAX] = {0};
  char * dir_path;
  sprintf(exe_path, "/proc/%d/exe", getpid());
  readlink(exe_path, exe_path, sizeof(exe_path));
  dir_path = dirname(exe_path);
  return FilePath(dir_path);
#endif // __GNUC__

  return FilePath( "" );
}
开发者ID:nickers,项目名称:opencaesar3,代码行数:24,代码来源:oc3_filepath.cpp


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