Jpp test-rotations-old
the software that should make you happy
Loading...
Searching...
No Matches
JLANG::JCppFacet Class Reference

Facet class to specify parsing of a C[++] variable name. More...

#include <JCppFacet.hh>

Inheritance diagram for JLANG::JCppFacet:
JLANG::JStringFacet

Public Types

typedef std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
 
typedef std::ostreambuf_iterator< char, std::char_traits< char > > ostreambuf_iterator
 

Public Member Functions

 JCppFacet ()
 Constructor.
 
virtual JCppFacetclone () const override
 Clone this facet.
 
istreambuf_iterator get (const istreambuf_iterator __begin, const istreambuf_iterator __end, const std::ios_base &format, std::ios_base::iostate &result, std::string &buffer) const
 Get string.
 
ostreambuf_iterator put (ostreambuf_iterator out, const std::ios_base &format, const char c, const std::string &buffer) const
 Put string.
 
std::istream & ignore (std::istream &in) const
 Ignore characters until next end of line.
 
std::istream & getline (std::istream &in, std::string &buffer) const
 Read characters until next end of line.
 

Static Public Member Functions

static bool is_eol (const char c)
 
static bool is_begin_single_line_comment (const char c1, const char c2)
 
static bool is_begin_multi_line_comment (const char c1, const char c2)
 
static bool is_end_single_line_comment (const char c1)
 
static bool is_end_multi_line_comment (const char c1, const char c2)
 
static int getIndex ()
 Get index for stream associated facet data.
 

Static Public Attributes

static std::locale::id id
 

Protected Member Functions

virtual istreambuf_iterator do_get (const istreambuf_iterator __begin, const istreambuf_iterator __end, const std::ios_base &format, std::ios_base::iostate &result, std::string &buffer) const override
 Get string.
 
virtual ostreambuf_iterator do_put (ostreambuf_iterator out, const std::ios_base &format, const char c, const std::string &buffer) const override
 Put string.
 
virtual istreambuf_iterator do_ignore (const istreambuf_iterator __begin, const istreambuf_iterator __end) const override
 Ignore white space and end of line characters.
 
virtual istreambuf_iterator do_ignore_single_line_comment (const istreambuf_iterator __begin, const istreambuf_iterator __end) const
 Ignore characters until end of line.
 
virtual istreambuf_iterator do_ignore_multi_line_comment (const istreambuf_iterator __begin, const istreambuf_iterator __end) const
 Ignore characters until next end of comment.
 
virtual istreambuf_iterator do_getline (const istreambuf_iterator __begin, const istreambuf_iterator __end, std::ios_base::iostate &result, std::string &buffer) const
 Read string.
 

Private Member Functions

 JCppFacet (const JCppFacet &)
 
void operator= (const JCppFacet &)
 

Detailed Description

Facet class to specify parsing of a C[++] variable name.

Definition at line 27 of file JCppFacet.hh.

Member Typedef Documentation

◆ istreambuf_iterator

std::istreambuf_iterator<char, std::char_traits<char> > JLANG::JStringFacet::istreambuf_iterator
inherited

Definition at line 34 of file JStringFacet.hh.

◆ ostreambuf_iterator

std::ostreambuf_iterator<char, std::char_traits<char> > JLANG::JStringFacet::ostreambuf_iterator
inherited

Definition at line 35 of file JStringFacet.hh.

Constructor & Destructor Documentation

◆ JCppFacet() [1/2]

JLANG::JCppFacet::JCppFacet ( )
inline

Constructor.

Definition at line 34 of file JCppFacet.hh.

35 {}

◆ JCppFacet() [2/2]

JLANG::JCppFacet::JCppFacet ( const JCppFacet & )
private

Member Function Documentation

◆ clone()

virtual JCppFacet * JLANG::JCppFacet::clone ( ) const
inlineoverridevirtual

Clone this facet.

Returns
pointer to newly created facet

Reimplemented from JLANG::JStringFacet.

Definition at line 43 of file JCppFacet.hh.

