Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
15 namespace JROOT {}
16 namespace JPP { using namespace JROOT; }
17 
18 namespace JROOT {
19 
20  using JLANG::JParseError;
21 
22 
23  /**
24  * Data structure for size of TCanvas.
25  */
26  class JCanvas {
27  public:
28  /**
29  * Default constructor.
30  */
31  JCanvas() :
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  istringstream(buffer.substr(0,pos)) >> cv.x;
70  istringstream(buffer.substr(pos+1)) >> cv.y;
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
JCanvas(const int __x, const int __y)
Constructor.
Definition: JCanvas.hh:43
int y
number of pixels in Y
Definition: JCanvas.hh:99
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
Definition: JException.hh:670
friend std::istream & operator>>(std::istream &in, JCanvas &cv)
Read canvas from input stream.
Definition: JCanvas.hh:57
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
static const char SEPARATOR
Definition: JCanvas.hh:96
JCanvas()
Default constructor.
Definition: JCanvas.hh:31
Exception for parsing value.
Definition: JException.hh:180
friend std::ostream & operator<<(std::ostream &out, const JCanvas &cv)
Write canvas to output stream.
Definition: JCanvas.hh:88
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:36
int x
number of pixels in X
Definition: JCanvas.hh:98
Data structure for size of TCanvas.
Definition: JCanvas.hh:26