🛰️航天仿真算法库 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 {
43 oldpath_ = posix::getcwd();
45 int rc = posix::chdir(std::string(path).c_str());
46 if(rc != 0){
47 aError("failed to change working directory to %.*s", path.size(), path.data());
48 }else{
49 curpath_ = path;
50 }
51 }
53 {
54 int rc = posix::chdir(oldpath_.c_str());
55 if(rc != 0){
56 aError("failed to change working directory to %s", oldpath_.c_str());
57 }
58 }
60 operator bool() const { return isChanged(); }
61
63 bool isChanged() const { return !curpath_.empty(); }
64
66 StringView getCurrentPath() const { return curpath_; }
67protected:
68 std::string oldpath_;
69 StringView curpath_;
70};
71
72
75AST_NAMESPACE_END
工作目录切换器
定义 WorkingDirectory.hpp:39
WorkingDirectory(StringView path)
定义 WorkingDirectory.hpp:41
bool isChanged() const
检查是否成功切换工作目录
定义 WorkingDirectory.hpp:63
StringView getCurrentPath() const
获取切换后的工作目录
定义 WorkingDirectory.hpp:66