30 : mMode(File), pSStream(0), mHasOutBuffer(false), mFileName(rFilename), mColumns(80/
FD_NAMELEN), mColCount(0) {
32 mFStream.exceptions(std::ios::badbit|std::ios::failbit);
34 mFStream.open(rFilename.c_str(), openmode);
36 catch (std::ios::failure&) {
37 std::stringstream errstr;
38 errstr <<
"Exception opening/writing file \""<< rFilename <<
"\"";
39 throw Exception(
"TokenWriter::TokenWriter", errstr.str(), 2);
48 : mMode(XmlFile), pSStream(0), mHasOutBuffer(false), mFileName(rFilename), mColumns(80/
FD_NAMELEN), mColCount(0) {
50 mFStream.exceptions(std::ios::badbit|std::ios::failbit);
52 mFStream.open(rFilename.c_str(), std::ios::out|std::ios::trunc);
53 mFStream <<
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?>" << std::endl;
56 std::string dtdfile=ftype;
57 std::transform(dtdfile.begin(), dtdfile.end(), dtdfile.begin(), tolower);
58 dtdfile=
"http://www.faudes.org/dtd/1.0/"+dtdfile+
".dtd";
59 mFStream <<
"<!DOCTYPE " << ftype <<
" SYSTEM \"" << dtdfile <<
"\">" << std::endl;
62 catch (std::ios::failure&) {
63 std::stringstream errstr;
64 errstr <<
"Exception opening/writing xml file \""<< rFilename <<
"\"";
65 throw Exception(
"TokenWriter::TokenWriter", errstr.str(), 2);
74 : mMode(mode), pSStream(0), mHasOutBuffer(false), mFileName(
""), mColumns(80/
FD_NAMELEN), mColCount(0) {
110 std::stringstream errstr;
111 errstr <<
"Invalid Mode / Not Implemented";
112 throw Exception(
"TokenWriter::TokenWriter", errstr.str(), 2);
119 : mMode(Stream), pSStream(&stream), mHasOutBuffer(false), mFileName(
"stream"), mColumns(0), mColCount(0) {
124 std::string dtdfile=ftype;
125 std::transform(dtdfile.begin(), dtdfile.end(), dtdfile.begin(), tolower);
126 dtdfile=
"http://www.faudes.org/dtd/1.0/"+dtdfile+
".dtd";
127 *
pSStream <<
"<!DOCTYPE " << ftype <<
" SYSTEM \"" << dtdfile <<
"\">" << std::endl;
130 }
catch (std::ios::failure&) {
131 std::stringstream errstr;
132 errstr <<
"Exception opening/writing xml stream";
133 throw Exception(
"TokenWriter::TokenWriter", errstr.str(), 2);
162 std::stringstream errstr;
163 errstr <<
"Not in String Mode";
164 throw Exception(
"TokenWriter::Str()", errstr.str(), 2);
195 catch (std::ios::failure&) {
196 std::stringstream errstr;
197 errstr <<
"Exception opening/writing file \"" <<
mFileName <<
"\"";
198 throw Exception(
"Generator::write", errstr.str(), 2);
211 FD_DV(
"TokenWriter::DoFlush()");
222 if(c==
'\r')
continue;
237 catch (std::ios::failure&) {
238 std::stringstream errstr;
239 errstr <<
"Exception opening/writing file \"" <<
mFileName <<
"\"";
240 throw Exception(
"TokenWriter::Write(token)", errstr.str(), 2);
247 FD_DV(
"TokenWriter::Write(token)");
301 if((rName ==
"\n") || (rName ==
"\r\n")) {
318 catch (std::ios::failure&) {
319 std::stringstream errstr;
320 errstr <<
"Exception opening/writing file \"" <<
mFileName <<
"\"";
321 throw Exception(
"TokenWriter::WriteText(text)", errstr.str(), 2);
328 std::stringstream errstr;
329 errstr <<
"Invalid begin token while writing file \"" <<
mFileName <<
"\"";
330 throw Exception(
"TokenWriter::WriteText(label,text)", errstr.str(), 2);
339 catch (std::ios::failure&) {
340 std::stringstream errstr;
341 errstr <<
"Exception writing file \"" <<
mFileName <<
"\"";
342 throw Exception(
"TokenWriter::WriteText(label,text)", errstr.str(), 2);
357 FD_DV(
"TokenWriter::Write(token)");
359 std::stringstream errstr;
360 errstr <<
"Invalid begin token while writing file \"" <<
mFileName <<
"\"";
361 throw Exception(
"TokenWriter::WriteVerbatim(tag,text)", errstr.str(), 2);
371 catch (std::ios::failure&) {
372 std::stringstream errstr;
373 errstr <<
"Exception opening/writing file \"" <<
mFileName <<
"\"";
374 throw Exception(
"TokenWriter::WriteVerbatim()", errstr.str(), 2);
390 if(rCharacterData.size()==0)
return;
396 catch (std::ios::failure&) {
397 std::stringstream errstr;
398 errstr <<
"Exception opening/writing file \"" <<
mFileName <<
"\"";
399 throw Exception(
"TokenWriter::WriteCharacterData(text)", errstr.str(), 2);
403 if(rCharacterData.size()>=1)
404 if(rCharacterData.at(rCharacterData.size()-1)==
'\n')
469 if(comment.length()==0)
471 if(comment.length()>0)
472 if(comment.at(0)!=
'%')
475 std::string::const_iterator cit=comment.begin();
476 for(;cit!=comment.end(); cit++) {
493 catch (std::ios::failure&) {
494 std::stringstream errstr;
495 errstr <<
"Exception opening/writing file \"" <<
mFileName <<
"\"";
496 throw Exception(
"TokenWriter::Comment", errstr.str(), 2);
509 static const std::string newline=
"\n\r";
510 if(comment.find_first_of(newline)!=std::string::npos)
513 std::string::const_iterator cit=comment.begin();
514 for(;cit!=comment.end(); cit++) {
525 catch (std::ios::failure&) {
526 std::stringstream errstr;
527 errstr <<
"Exception opening/writing file \"" <<
mFileName <<
"\"";
528 throw Exception(
"TokenWriter::Comment", errstr.str(), 2);
#define FD_NAMELEN
Length of strings for text fields in token output.
#define FD_DV(message)
Debug: optional low-level report on iterations and token IO.
static ConsoleOut * G(void)
Acess static instance.
virtual void Write(const std::string &message, long int cntnow=0, long int cntdone=0, int verb=0)
Write a std::string message (optional progress report and verbosity)
void WriteInteger16(long int val)
Write integer as hex.
std::ostringstream mSStream
Actual stream object, string output.
std::string FileName(void) const
Get the filename.
std::string Str(void)
Retrieve output as string (if in String mode)
void WriteFloat(const double &val)
Write float.
bool mEndl
Endl seperator on/off.
void WriteXmlComment(const std::string &rComment)
Write comment in Xml format.
std::ostream * mpStream
ostream object pointer
~TokenWriter(void)
Destructor.
std::string mFileName
Filename.
Token mOutBuffer
Outputbuffer.
void WriteText(const std::string &rText)
Write text.
Mode
Mode of operation: write to file, string or stdout.
void WriteEmpty(const std::string &rLabel)
Write empty section label.
int mColCount
Column counter.
void WriteCharacterData(const std::string &rCharData)
Write character data.
int mColumns
Number of columns.
void WriteComment(const std::string &rComment)
Write comment in faudes format.
void Write(Token &rToken)
Write next token.
void Endl(void)
Write endl separator.
std::ostream * Streamp(void)
Access C++ stream.
void WriteString(const std::string &rString)
Write string.
std::ostream * pSStream
Actual stream object, stream output.
void WriteEnd(const std::string &rLabel)
Write end label.
void WriteBinary(const char *pData, long int len)
Write comment.
int Columns(void) const
Get number of columns in a line.
void Flush(void)
Flush any buffers.
void WriteVerbatim(Token &rBeginTag, const std::string &rText)
Write verbatim text section.
TokenWriter(Mode mode)
Console or String TokenWriter constructor.
std::ofstream mFStream
Actual stream object, file output.
void DoFlush(bool clf=1)
Flush internal buffer.
void WriteInteger(Idx index)
Write non negative integer.
void WriteBegin(const std::string &rLabel)
Write begin label.
void WriteOption(const std::string &rOpt)
Write option (may not contain any "+")
Tokens model atomic data for stream IO.
void SetNone(void)
Initialize None token.
const std::string & PreceedingSpace(void) const
Preceeding space when writing to stream.
void SetInteger16(const Int number)
Initialize as Integer16 token.
const std::string & StringValue(void) const
Get string value of a name token.
void SetInteger(const Int number)
Initialize as Integer token.
@ End
<\label> (end of section)
static void WriteVerbatim(std::ostream *pStream, const std::string &rString, bool lfflag=0)
Write a std::string value to an output stream.
void Write(std::ostream *pStream) const
Write Token to output stream.
void SetString(const std::string &rName)
Initialize as String token.
void SetOption(const std::string &rName)
Initialize as Option token.
bool IsBegin(void) const
Test token Type.
void SetFloat(const faudes::Float number)
Initialize as Float token.
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
static void WriteBinary(std::ostream *pStream, const char *pData, std::size_t len)
Write specified binary data as base64 string to output stream.
static int WriteEscapedString(std::ostream *pStream, const std::string &outstr)
Write a std::string value to an output stream.
void SetBegin(const std::string &rName)
Initialize as Begin token.
bool IsEnd(void) const
Test token Type.
std::string mPreceedingSpace
Preceeding space (cosmetic)
void SetEnd(const std::string &rName)
Initialize as End token.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)