Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | List of all members
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. More...
 
virtual JCppFacetclone () const
 Clone this facet. More...
 
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. More...
 
ostreambuf_iterator put (ostreambuf_iterator out, const std::ios_base &format, const char c, const std::string &buffer) const
 Put string. More...
 
std::istream & ignore (std::istream &in) const
 Ignore characters until next end of line. More...
 
std::istream & getline (std::istream &in, std::string &buffer) const
 Read characters until next end of line. More...
 

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. More...
 

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
 Get string. More...
 
virtual ostreambuf_iterator do_put (ostreambuf_iterator out, const std::ios_base &format, const char c, const std::string &buffer) const
 Put string. More...
 
virtual istreambuf_iterator do_ignore (const istreambuf_iterator __begin, const istreambuf_iterator __end) const
 Ignore white space and end of line characters. More...
 
virtual istreambuf_iterator do_ignore_single_line_comment (const istreambuf_iterator __begin, const istreambuf_iterator __end) const
 Ignore characters until end of line. More...
 
virtual istreambuf_iterator do_ignore_multi_line_comment (const istreambuf_iterator __begin, const istreambuf_iterator __end) const
 Ignore characters until next end of comment. More...
 
virtual istreambuf_iterator do_getline (const istreambuf_iterator __begin, const istreambuf_iterator __end, std::ios_base::iostate &result, std::string &buffer) const
 Read string. More...
 

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

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

Definition at line 34 of file JStringFacet.hh.

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

Definition at line 35 of file JStringFacet.hh.

Constructor & Destructor Documentation

JLANG::JCppFacet::JCppFacet ( )
inline

Constructor.

Definition at line 34 of file JCppFacet.hh.

35  {}
JLANG::JCppFacet::JCppFacet ( const JCppFacet )
private

Member Function Documentation

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

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
static bool JLANG::JCppFacet::is_eol ( const char  c)
inlinestatic

Definition at line 49 of file JCppFacet.hh.

49 { return c == ';'; }
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.
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 == '*'; }
TCanvas * c1
Global variables to handle mouse events.
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'; }
TCanvas * c1
Global variables to handle mouse events.
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 == '/'; }
TCanvas * c1
Global variables to handle mouse events.
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
Get string.
Definition: JCppFacet.hh:107
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
Put string.
Definition: JCppFacet.hh:187
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
inlineprotectedvirtual

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  istreambuf_iterator i = __begin;
123 
124  if (i == __end || (i = do_ignore(i, __end)) == __end) {
125 
126  result |= ios_base::failbit;
127  result |= ios_base::eofbit;
128 
129  } else {
130 
131  // skip comment line(s)
132 
133  char c = *i;
134 
135  for (++i; i != __end; c = *i, ++i) {
136 
138  i = do_ignore_single_line_comment(i, __end);
139  else if (is_begin_multi_line_comment (c,*i))
140  i = do_ignore_multi_line_comment (i, __end);
141  else
142  break;
143 
144  i = do_ignore(i, __end);
145  }
146 
147  if (i == __end) {
148 
149  result |= ios_base::failbit;
150  result |= ios_base::eofbit;
151 
152  } else {
153 
154  // first character must be a letter or '_'
155 
156  if (c == '_' || isalpha(c)) {
157 
158  buffer.clear();
159  buffer.push_back(c);
160 
161  // following characters may also be digits
162 
163  for (--n; i != __end && n != 0 && (*i == '_' ||
164  isalpha(*i) ||
165  isdigit(*i)); ++i, --n)
166  buffer.push_back(*i);
167  }
168 
169  if (i == __end)
170  result |= ios_base::eofbit;
171  }
172  }
173 
174  return i;
175  }
static bool is_begin_single_line_comment(const char c1, const char c2)
Definition: JCppFacet.hh:51
virtual istreambuf_iterator do_ignore(const istreambuf_iterator __begin, const istreambuf_iterator __end) const
Ignore white space and end of line characters.
Definition: JCppFacet.hh:218
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
Definition: JStringFacet.hh:34
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
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:258
static bool is_begin_multi_line_comment(const char c1, const char c2)
Definition: JCppFacet.hh:52
virtual ostreambuf_iterator JLANG::JCppFacet::do_put ( ostreambuf_iterator  out,
const std::ios_base &  format,
const char  c,
const std::string &  buffer 
) const
inlineprotectedvirtual

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 187 of file JCppFacet.hh.

191  {
192  using namespace std;
193 
194  if (format.flags() & ios_base::right) {
195  for (streamsize i = buffer.size(); i < format.width(); ++i, ++out)
196  *out = c;
197  }
198 
199  for (string::const_iterator i = buffer.begin(); i != buffer.end(); ++i, ++out)
200  *out = *i;
201 
202  if (format.flags() & ios_base::left) {
203  for (streamsize i = buffer.size(); i < format.width(); ++i, ++out)
204  *out = c;
205  }
206 
207  return out;
208  }
virtual istreambuf_iterator JLANG::JCppFacet::do_ignore ( const istreambuf_iterator  __begin,
const istreambuf_iterator  __end 
) const
inlineprotectedvirtual

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 218 of file JCppFacet.hh.

220  {
221  istreambuf_iterator i = __begin;
222 
223  while (i != __end && (isspace(*i) || is_eol(*i)))
224  ++i;
225 
226  return i;
227  }
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
Definition: JStringFacet.hh:34
static bool is_eol(const char c)
Definition: JCppFacet.hh:49
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  return i;
248  }
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
Definition: JStringFacet.hh:34
static bool is_end_single_line_comment(const char c1)
Definition: JCppFacet.hh:54
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 258 of file JCppFacet.hh.

260  {
261  istreambuf_iterator i = __begin;
262 
263  if (i != __end) {
264 
265  char c = *i;
266 
267  for (++i; i != __end && !is_end_multi_line_comment(c,*i); c = *i, ++i) {}
268 
269  if (i != __end)
270  ++i; // skip end of line
271  }
272 
273  return i;
274  }
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
Definition: JStringFacet.hh:34
static bool is_end_multi_line_comment(const char c1, const char c2)
Definition: JCppFacet.hh:55
void JLANG::JCppFacet::operator= ( const JCppFacet )
private
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  }
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
Definition: JStringFacet.hh:34
virtual istreambuf_iterator do_ignore(const istreambuf_iterator __begin, const istreambuf_iterator __end) const
Ignore characters until next end of line.
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  }
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
Definition: JStringFacet.hh:34
virtual istreambuf_iterator do_getline(const istreambuf_iterator __begin, const istreambuf_iterator __end, std::ios_base::iostate &result, std::string &buffer) const
Read string.
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  }
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  }
std::istreambuf_iterator< char, std::char_traits< char > > istreambuf_iterator
Definition: JStringFacet.hh:34

Member Data Documentation

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: