SAGA Adaptor CPI v.1.0
|
00001 // Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) 00002 // 00003 // Use, modification and distribution is subject to the Boost Software 00004 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 00005 // http://www.boost.org/LICENSE_1_0.txt) 00006 00007 #ifndef _SAGA_PROCESS_H_ 00008 #define _SAGA_PROCESS_H_ 1 00009 00010 #include <map> 00011 #include <vector> 00012 #include <iostream> 00013 00014 // other includes from SAGA (this pulls export definitions, which we actually 00015 // want, but can't include directly for some reason 00016 #include <saga/saga/util.hpp> 00017 00018 // boost process 00019 #include <boost/process.hpp> 00020 00021 // suppress warnings about dependent classes not being exported from the dll 00022 #if defined(BOOST_MSVC) 00023 #pragma warning(push) 00024 #pragma warning(disable : 4251 4231 4660) 00025 #endif 00026 00027 namespace saga 00028 { 00029 namespace adaptors 00030 { 00031 namespace utils 00032 { 00033 class SAGA_EXPORT process 00034 { 00035 private: 00036 std::string cmd_; 00037 std::vector <std::string> args_; 00038 std::map <std::string, std::string> env_; 00039 00040 boost::process::child c_; 00041 00042 std::vector <std::string> out_v_; 00043 std::vector <std::string> err_v_; 00044 00045 int exit_; 00046 bool done_; 00047 bool fail_; 00048 std::string msg_; 00049 00050 00051 public: 00052 process (void); 00053 00054 process (std::string cmd); 00055 process (std::vector <std::string> const& args); 00056 process (std::map <std::string, std::string> const& env); 00057 00058 process (std::string cmd, 00059 std::vector <std::string> const& args); 00060 process (std::string cmd, 00061 std::map <std::string, std::string> const& env); 00062 00063 process (std::string cmd, 00064 std::vector <std::string> const& args, 00065 std::map <std::string, std::string> const& env); 00066 00067 void clear (void); 00068 void set_cmd (std::string cmd); 00069 00070 void clear_args (void); 00071 void set_args (std::vector <std::string> const& args); 00072 void add_arg (std::string arg); 00073 void add_args (std::string arg_1, 00074 std::string arg_2); 00075 00076 void clear_env (void); 00077 void set_env (std::map <std::string, std::string> const& env); 00078 void add_env (std::string key, std::string val); 00079 00080 std::vector <std::string> run_sync (bool io = true); 00081 00082 void clear_out (void); 00083 void clear_err (void); 00084 00085 boost::process::pistream & get_out (void); 00086 boost::process::pistream & get_err (void); 00087 00088 std::string get_out_s (void); 00089 std::string get_err_s (void); 00090 00091 std::vector <std::string> get_out_v (void); 00092 std::vector <std::string> get_err_v (void); 00093 00094 int exitcode (void) { return exit_; } 00095 bool done (void) { return done_; } 00096 bool fail (void) { return fail_; } 00097 std::string msg (void) { return msg_; } 00098 }; 00099 00100 } // namespace utils 00101 00102 } // namespace adaptors 00103 00104 } // namespace saga 00105 00106 #if defined(BOOST_MSVC) 00107 #pragma warning(pop) 00108 #endif 00109 00110 #endif // _SAGA_PROCESS_H_ 00111