44 {
45 return new JCppFacet();
46 }
JCppFacet()
Constructor.
Definition JCppFacet.hh:34

◆ is_eol()

static bool JLANG::JCppFacet::is_eol ( const char c)
inlinestatic

Definition at line 49 of file JCppFacet.hh.

49{ return c == ';'; }

◆ is_begin_single_line_comment()

static bool JLANG::JCppFacet::is_begin_single_line_comment ( const char c1,
const char c2 )
inlinestatic

Definition at line 51 of file JCppFacet.hh.

51{ return c1 == '/' && c2 == '/'; }
TCanvas * c1
Global variables to handle mouse events.

◆ is_begin_multi_line_comment()

static bool JLANG::JCppFacet::is_begin_multi_line_comment ( const char c1,
const char c2 )
inlinestatic

Definition at line 52 of file JCppFacet.hh.

52{ return c1 == '/' && c2 == '*'; }

◆ is_end_single_line_comment()

static bool JLANG::JCppFacet::is_end_single_line_comment ( const char c1)
inlinestatic

Definition at line 54 of file JCppFacet.hh.

54{ return c1 == '\n'; }

◆ is_end_multi_line_comment()

static bool JLANG::JCppFacet::is_end_multi_line_comment ( const char c1,
const char c2 )
inlinestatic

Definition at line 55 of file JCppFacet.hh.

55{ return c1 == '*' && c2 == '/'; }

◆ get()

istreambuf_iterator JLANG::JCppFacet::get ( const istreambuf_iterator __begin,
const istreambuf_iterator __end,
const std::ios_base & format,
std::ios_base::iostate & result,
std::string & buffer ) const
inline

Get string.

Parameters
__beginbegin position of input stream
__endend position of input stream
formatformat
resultstatus after input operation
bufferoutput string
Returns
position of input stream

Definition at line 68 of file JCppFacet.hh.

73 {
74 return do_get(__begin, __end, format, result, buffer);
75 }
virtual istreambuf_iterator do_get(const istreambuf_iterator __begin, const istreambuf_iterator __end, const std::ios_base &format, std::ios_base::iostate &result, std::string &buffer) const override
Get string.
Definition JCppFacet.hh:107

◆ put()

ostreambuf_iterator JLANG::JCppFacet::put ( ostreambuf_iterator out,
const std::ios_base & format,
const char c,
const std::string & buffer ) const
inline

Put string.

Parameters
outbegin position of output stream
formatformat
cfill character
bufferinput string
Returns
position of output stream buffer

Definition at line 87 of file JCppFacet.hh.

91 {
92 return do_put(out, format, c, buffer);
93 }
virtual ostreambuf_iterator do_put(ostreambuf_iterator out, const std::ios_base &format, const char c, const std::string &buffer) const override
Put string.
Definition JCppFacet.hh:183

◆ do_get()

virtual istreambuf_iterator JLANG::JCppFacet::do_get ( const istreambuf_iterator __begin,
const istreambuf_iterator __end,
const std::ios_base & format,
std::ios_base::iostate & result,
std::string & buffer ) const
inlineoverrideprotectedvirtual

Get string.

Parameters
__beginbegin position of input stream
__endend position of input stream
formatformat
resultstatus after input operation
bufferoutput string
Returns
position of input stream

Reimplemented from JLANG::JStringFacet.

Definition at line 107 of file JCppFacet.hh.

