Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JEEP::JComment Struct Reference

Auxiliary class for comment. More...

#include <JComment.hh>

Inheritance diagram for JEEP::JComment:
std::vector< std::string >

Public Types

enum  { UUID_t = 0 }
 

Public Member Functions

 JComment ()
 Default constructor.
 
JCommentupdate (const JUUID &uuid)
 Update this comment with given UUID.
 
JCommentupdate ()
 Update this comment with random UUID.
 
JCommentadd (const std::string &comment)
 Add comment.
 
JCommentadd (const JComment_t &comment)
 Add comment block.
 
bool hasUUID () const
 Check if this comment has UUID.
 
JUUID getUUID () const
 Get UUID.
 

Static Public Member Functions

static bool is_special (const std::string &buffer)
 Check if given string is special.
 

Static Public Attributes

static constexpr char START_COMMENT = '#'
 start comment
 
static constexpr char CLOSE_COMMENT = '\n'
 close comment
 
static constexpr char START_SPECIAL = '$'
 start special comment
 
static constexpr char CLOSE_SPECIAL = '$'
 close special comment
 
static constexpr char QUOTE = '"'
 quote
 

Friends

std::istream & operator>> (std::istream &in, JComment &comment)
 Read comment from input.
 
std::ostream & operator<< (std::ostream &out, const JComment &comment)
 Write comment to output.
 

Detailed Description

Auxiliary class for comment.

A comment starts with a JComment::START_COMMENT and ends with a JComment::CLOSE_COMMENT.
The text between the quotes JComment::QUOTE is considered as one block which may cross newlines, etc.
The comments are appended.

Definition at line 41 of file JComment.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
UUID_t 

index of UUID

Definition at line 44 of file JComment.hh.

44 {
45 UUID_t = 0 //!< index of UUID
46 };
@ UUID_t
index of UUID
Definition JComment.hh:45

Constructor & Destructor Documentation

◆ JComment()

JEEP::JComment::JComment ( )
inline

Default constructor.

Definition at line 58 of file JComment.hh.

59 {}

Member Function Documentation

◆ update() [1/2]

JComment & JEEP::JComment::update ( const JUUID & uuid)
inline

Update this comment with given UUID.

Parameters
uuidUUID
Returns
this comment

Definition at line 68 of file JComment.hh.

69 {
70 if (!this->hasUUID()) {
71 if ((int) this->size() <= UUID_t)
72 this->resize(UUID_t + 1);
73 else
74 this->insert(this->begin() + UUID_t, value_type());
75 }
76
77 (*this)[UUID_t] = MAKE_STRING(START_SPECIAL << uuid << CLOSE_SPECIAL);
78
79 return *this;
80 }
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
static constexpr char START_SPECIAL
start special comment
Definition JComment.hh:50
bool hasUUID() const
Check if this comment has UUID.
Definition JComment.hh:129
static constexpr char CLOSE_SPECIAL
close special comment
Definition JComment.hh:51

◆ update() [2/2]

JComment & JEEP::JComment::update ( )
inline

Update this comment with random UUID.

Returns
this comment

Definition at line 88 of file JComment.hh.

89 {
90 return this->update(JUUID::rndm());
91 }
JComment & update()
Update this comment with random UUID.
Definition JComment.hh:88
static const JUUID & rndm()
Generate random UUID.
Definition JUUID.hh:78

◆ add() [1/2]

JComment & JEEP::JComment::add ( const std::string & comment)
inline

Add comment.

Parameters
commentcomment
Returns
this comment

Definition at line 100 of file JComment.hh.

101 {
102 this->push_back(comment);
103
104 return this->update();
105 }

◆ add() [2/2]

JComment & JEEP::JComment::add ( const JComment_t & comment)
inline

Add comment block.

Parameters
commentcomment block
Returns
this comment

Definition at line 114 of file JComment.hh.

