Shellp
|
00001 /* 00002 00003 This file is a part of Shellp, a 'shell helper' library. 00004 00005 Copyright (C) 2011-2012 Jori Liesenborgs 00006 00007 Contact: jori.liesenborgs@gmail.com 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 00022 USA 00023 00024 */ 00025 00026 #ifndef SHELLP_IOSYSTEM_H 00027 00028 #define SHELLP_IOSYSTEM_H 00029 00030 #include "shellconfig.h" 00031 #include <errut/errorbase.h> 00032 #include <string> 00033 #include <vector> 00034 #include <list> 00035 00036 namespace shellp 00037 { 00038 00039 class SHELLP_IMPORTEXPORT IOSystem : public errut::ErrorBase 00040 { 00041 protected: 00042 IOSystem() { m_echo = true; } 00043 public: 00044 virtual ~IOSystem() { } 00045 00046 bool echo() const { return m_echo; } 00047 void setEcho(bool f) { m_echo = f; } 00048 00049 bool readInputLine(const std::string &prefix, std::string &line); 00050 virtual void writeOutputLine(const std::string &line, bool newline = true) { } 00051 virtual void setPercentageFeedback(double pct); 00052 00053 virtual bool supports2DPlot() const { return false; } 00054 virtual bool supports3DPlot() const { return false; } 00055 virtual bool plot2D(int id, const std::string &title, 00056 const std::string &xLabel, const std::string &yLabel, 00057 const std::vector<double> &xPoints, const std::vector<double> &yPoints, 00058 bool forceShow = true); 00059 virtual bool plot3D(int id, const std::string &title, 00060 const std::string &xLabel, const std::string &yLabel, 00061 const std::string &zLabel, 00062 double xOff, double yOff, double xDdist, double yDist, 00063 double xMultiplier, double yMultiplier, double zMultiplier, 00064 const std::vector<double> &data, int numX, int numY, bool forceShow = true); 00065 00066 virtual void writeStatusLine(const std::string &str) { writeOutputLine(str, true); } 00067 00068 void print(const char *format, ...); 00069 void printNoNewLine(const char *format, ...); 00070 00071 static void splitLine(const std::string &line, std::vector<std::string> &args); 00072 00073 void flushExtraInputLines() { m_extraInputLines.clear(); } 00074 void insertExtraInputLine(const std::string &line) { m_extraInputLines.push_front(line); } 00075 void appendExtraInputLine(const std::string &line) { m_extraInputLines.push_back(line); } 00076 private: 00077 virtual bool readInputLineInternal(std::string &line); 00078 virtual void writeInputPrefix(const std::string &prefix) { } 00079 00080 std::list<std::string> m_extraInputLines; 00081 bool m_echo; 00082 }; 00083 00084 } // end namespace 00085 00086 #endif // SHELLP_IOSYSTEM_H 00087