112 {
113 using namespace std;
114
115 result = (ios_base::iostate) 0; // reset I/O status
116
117 streamsize n = format.width(); // number of characters to read
118
119 if (n == 0) {
120 n = numeric_limits<streamsize>::max();
121 }
122
123 istreambuf_iterator i = __begin;
124
125 if (i == __end || (i = do_ignore(i, __end)) == __end) {
126
127 result |= ios_base::failbit;
128 result |= ios_base::eofbit;
129
130 } else {
131
132 char c = *i;
133
134 for (++i; i != __end; c = *i, ++i) {
135
136 // skip comment line(s)
137
139 i = do_ignore_single_line_comment(i, __end);
140 else if (is_begin_multi_line_comment (c,*i))
141 i = do_ignore_multi_line_comment (i, __end);
142 else if (c == '_' || isalpha(c)) // first character must be letter or underscore
143 break;
144
145 i = do_ignore(i, __end);
146 }
147
148 if (i == __end) {
149
150 result |= ios_base::failbit;
151 result |= ios_base::eofbit;
152
153 } else {
154
155 buffer.clear();
156 buffer.push_back(c);
157
158 for (--n; i != __end && n != 0 && (*i == '_' ||
159 isalnum(*i)); // following characters may also be digits
160 ++i, --n) {
161 buffer.push_back(*i);
162 }
163
164 if (i == __end) {
165 result |= ios_base::eofbit;
166 }
167 }
168 }
169
170 return i;
171 }
virtual istreambuf_iterator do_ignore(const istreambuf_iterator __begin, const istreambuf_iterator __end) const override
Ignore white space and end of line characters.
Definition JCppFacet.hh:217
static bool is_begin_multi_line_comment(const char c1, const char c2)
Definition JCppFacet.hh:52
virtual istreambuf_iterator do_ignore_single_line_comment(const istreambuf_iterator __begin, const istreambuf_iterator __end) const
Ignore characters until end of line.
Definition JCppFacet.hh:237
static bool is_begin_single_line_comment(const char c1, const char c2)
Definition JCppFacet.hh:51
virtual istreambuf_iterator do_ignore_multi_line_comment(const istreambuf_iterator __begin, const istreambuf_iterator __end) const
Ignore characters until next end of comment.
Definition JCppFacet.hh:259
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
const int n
Definition JPolint.hh:791

◆ do_put()

virtual ostreambuf_iterator JLANG::JCppFacet::do_put ( ostreambuf_iterator out,
const std::ios_base & format,
const char c,
const std::string & buffer ) const
inlineoverrideprotectedvirtual

Put string.

Parameters
outbegin position of output stream
formatformat
cfill character
bufferinput string
Returns
current position of output stream

Reimplemented from JLANG::JStringFacet.

Definition at line 183 of file JCppFacet.hh.

187 {
188 using namespace std;
189
190 if (format.flags() & ios_base::right) {
191 for (streamsize i = buffer.size(); i < format.width(); ++i, ++out) {
192 *out = c;
193 }
194 }
195
196 for (string::const_iterator i = buffer.begin(); i != buffer.end(); ++i, ++out) {
197 *out = *i;
198 }
199
200 if (format.flags() & ios_base::left) {
201 for (streamsize i = buffer.size(); i < format.width(); ++i, ++out) {
202 *out = c;
203 }
204 }
205
206 return out;
207 }

◆ do_ignore()

virtual istreambuf_iterator JLANG::JCppFacet::do_ignore ( const istreambuf_iterator __begin,
const istreambuf_iterator __end ) const
inlineoverrideprotectedvirtual

Ignore white space and end of line characters.

Parameters
__beginbegin position of input stream
__endend position of input stream
Returns
position of input stream

Reimplemented from JLANG::JStringFacet.

Definition at line 217 of file JCppFacet.hh.

219 {
220 istreambuf_iterator i = __begin;
221
222 while (i != __end && (isspace(*i) || is_eol(*i))) {
223 ++i;
224 }
225
226 return i;
227 }
static bool is_eol(const char c)
Definition JCppFacet.hh:49

◆ do_ignore_single_line_comment()

virtual istreambuf_iterator JLANG::JCppFacet::do_ignore_single_line_comment ( const istreambuf_iterator __begin,
const istreambuf_iterator __end ) const
inlineprotectedvirtual

Ignore characters until end of line.

Parameters
__beginbegin position of input stream
__endend position of input stream
Returns
position of input stream

Definition at line 237 of file JCppFacet.hh.

