Leosac  0.8.0
Open Source Access Control
unixshellscript.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
26 #ifndef UNIXSHELLSCRIPT_HPP
27 #define UNIXSHELLSCRIPT_HPP
28 
29 #include <sstream>
30 #include <string>
31 
32 namespace Leosac
33 {
34 namespace Tools
35 {
37 {
38  static const std::size_t BufferSize = 1024;
39 
40  public:
41  explicit UnixShellScript(const std::string &script);
42 
43  ~UnixShellScript() = default;
44 
45  UnixShellScript(const UnixShellScript &other) = delete;
46 
47  UnixShellScript &operator=(const UnixShellScript &other) = delete;
48 
49  public:
50  int run(const std::string &args = std::string());
51 
52  const std::string &getOutput() const;
53 
54  template <typename T>
55  static std::string toCmdLine(T value)
56  {
57  std::ostringstream oss;
58 
59  oss << value;
60  return (oss.str());
61  }
62 
63  template <typename T, typename... Targs>
64  static std::string toCmdLine(T value, Targs... args)
65  {
66  if (sizeof...(args) > 0)
67  return (toCmdLine(value) + ' ' + toCmdLine(args...));
68  }
69 
70  private:
71  const std::string _script;
72  std::string _output;
73 };
74 }
75 }
76 
77 #endif // UNIXSHELLSCRIPT_HPP
Leosac::Tools::UnixShellScript::~UnixShellScript
~UnixShellScript()=default
Leosac::Tools::UnixShellScript::_script
const std::string _script
Definition: unixshellscript.hpp:71
Leosac::Tools::UnixShellScript::run
int run(const std::string &args=std::string())
Definition: unixshellscript.cpp:46
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Tools::UnixShellScript::operator=
UnixShellScript & operator=(const UnixShellScript &other)=delete
Leosac::Tools::UnixShellScript::UnixShellScript
UnixShellScript(const std::string &script)
Definition: unixshellscript.cpp:41
Leosac::Tools::UnixShellScript::toCmdLine
static std::string toCmdLine(T value)
Definition: unixshellscript.hpp:55
Leosac::Tools::UnixShellScript::getOutput
const std::string & getOutput() const
Definition: unixshellscript.cpp:66
Leosac::Tools::UnixShellScript::BufferSize
static const std::size_t BufferSize
Definition: unixshellscript.hpp:38
Leosac::Tools::UnixShellScript::_output
std::string _output
Definition: unixshellscript.hpp:72
Leosac::Tools::UnixShellScript
Definition: unixshellscript.hpp:36
Leosac::Tools::UnixShellScript::toCmdLine
static std::string toCmdLine(T value, Targs... args)
Definition: unixshellscript.hpp:64