add pipestream ctor overload for vectors of string
[libi2ncommon] / src / pipestream.hxx
index 83244ed..d13f312 100644 (file)
@@ -31,6 +31,9 @@ on this file might be covered by the GNU General Public License.
 
 #include <string>
 #include <streambuf>
+#include <istream>
+#include <ostream>
+#include <vector>
 
 struct ExecResult
 {
@@ -52,8 +55,22 @@ struct ExecResult
 typedef struct ExecResult ExecResult;
 
 std::string capture_exec(const std::string& command, ExecResult &rescode);
+std::string capture_exec(const char *const *command, ExecResult &rescode);
+std::string capture_exec(const std::vector<std::string>& command, ExecResult &rescode);
 
-std::string capture_exec(const std::string& command)
+inline std::string capture_exec (const std::string &command)
+{
+    ExecResult r;
+    return capture_exec(command,r);
+}
+
+inline std::string capture_exec(const char *const *command)
+{
+    ExecResult r;
+    return capture_exec(command,r);
+}
+
+inline std::string capture_exec(const std::vector<std::string>& command)
 {
     ExecResult r;
     return capture_exec(command,r);
@@ -72,6 +89,7 @@ class inpipebuf : public std::streambuf
 {
 protected:
     char buffer;
+
     FILE *pipe;
 
     // "callback" variables for destructor to store exit status
@@ -80,6 +98,8 @@ protected:
 
 public:
     inpipebuf(const std::string& command);
+    inpipebuf(const char *const *command);
+    inpipebuf(const std::vector<std::string> &command);
 
     ~inpipebuf();
 
@@ -87,6 +107,9 @@ public:
 
 protected:
     virtual int_type underflow();
+
+private:
+    FILE *init_without_shell (const char *const *argv) const;
 };
 
 /** @brief stream around inpipebuf -- see comment there */
@@ -99,6 +122,13 @@ public:
     inpipestream(const std::string& command)
             : std::istream(&buf), buf(command)
     {}
+    inpipestream(const char *const command[])
+            : std::istream(&buf), buf(command)
+    {}
+
+    inpipestream(const std::vector<std::string> &command)
+            : std::istream(&buf), buf(command)
+    {}
 
     void store_exit_status(bool *_status_set, int *_exit_status)
     { buf.store_exit_status(_status_set, _exit_status); }