Jpp 21.0.0-rc.1-88-g0130508c4
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
9/**
10 * \author mdejong
11 */
12
13namespace JROOT {}
14namespace JPP { using namespace JROOT; }
15
16namespace JROOT {
17
18 /**
19 * Data structure for size of TCanvas.
20 */
21 class JCanvas {
22 public:
23
24 static const char SEPARATOR = 'x';
25
26 /**
27 * Default constructor.
28 */
30 x(500),
31 y(500)
32 {}
33
34
35 /**
36 * Constructor.
37 *
38 * \param x width
39 * \param y height
40 */
41 JCanvas(const int x,
42 const int y) :
43 x(x),
44 y(y)
45 {}
46
47
48 /**
49 * Read canvas from input stream.
50 *
51 * \param in input stream
52 * \param cv canvas
53 * \return input stream
54 */
55 friend inline std::istream& operator>>(std::istream& in, JCanvas& cv)
56 {
57 using namespace std;
58
59 string buffer;
60
61 getline(in,buffer);
62
63 size_t pos = buffer.find(SEPARATOR);
64
65 if (pos != string::npos) {
66
67 if (!(istringstream(buffer.substr(0,pos)) >> cv.x)) { in.setstate(ios::badbit); }
68 if (!(istringstream(buffer.substr(pos+1)) >> cv.y)) { in.setstate(ios::badbit); }
69
70 } else {
71
72 in.setstate(ios::badbit);
73 }
74
75 return in;
76 }
77
78
79 /**
80 * Write canvas to output stream.
81 *
82 * \param out output stream
83 * \param cv canvas
84 * \return output stream
85 */
86 friend inline std::ostream& operator<<(std::ostream& out, const JCanvas& cv)
87 {
88 out << cv.x << SEPARATOR << cv.y;
89
90 return out;
91 }
92
93
94 int x; //!< number of pixels in X
95 int y; //!< number of pixels in Y
96 };
97}
98
99#endif
Data structure for size of TCanvas.
Definition JCanvas.hh:21
friend std::ostream & operator<<(std::ostream &out, const JCanvas &cv)
Write canvas to output stream.
Definition JCanvas.hh:86
int y
number of pixels in Y
Definition JCanvas.hh:95
friend std::istream & operator>>(std::istream &in, JCanvas &cv)
Read canvas from input stream.
Definition JCanvas.hh:55
static const char SEPARATOR
Definition JCanvas.hh:24
JCanvas()
Default constructor.
Definition JCanvas.hh:29
int x
number of pixels in X
Definition JCanvas.hh:94
JCanvas(const int x, const int y)
Constructor.
Definition JCanvas.hh:41
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.