ReFRACtor
dir_change.h
Go to the documentation of this file.
1 #ifndef DIR_CHANGE_H
2 #define DIR_CHANGE_H
3 #include <string>
4 #include <unistd.h>
5 #include <fcntl.h>
6 #include "fp_exception.h"
7 
8 namespace FullPhysics {
9 
10 //-----------------------------------------------------------------------
13 //-----------------------------------------------------------------------
14 
15 class DirChange {
16 public:
17  DirChange(const std::string& newdir)
18  {
19  dirhandle = open(".", O_RDONLY);
20  int status = chdir(newdir.c_str());
21  if(status != 0) {
22  std::stringstream err_msg;
23  err_msg << "Could not change to directory: " << newdir;
24  throw Exception(err_msg.str());
25  }
26  }
27  ~DirChange() noexcept(false)
28  {
29  int status = fchdir(dirhandle);
30  close(dirhandle);
31  if(status != 0)
32  throw Exception("Call to fchdir failed");
33  }
34 private:
35  int dirhandle;
36 };
37 }
38 #endif
DirChange(const std::string &newdir)
Definition: dir_change.h:17
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
Utility class.
Definition: dir_change.h:15
~DirChange() noexcept(false)
Definition: dir_change.h:27

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10