🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
WorkingDirectory.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstUtil/StringView.hpp"
25#include "AstUtil/PosixExt.hpp"
26#include "AstUtil/Logger.hpp"
27
28AST_NAMESPACE_BEGIN
29
39{
40public:
42 : oldpath_(), curpath_()
43 {
44 oldpath_ = posix::getcwd();
46 int rc = posix::chdir(std::string(path).c_str());
47 if(rc != 0){
48 aError("failed to change working directory to %.*s", path.size(), path.data());
49 }else{
50 curpath_ = path;
51 }
52 }
54 {
55 int rc = posix::chdir(oldpath_.c_str());
56 if(rc != 0){
57 aError("failed to change working directory to %s", oldpath_.c_str());
58 }
59 }
61 operator bool() const { return isChanged(); }
62
64 bool isChanged() const { return !curpath_.empty(); }
65
67 StringView getCurrentPath() const { return curpath_; }
68protected:
69 A_DISABLE_COPY(WorkingDirectory);
70 std::string oldpath_;
71 StringView curpath_;
72};
73
74
77AST_NAMESPACE_END
工作目录切换器
定义 WorkingDirectory.hpp:39
WorkingDirectory(StringView path)
定义 WorkingDirectory.hpp:41
bool isChanged() const
检查是否成功切换工作目录
定义 WorkingDirectory.hpp:64
StringView getCurrentPath() const
获取切换后的工作目录
定义 WorkingDirectory.hpp:67