[an error occurred while processing this directive]
Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

hugin_base/appbase/ExternalProgram.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00031 #ifndef _APPBASE_EXTERNALPROGRAM_H
00032 #define _APPBASE_EXTERNALPROGRAM_H
00033 
00034 #include <string>
00035 
00036 
00037 namespace AppBase {
00038 
00039     
00041 class ArgumentQuotator
00042 {    
00043     public:
00045         ArgumentQuotator() {};
00047         virtual ~ArgumentQuotator() {};
00048     
00049     public:
00051         virtual std::string quoteArgument(const std::string& argument) =0;
00052         
00054         virtual std::string quoteFilename(const std::string& filename) =0;
00055 };
00056 
00058 class StandardArgumentQuotator : public ArgumentQuotator
00059 {
00060     public:
00062         StandardArgumentQuotator() {};
00064         virtual ~StandardArgumentQuotator() {};
00065         
00066     public:
00068         virtual std::string quoteArgument(const std::string& argument);
00069         
00071         virtual std::string quoteFilename(const std::string& filename);
00072 };
00073 
00074     
00078 class ExternalProgram : public virtual ArgumentQuotator
00079 {
00080     public:
00081         typedef std::string String;
00082     
00083     public:
00085         ExternalProgram()
00086          : m_exitCode(-1), m_quotator(m_defaultQuotator)
00087         {}
00088     
00090         ExternalProgram(ArgumentQuotator& quotator)
00091          : m_exitCode(-1), m_quotator(quotator)
00092         {}
00093     
00095         virtual ~ExternalProgram() {};
00096         
00097         
00098         // -- accessors --
00099         
00100     public:
00102         virtual void setCommand(String command)
00103             { m_command = command; };
00104         
00106         virtual String getCommand()
00107             { return m_command; };
00108         
00110         virtual void setArguments(String arguments)
00111             { m_arguments = arguments; };    
00112         
00114         virtual String getArguments()
00115             { return m_arguments; };
00116         
00117         
00118         // -- argument utilities --
00119         
00120     public:
00122         virtual void addArgument(String argument)
00123             { m_arguments.append(" " + argument); };
00124         
00126         virtual void addArgumentSafely(String argument)
00127             { addArgument(quoteArgument(argument)); };
00128         
00130         virtual void addFilenameSafely(String filename)
00131             { addArgument(quoteFilename(filename)); };
00132         
00134         virtual void setCommandSafely(String command)
00135             { setCommand(quoteFilename(command)); };
00136         
00137         
00138     public:
00140         ArgumentQuotator& getQuotator() const
00141             {return m_quotator;}
00142             
00144         virtual String quoteArgument(const String& argument)
00145             {return getQuotator().quoteArgument(argument);}
00146         
00148         virtual String quoteFilename(const String& filename)
00149             {return getQuotator().quoteFilename(filename);}
00150         
00151         
00152         // -- executing --
00153         
00154     public:
00156         virtual int getExitCode()
00157             { return m_exitCode; };
00158         
00160         virtual void setExitCode(int exitCode)
00161             { m_exitCode = exitCode; };
00162         
00163         
00164         // -- variables --        
00165     private:
00166         String m_command;
00167         String m_arguments;
00168         int m_exitCode;
00169         
00170         ArgumentQuotator& m_quotator;
00171         StandardArgumentQuotator m_defaultQuotator;
00172 };
00173 
00174 
00175 
00179 class ExternalProgramExecutor
00180 {
00181         
00182     public:
00184         virtual ~ExternalProgramExecutor() {};
00185         
00186         
00187     public:
00189         enum ExecutionResult {INTERRUPTED = -1, NORMAL = 0, ERROR = 1};
00190         
00192         virtual ExecutionResult executeProgram(ExternalProgram* program) =0;
00193         
00194 };
00195 
00196 
00197 
00198 } //namespace
00199 #endif //_H

Generated on Mon Sep 20 01:01:27 2010 for Hugintrunk by doxygen 1.3.9.1