1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <precomp.h>
23 #include <adc_msg.hxx>
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <cosv/file.hxx>
28 #include <cosv/tpl/tpltools.hxx>
29
30
31 namespace autodoc
32 {
33
34
Messages()35 Messages::Messages()
36 : aMissingDocs(),
37 aParseErrors(),
38 aInvalidConstSymbols(),
39 aUnresolvedLinks(),
40 aTypeVsMemberMisuses()
41 {
42 }
43
~Messages()44 Messages::~Messages()
45 {
46 }
47
48 void
WriteFile(const String & i_sOutputFilePath)49 Messages::WriteFile(const String & i_sOutputFilePath)
50 {
51 csv::File
52 aOut(i_sOutputFilePath, csv::CFM_CREATE);
53 aOut.open();
54
55 // KORR_FUTURE Enable this when appropriate:
56 WriteParagraph( aOut,
57 aParseErrors,
58 "Incompletely Parsed Files",
59 "Stopped parsing at " );
60
61 WriteParagraph( aOut,
62 aMissingDocs,
63 "Entities Without Documentation",
64 " in " );
65
66 WriteParagraph( aOut,
67 aInvalidConstSymbols,
68 "Incorrectly Written Const Symbols",
69 " in " );
70
71 WriteParagraph( aOut,
72 aUnresolvedLinks,
73 "Unresolved Links",
74 " in\n " );
75
76 WriteParagraph( aOut,
77 aTypeVsMemberMisuses,
78 "Confusion or Misuse of <Type> vs. <Member>",
79 " in " );
80 aOut.close();
81 }
82
83 void
Out_MissingDoc(const String & i_sEntity,const String & i_sFile,uintt i_nLine)84 Messages::Out_MissingDoc( const String & i_sEntity,
85 const String & i_sFile,
86 uintt i_nLine)
87 {
88 AddValue( aMissingDocs,
89 i_sEntity,
90 i_sFile,
91 i_nLine );
92 }
93
94 void
Out_ParseError(const String & i_sFile,uintt i_nLine)95 Messages::Out_ParseError( const String & i_sFile,
96 uintt i_nLine)
97 {
98 aParseErrors[Location(i_sFile,i_nLine)] = String::Null_();
99 }
100
101 void
Out_InvalidConstSymbol(const String & i_sText,const String & i_sFile,uintt i_nLine)102 Messages::Out_InvalidConstSymbol( const String & i_sText,
103 const String & i_sFile,
104 uintt i_nLine)
105 {
106 AddValue( aInvalidConstSymbols,
107 i_sText,
108 i_sFile,
109 i_nLine );
110 }
111
112 void
Out_UnresolvedLink(const String & i_sLinkText,const String & i_sFile,uintt i_nLine)113 Messages::Out_UnresolvedLink( const String & i_sLinkText,
114 const String & i_sFile,
115 uintt i_nLine)
116 {
117 AddValue( aUnresolvedLinks,
118 i_sLinkText,
119 i_sFile,
120 i_nLine );
121 }
122
123 void
Out_TypeVsMemberMisuse(const String & i_sLinkText,const String & i_sFile,uintt i_nLine)124 Messages::Out_TypeVsMemberMisuse( const String & i_sLinkText,
125 const String & i_sFile,
126 uintt i_nLine)
127 {
128 AddValue( aTypeVsMemberMisuses,
129 i_sLinkText,
130 i_sFile,
131 i_nLine );
132 }
133
134 Messages &
The_()135 Messages::The_()
136 {
137 static Messages TheMessages_;
138 return TheMessages_;
139 }
140
141 void
AddValue(MessageMap & o_dest,const String & i_sText,const String & i_sFile,uintt i_nLine)142 Messages::AddValue( MessageMap & o_dest,
143 const String & i_sText,
144 const String & i_sFile,
145 uintt i_nLine )
146 {
147 String &
148 rDest = o_dest[Location(i_sFile,i_nLine)];
149 StreamLock
150 slDest(2000);
151 if (NOT rDest.empty())
152 slDest() << rDest;
153 slDest() << "\n " << i_sText;
154 rDest = slDest().c_str();
155 }
156
157 void
WriteParagraph(csv::File & o_out,const MessageMap & i_source,const String & i_title,const String &)158 Messages::WriteParagraph( csv::File & o_out,
159 const MessageMap & i_source,
160 const String & i_title,
161 const String & )
162 {
163 StreamStr aLine(2000);
164
165 // Write title of paragraph:
166 aLine << i_title
167 << "\n";
168 o_out.write(aLine.c_str());
169
170 aLine.seekp(0);
171 for (uintt i = i_title.size(); i > 0; --i)
172 {
173 aLine << '-';
174 }
175 aLine << "\n\n";
176 o_out.write(aLine.c_str());
177
178 // Write Content
179 MessageMap::const_iterator it = i_source.begin();
180 MessageMap::const_iterator itEnd = i_source.end();
181 for ( ; it != itEnd; ++it )
182 {
183 aLine.seekp(0);
184 aLine << (*it).first.sFile;
185 // Nobody wants to see this, if we don't know the line:
186 if ((*it).first.nLine != 0)
187 {
188 aLine << ", line "
189 << (*it).first.nLine;
190 }
191 if (NOT (*it).second.empty())
192 {
193 aLine << ':'
194 << (*it).second
195 << "\n";
196 }
197 o_out.write(aLine.c_str());
198 }
199 o_out.write("\n\n\n");
200 }
201
202 } // namespace autodoc
203