115 {
116 for (const_iterator i = comment.begin(); i != comment.end(); ++i) {
117 this->push_back(*i);
118 }
119
120 return this->update();
121 }

◆ hasUUID()

bool JEEP::JComment::hasUUID ( ) const
inline

Check if this comment has UUID.

Returns
true if UUID present; else false

Definition at line 129 of file JComment.hh.

130 {
131 return (UUID_t < (int) this->size() && is_special((*this)[UUID_t]));
132 }
static bool is_special(const std::string &buffer)
Check if given string is special.
Definition JComment.hh:223

◆ getUUID()

JUUID JEEP::JComment::getUUID ( ) const
inline

Get UUID.

Returns
UUID

Definition at line 140 of file JComment.hh.

141 {
142 if (this->hasUUID()) {
143
144 const std::string& buffer = (*this)[UUID_t];
145
146 return JUUID::valueOf(buffer.substr(1, buffer.size() - 2));
147
148 } else {
149
150 THROW(JNoValue, "No UUID in comment.");
151 }
152 }
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
static JUUID valueOf(const std::string &buffer)
Extract UUID.
Definition JUUID.hh:124

◆ is_special()

static bool JEEP::JComment::is_special ( const std::string & buffer)
inlinestatic

Check if given string is special.

Parameters
bufferinput string
Returns
true if special; else false

Definition at line 223 of file JComment.hh.

224 {
225 const int N = buffer.size();
226
227 return (N > 2 &&
228 buffer[0] == START_SPECIAL &&
229 buffer[N-1] == CLOSE_SPECIAL);
230 }

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & in,
JComment & comment )
friend

Read comment from input.

Parameters
ininput stream
commentcomment
Returns
input stream

Definition at line 162 of file JComment.hh.

163 {
164 using namespace std;
165
166 while (in.peek() == (int) START_COMMENT) {
167
168 in.get();
169
170 if (in.peek() == (int) ' ') {
171 in.get();
172 }
173
174 int c;
175 string buffer;
176
177 while ((c = in.get()) != EOF && c != (int) CLOSE_COMMENT) {
178
179 buffer.push_back((char) c);
180
181 if (c == (int) QUOTE) {
182
183 while ((c = in.get()) != EOF && c != (int) QUOTE) {
184 buffer.push_back((char) c);
185 }
186
187 buffer.push_back(QUOTE);
188 }
189 }
190
191 comment.push_back(buffer);
192 }
193
194 return in;
195 }
static constexpr char QUOTE
quote
Definition JComment.hh:52
static constexpr char START_COMMENT
start comment
Definition JComment.hh:48
static constexpr char CLOSE_COMMENT
close comment
Definition JComment.hh:49

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const JComment & comment )
friend

Write comment to output.

Parameters
outoutput stream
commentcomment
Returns
output stream

Definition at line 205 of file JComment.hh.

206 {
207 using namespace std;
208
209 for (JComment::const_iterator i = comment.begin(); i != comment.end(); ++i) {
210 out << START_COMMENT << ' ' << *i << CLOSE_COMMENT;
211 }
212
213 return out << flush;
214 }

Member Data Documentation

◆ START_COMMENT

char JEEP::JComment::START_COMMENT = '#'
staticconstexpr

start comment

Definition at line 48 of file JComment.hh.

◆ CLOSE_COMMENT

char JEEP::JComment::CLOSE_COMMENT = '\n'
staticconstexpr

close comment

Definition at line 49 of file JComment.hh.

◆ START_SPECIAL

char JEEP::JComment::START_SPECIAL = '$'
staticconstexpr

start special comment

Definition at line 50 of file JComment.hh.

◆ CLOSE_SPECIAL

char JEEP::JComment::CLOSE_SPECIAL = '$'
staticconstexpr

close special comment

Definition at line 51 of file JComment.hh.

◆ QUOTE

char JEEP::JComment::QUOTE = '"'
staticconstexpr

quote

Definition at line 52 of file JComment.hh.


The documentation for this struct was generated from the following file: