NCBI C++ ToolKit
comments.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: comments.cpp 69987 2015-11-25 13:58:19Z gouriano $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Author: Eugene Vasilchenko
27 *
28 * File Description:
29 * !!! PUT YOUR DESCRIPTION HERE !!!
30 *
31 */
32 
33 #include <ncbi_pch.hpp>
34 #include <corelib/ncbistd.hpp>
35 #include <corelib/ncbiutil.hpp>
36 #include "comments.hpp"
37 #include "srcutil.hpp"
38 
40 
42 {
43 }
44 
46 {
47 }
48 
50 {
51  m_Comments = other.m_Comments;
52  return *this;
53 }
54 
55 void CComments::Add(const string& s)
56 {
57  m_Comments.push_back(s);
58 }
59 
61  const string& before,
62  const string& between,
63  const string& after) const
64 {
65  out << before;
66 
68  if ( i != m_Comments.begin() )
69  out << between;
70  out << *i;
71  }
72 
73  return out << after;
74 }
75 
77 {
78  return Empty() ? out : Print(out, " ///<"," ",kEmptyStr);
79 }
80 
82 {
83  return Empty() ? out : Print(out, "///","\n///","\n");
84 }
85 
87 {
88  return Empty() ? out : Print(out, " ///","\n ///","\n");
89 }
90 
91 bool CComments::PrintSchemaComments(CNcbiOstream& out, int indent, int /*flags*/) const
92 {
93  if ( Empty() ) {
94  return false;
95  }
96 
97  out << '>'; // close 'element' tag
98 #if 0
99  PrintASNNewLine(out, indent) << "<xs:annotation><xs:documentation>";
100  ITERATE ( TComments, i, m_Comments ) {
101  out << '\n' << *i;
102  }
103  PrintASNNewLine(out, indent) << "</xs:documentation></xs:annotation>";
104 #else
105  if ( OneLine() ) {
106  PrintASNNewLine(out, indent) << "<xs:annotation><xs:documentation>";
107  out << NStr::TruncateSpaces(m_Comments.front());
108  out << "</xs:documentation></xs:annotation>";
109  }
110  else {
111  PrintASNNewLine(out, indent) << "<xs:annotation><xs:documentation>";
112  ITERATE ( TComments, i, m_Comments ) {
113  out << '\n' << *i;
114  }
115  PrintASNNewLine(out, indent) << "</xs:documentation></xs:annotation>";
116  }
117 #endif
118  return true;
119 }
120 
121 CNcbiOstream& CComments::PrintDTD(CNcbiOstream& out, int flags) const
122 {
123  if ( Empty() ) // no comments
124  return out;
125 
126  if ( !(flags & eDoNotWriteBlankLine) ) {
127  // prepend comments by empty line to separate from previous comments
128  out << '\n';
129  }
130 
131  // comments start
132  out <<
133  "<!--";
134 
135  if ( !(flags & eAlwaysMultiline) && OneLine() ) {
136  // one line comment
137  out << m_Comments.front() << ' ';
138  }
139  else {
140  // multiline comments
141  out << '\n';
142  ITERATE ( TComments, i, m_Comments ) {
143  out << *i << '\n';
144  }
145  }
146 
147  // comments end
148  out << "-->";
149 
150  if ( !(flags & eNoEOL) )
151  out << '\n';
152 
153  return out;
154 }
155 
156 CNcbiOstream& CComments::PrintASN(CNcbiOstream& out,
157  int indent, int flags) const
158 {
159  if ( Empty() ) // no comments
160  return out;
161 
162  bool newLine = (flags & eDoNotWriteBlankLine) == 0;
163  // prepend comments by empty line to separate from previous comments
164 
165  ITERATE ( TComments, i, m_Comments ) {
166  if ( newLine )
167  PrintASNNewLine(out, indent);
168  out << "--" << NStr::Replace(*i, "--", "");
169  newLine = true;
170  }
171 
172  if ( (flags & eNoEOL) == 0 )
173  PrintASNNewLine(out, indent);
174 
175  return out;
176 }
177 
178 END_NCBI_SCOPE
void Add(const string &s)
Definition: comments.cpp:55
TComments m_Comments
Definition: comments.hpp:77
CComments(void)
Definition: comments.cpp:41
bool PrintSchemaComments(CNcbiOstream &out, int indent, int flags=0) const
Definition: comments.cpp:91
CNcbiOstream & PrintHPPClass(CNcbiOstream &out) const
Definition: comments.cpp:81
CNcbiOstream & Print(CNcbiOstream &out, const string &before, const string &between, const string &after) const
Definition: comments.cpp:60
CComments & operator=(const CComments &other)
Definition: comments.cpp:49
CNcbiOstream & PrintHPPMember(CNcbiOstream &out) const
Definition: comments.cpp:86
list< string > TComments
Definition: comments.hpp:75
bool Empty(void) const
Definition: comments.hpp:89
~CComments(void)
Definition: comments.cpp:45
CNcbiOstream & PrintHPPEnum(CNcbiOstream &out) const
Definition: comments.cpp:76
Include a standard set of the NCBI C++ Toolkit most basic headers.
std::ofstream out("events_result.xml")
main entry point for tests
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
int i
yy_size_t n
Useful/utility classes and methods.
string indent(" ")
Modified on Tue Dec 05 02:12:19 2023 by modify_doxy.py rev. 669887