oct-env.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #if !defined (octave_env_h)
00024 #define octave_env_h 1
00025 
00026 #include <string>
00027 
00028 class
00029 OCTAVE_API
00030 octave_env
00031 {
00032 protected:
00033 
00034   octave_env (void);
00035 
00036 public:
00037 
00038   static std::string polite_directory_format (const std::string& name);
00039 
00040   static bool absolute_pathname (const std::string& s);
00041 
00042   static bool rooted_relative_pathname (const std::string& s);
00043 
00044   static std::string base_pathname (const std::string& s);
00045 
00046   static std::string
00047   make_absolute (const std::string& s,
00048                  const std::string& dot_path = get_current_directory ());
00049 
00050   static std::string get_current_directory (void);
00051 
00052   static std::string get_home_directory (void);
00053 
00054   static std::string get_program_name (void);
00055 
00056   static std::string get_program_invocation_name (void);
00057 
00058   static std::string get_user_name (void);
00059 
00060   static std::string get_host_name (void);
00061 
00062   static std::string getenv (const std::string& name);
00063 
00064   static void putenv (const std::string& name, const std::string& value);
00065 
00066   static bool have_x11_display (void);
00067 
00068   static bool chdir (const std::string& newdir);
00069 
00070   static void set_program_name (const std::string& s);
00071 
00072 private:
00073 
00074   static bool instance_ok (void);
00075 
00076   std::string do_polite_directory_format (const std::string& name) const;
00077 
00078   bool do_absolute_pathname (const std::string& s) const;
00079 
00080   bool do_rooted_relative_pathname (const std::string& s) const;
00081 
00082   std::string do_base_pathname (const std::string& s) const;
00083 
00084   std::string do_make_absolute (const std::string& s,
00085                                 const std::string& dot_path) const;
00086 
00087   std::string do_getcwd (void) const;
00088 
00089   std::string do_get_home_directory (void) const;
00090 
00091   std::string do_get_user_name (void) const;
00092 
00093   std::string do_get_host_name (void) const;
00094 
00095   std::string do_getenv (const std::string& name) const;
00096 
00097   void do_putenv (const std::string& name, const std::string& value) const;
00098 
00099   bool do_chdir (const std::string& newdir);
00100 
00101   void do_set_program_name (const std::string& s) const;
00102 
00103   void pathname_backup (std::string& path, int n) const;
00104 
00105   void error (int) const;
00106 
00107   void error (const std::string&) const;
00108 
00109   // No copying!
00110 
00111   octave_env (const octave_env&);
00112 
00113   octave_env& operator = (const octave_env&);
00114 
00115   // The real thing.
00116   static octave_env *instance;
00117 
00118 
00119   static void cleanup_instance (void) { delete instance; instance = 0; }
00120 
00121   // TRUE means follow symbolic links that point to directories just
00122   // as if they are real directories.
00123   bool follow_symbolic_links;
00124 
00125   // TRUE means that pwd always give verbatim directory, regardless
00126   // of symbolic link following.
00127   bool verbatim_pwd;
00128 
00129   // Where are we?
00130   mutable std::string current_directory;
00131 
00132   // Etc.
00133   mutable std::string prog_name;
00134 
00135   mutable std::string prog_invocation_name;
00136 
00137   mutable std::string user_name;
00138 
00139   mutable std::string host_name;
00140 };
00141 
00142 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines