Jpp
JComment.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JCOMMENT__
2 #define __JEEP__JCOMMENT__
3 
4 #include <istream>
5 #include <ostream>
6 #include <sstream>
7 #include <string>
8 #include <vector>
9 
10 //#include "JIO/JSerialisable.hh"
11 //#include "JIO/JSTDIO.hh"
12 #include "Jeep/JPrint.hh"
13 
14 
15 /**
16  * \author mdejong
17  */
18 
19 namespace JEEP {}
20 namespace JPP { using namespace JEEP; }
21 
22 namespace JEEP {
23 
24  //using JIO::JReader;
25  //using JIO::JWriter;
26 
27 
28  /**
29  * Auxiliary class for comment.
30  *
31  * A comment starts with a <pre>JComment::START_COMMENT</pre> and ends with a <pre>JComment::CLOSE_COMMENT</pre>.
32  * The comments are appended.
33  */
34  struct JComment :
35  public std::vector<std::string>
36  {
37 
38  static const char START_COMMENT = '#'; //!< start of comment
39  static const char CLOSE_COMMENT = '\n'; //!< close of comment
40 
41 
42  /**
43  * Default constructor.
44  */
46  {}
47 
48 
49  /**
50  * Add comment.
51  *
52  * \param comment comment
53  * \return this comment
54  */
55  JComment& add(const std::string& comment)
56  {
57  this->push_back(comment);
58 
59  return *this;
60  }
61 
62 
63  /**
64  * Add comment.
65  *
66  * \param comment comment
67  * \return this comment
68  */
69  JComment& add(const JComment& comment)
70  {
71  for (const_iterator i = comment.begin(); i != comment.end(); ++i) {
72  this->push_back(*i);
73  }
74 
75  return *this;
76  }
77 
78 
79  /**
80  * Read comment from input.
81  *
82  * \param in input stream
83  * \param comment comment
84  * \return input stream
85  */
86  friend inline std::istream& operator>>(std::istream& in, JComment& comment)
87  {
88  using namespace std;
89 
90  for (string buffer; in.peek() == (int) START_COMMENT; ) {
91 
92  in.get();
93 
94  if (in.peek() == (int) ' ') {
95  in.get();
96  }
97 
98  getline(in, buffer, CLOSE_COMMENT);
99 
100  comment.push_back(buffer);
101  }
102 
103  return in;
104  }
105 
106 
107  /**
108  * Write comment to output.
109  *
110  * \param out output stream
111  * \param comment comment
112  * \return output stream
113  */
114  friend inline std::ostream& operator<<(std::ostream& out, const JComment& comment)
115  {
116  using namespace std;
117 
118  for (JComment::const_iterator i = comment.begin(); i != comment.end(); ++i) {
119  out << START_COMMENT << ' ' << *i << CLOSE_COMMENT;
120  }
121 
122  return out << flush;
123  }
124 
125 
126  /**
127  * Read comment from input.
128  *
129  * \param in reader
130  * \param comment comment
131  * \return reader
132  */
133  /*
134  friend inline JReader& operator>>(JReader& in, JComment& comment)
135  {
136  return in;
137  }
138  */
139 
140  /**
141  * Write comment to output.
142  *
143  * \param out writer
144  * \param comment comment
145  * \return writer
146  */
147  /*
148  friend inline JWriter& operator<<(JWriter& out, const JComment& comment)
149  {
150  return out;
151  }
152  */
153  };
154 }
155 
156 #endif
JEEP::JComment::START_COMMENT
static const char START_COMMENT
start of comment
Definition: JComment.hh:38
JEEP::JComment::JComment
JComment()
Default constructor.
Definition: JComment.hh:45
JPrint.hh
JEEP
General puprpose classes and methods.
Definition: JArgs.hh:15
std::vector
Definition: JSTDTypes.hh:12
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JEEP::JComment::operator>>
friend std::istream & operator>>(std::istream &in, JComment &comment)
Read comment from input.
Definition: JComment.hh:86
JEEP::JComment
Auxiliary class for comment.
Definition: JComment.hh:34
JEEP::JComment::add
JComment & add(const JComment &comment)
Add comment.
Definition: JComment.hh:69
JEEP::JComment::operator<<
friend std::ostream & operator<<(std::ostream &out, const JComment &comment)
Write comment to output.
Definition: JComment.hh:114
JEEP::JComment::CLOSE_COMMENT
static const char CLOSE_COMMENT
close of comment
Definition: JComment.hh:39
std
Definition: jaanetDictionary.h:36
JEEP::JComment::add
JComment & add(const std::string &comment)
Add comment.
Definition: JComment.hh:55
JLANG::getline
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:468