Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JCanvas.hh
Go to the documentation of this file.
1#ifndef __JROOT__JCANVAS__
2#define __JROOT__JCANVAS__
3
4#include <istream>
5#include <ostream>
6#include <sstream>
7
8#include "JLang/JException.hh"
9
10
11/**
12 * \author mdejong
13 */
14
15namespace JROOT {}
16namespace JPP { using namespace JROOT; }
17
18namespace JROOT {
19
21
22
23 /**
24 * Data structure for size of TCanvas.
25 */
26 class JCanvas {
27 public:
28 /**
29 * Default constructor.
30 */
32 x(500),
33 y(500)
34 {}
35
36
37 /**
38 * Constructor.
39 *
40 * \param __x width
41 * \param __y height
42 */
43 JCanvas(const int __x,
44 const int __y) :
45 x(__x),
46 y(__y)
47 {}
48
49
50 /**
51 * Read canvas from input stream.
52 *
53 * \param in input stream
54 * \param cv canvas
55 * \return input stream
56 */
57 friend inline std::istream& operator>>(std::istream& in, JCanvas& cv)
58 {
59 using namespace std;
60
61 string buffer;
62
63 getline(in,buffer);
64
65 size_t pos = buffer.find(SEPARATOR);
66
67 if (pos != string::npos) {
68
69 if (!(istringstream(buffer.substr(0,pos)) >> cv.x)) { in.setstate(ios::badbit); }
70 if (!(istringstream(buffer.substr(pos+1)) >> cv.y)) { in.setstate(ios::badbit); }
71
72 } else {
73
74 THROW(JParseError, "JCanvas error parsing " << buffer);
75 }
76
77 return in;
78 }
79
80
81 /**
82 * Write canvas to output stream.
83 *
84 * \param out output stream
85 * \param cv canvas
86 * \return output stream
87 */
88 friend inline std::ostream& operator<<(std::ostream& out, const JCanvas& cv)
89 {
90 out << cv.x << SEPARATOR << cv.y;
91
92 return out;
93 }
94
95
96 static const char SEPARATOR = 'x';
97
98 int x; //!< number of pixels in X
99 int y; //!< number of pixels in Y
100 };
101}
102
103#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Exception for parsing value.
Data structure for size of TCanvas.
Definition JCanvas.hh:26
friend std::ostream & operator<<(std::ostream &out, const JCanvas &cv)
Write canvas to output stream.
Definition JCanvas.hh:88
JCanvas(const int __x, const int __y)
Constructor.
Definition JCanvas.hh:43
int y
number of pixels in Y
Definition JCanvas.hh:99
friend std::istream & operator>>(std::istream &in, JCanvas &cv)
Read canvas from input stream.
Definition JCanvas.hh:57
static const char SEPARATOR
Definition JCanvas.hh:96
JCanvas()
Default constructor.
Definition JCanvas.hh:31
int x
number of pixels in X
Definition JCanvas.hh:98
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.