#ifndef __JROOT__JCANVAS__ #define __JROOT__JCANVAS__ #include #include #include #include "JLang/JException.hh" /** * \author mdejong */ namespace JROOT {} namespace JPP { using namespace JROOT; } namespace JROOT { using JLANG::JParseError; /** * Data structure for size of TCanvas. */ class JCanvas { public: /** * Default constructor. */ JCanvas() : x(500), y(500) {} /** * Constructor. * * \param __x width * \param __y height */ JCanvas(const int __x, const int __y) : x(__x), y(__y) {} /** * Read canvas from input stream. * * \param in input stream * \param cv canvas * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JCanvas& cv) { using namespace std; string buffer; getline(in,buffer); size_t pos = buffer.find(SEPARATOR); if (pos != string::npos) { if (!(istringstream(buffer.substr(0,pos)) >> cv.x)) { in.setstate(ios::badbit); } if (!(istringstream(buffer.substr(pos+1)) >> cv.y)) { in.setstate(ios::badbit); } } else { THROW(JParseError, "JCanvas error parsing " << buffer); } return in; } /** * Write canvas to output stream. * * \param out output stream * \param cv canvas * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JCanvas& cv) { out << cv.x << SEPARATOR << cv.y; return out; } static const char SEPARATOR = 'x'; int x; //!< number of pixels in X int y; //!< number of pixels in Y }; } #endif