239 {
240 istreambuf_iterator i = __begin;
241
242 for ( ; i != __end && !is_end_single_line_comment(*i); ++i) {}
243
244 if (i != __end) {
245 ++i; // skip end of line
246 }
247
248 return i;
249 }
static bool is_end_single_line_comment(const char c1)
Definition JCppFacet.hh:54

◆ do_ignore_multi_line_comment()

virtual istreambuf_iterator JLANG::JCppFacet::do_ignore_multi_line_comment ( const istreambuf_iterator __begin,
const istreambuf_iterator __end ) const
inlineprotectedvirtual

Ignore characters until next end of comment.

Parameters
__beginbegin position of input stream
__endend position of input stream
Returns
position of input stream

Definition at line 259 of file JCppFacet.hh.

261 {
262 istreambuf_iterator i = __begin;
263
264 if (i != __end) {
265
266 char c = *i;
267
268 for (++i; i != __end && !is_end_multi_line_comment(c,*i); c = *i, ++i) {}
269
270 if (i != __end) {
271 ++i; // skip end of line
272 }
273 }
274
275 return i;
276 }
static bool is_end_multi_line_comment(const char c1, const char c2)
Definition JCppFacet.hh:55

◆ operator=()

void JLANG::JCppFacet::operator= ( const JCppFacet & )
private

◆ ignore()

std::istream & JLANG::JStringFacet::ignore ( std::istream & in) const
inlineinherited

Ignore characters until next end of line.

Parameters
ininput stream
Returns
input stream

Definition at line 104 of file JStringFacet.hh.

105 {
107 in.setstate(std::ios_base::eofbit);
108 }
109
110 return in;
111 }
virtual istreambuf_iterator do_ignore(const istreambuf_iterator __begin, const istreambuf_iterator __end) const
Ignore characters until next end of line.

◆ getline()

std::istream & JLANG::JStringFacet::getline ( std::istream & in,
std::string & buffer ) const
inlineinherited

Read characters until next end of line.

Parameters
ininput stream
bufferoutput string
Returns
input stream

Definition at line 121 of file JStringFacet.hh.

123 {
124 using namespace std;
125
126 ios_base::iostate state = in.rdstate();
127
128 if (do_getline(in, istreambuf_iterator(), state, buffer) == istreambuf_iterator()) {
129 in.setstate(std::ios_base::eofbit);
130 }
131
132 if (state != ios_base::goodbit && state != ios_base::eofbit) {
133 in.setstate(state);
134 }
135
136 return in;
137 }
virtual istreambuf_iterator do_getline(const istreambuf_iterator __begin, const istreambuf_iterator __end, std::ios_base::iostate &result, std::string &buffer) const
Read string.

◆ getIndex()

static int JLANG::JStringFacet::getIndex ( )
inlinestaticinherited

Get index for stream associated facet data.

Returns
index

Definition at line 145 of file JStringFacet.hh.

146 {
147 static int i = std::ios_base::xalloc();
148
149 return i;
150 }

◆ do_getline()

virtual istreambuf_iterator JLANG::JStringFacet::do_getline ( const istreambuf_iterator __begin,
const istreambuf_iterator __end,
std::ios_base::iostate & result,
std::string & buffer ) const
inlineprotectedvirtualinherited

Read string.

Parameters
__beginbegin position of input stream
__endend position of input stream
resultstatus after input operation
bufferoutput string
Returns
position of input stream

Reimplemented in JLANG::JEquationFacet.

Definition at line 275 of file JStringFacet.hh.

279 {
280 using namespace std;
281
282 istreambuf_iterator i = __begin;
283
284 if (i == __end) {
285
286 result |= ios_base::failbit;
287 result |= ios_base::eofbit;
288
289 } else {
290
291 buffer.clear();
292
293 for ( ; i != __end && *i != '\n'; ++i) {
294 buffer.push_back(*i);
295 }
296
297 if (i != __end) {
298 ++i; // skip end of line
299 }
300 }
301
302 return i;
303 }

Member Data Documentation

◆ id

std::locale::id JLANG::JStringFacet::id
staticinherited
Author
mdejong

Definition at line 31 of file JStringFacet.hh.


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