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 "pm_index.hxx"
24
25
26 // NOT FULLY DEFINED SERVICES
27 #include <ary/cpp/c_gate.hxx>
28 #include <ary/cpp/c_class.hxx>
29 #include <ary/cpp/c_define.hxx>
30 #include <ary/cpp/c_enum.hxx>
31 #include <ary/cpp/c_enuval.hxx>
32 #include <ary/cpp/c_funct.hxx>
33 #include <ary/cpp/c_macro.hxx>
34 #include <ary/cpp/c_namesp.hxx>
35 #include <ary/cpp/c_tydef.hxx>
36 #include <ary/cpp/c_vari.hxx>
37 #include <ary/cpp/cp_ce.hxx>
38 #include "aryattrs.hxx"
39 #include "hd_chlst.hxx"
40 #include "hd_docu.hxx"
41 #include "html_kit.hxx"
42 #include "navibar.hxx"
43 #include "opageenv.hxx"
44 #include "pagemake.hxx"
45 #include "strconst.hxx"
46
47 using namespace csi;
48 using ary::GlobalId;
49
50
51
52
53 namespace
54 {
55
56 inline const char *
F_CK_Text(ary::cpp::E_ClassKey i_eCK)57 F_CK_Text( ary::cpp::E_ClassKey i_eCK )
58 {
59 switch (i_eCK)
60 {
61 case ary::cpp::CK_class: return "class";
62 case ary::cpp::CK_struct: return "struct";
63 case ary::cpp::CK_union: return "union";
64 } // end switch
65 return "";
66 }
67
68 template <class CE>
69 inline const char *
F_OwnerType(const CE & i_rData,const ary::cpp::Gate & i_rGate)70 F_OwnerType( const CE & i_rData, const ary::cpp::Gate & i_rGate )
71 {
72 if ( i_rData.Protection() == ary::cpp::PROTECT_global )
73 return "namespace ";
74
75 const ary::cpp::Class *
76 pClass = dynamic_cast< const ary::cpp::Class* >(
77 i_rGate.Ces().Search_Ce(i_rData.Owner()) );
78 if (pClass != 0)
79 return F_CK_Text(pClass->ClassKey());
80 return "";
81 }
82
83 } // anonymous namespace
84
PageMaker_Index(PageDisplay & io_rPage,char i_c)85 PageMaker_Index::PageMaker_Index( PageDisplay & io_rPage,
86 char i_c )
87 : SpecializedPageMaker(io_rPage),
88 pNavi(0),
89 c(i_c),
90 pCurIndex(0)
91 {
92 }
93
~PageMaker_Index()94 PageMaker_Index::~PageMaker_Index()
95 {
96 }
97
98 void
MakePage()99 PageMaker_Index::MakePage()
100 {
101 pNavi = new NavigationBar( Env(), NavigationBar::LOC_Index );
102
103 Write_NavBar();
104 Write_TopArea();
105 Write_CompleteAlphabeticalList();
106 }
107
108 void
do_Process(const ary::cpp::Namespace & i_rData)109 PageMaker_Index::do_Process( const ary::cpp::Namespace & i_rData )
110 {
111 Write_CeIndexEntry( i_rData, "namespace", "namespace" );
112 }
113
114 void
do_Process(const ary::cpp::Class & i_rData)115 PageMaker_Index::do_Process( const ary::cpp::Class & i_rData )
116 {
117 // KORR_FUTURE
118 // Really throw out all anonymous classes from index?
119
120 if ( strncmp(i_rData.LocalName().c_str()+1,"_Anonymous",10) == 0 )
121 return;
122
123 Write_CeIndexEntry( i_rData,
124 F_CK_Text(i_rData.ClassKey()),
125 F_OwnerType(i_rData, Env().Gate()) );
126 }
127
128 void
do_Process(const ary::cpp::Enum & i_rData)129 PageMaker_Index::do_Process( const ary::cpp::Enum & i_rData )
130 {
131 Write_CeIndexEntry( i_rData, "enum", F_OwnerType(i_rData, Env().Gate()) );
132 }
133
134 void
do_Process(const ary::cpp::Typedef & i_rData)135 PageMaker_Index::do_Process( const ary::cpp::Typedef & i_rData )
136 {
137 Write_CeIndexEntry( i_rData, "typedef", F_OwnerType(i_rData, Env().Gate()) );
138 }
139
140 void
do_Process(const ary::cpp::Function & i_rData)141 PageMaker_Index::do_Process( const ary::cpp::Function & i_rData )
142 {
143 Write_CeIndexEntry( i_rData, "function", F_OwnerType(i_rData, Env().Gate()) );
144 }
145
146 void
do_Process(const ary::cpp::Variable & i_rData)147 PageMaker_Index::do_Process( const ary::cpp::Variable & i_rData )
148 {
149 Write_CeIndexEntry( i_rData, "variable", F_OwnerType(i_rData, Env().Gate()) );
150 }
151
152 void
do_Process(const ary::cpp::EnumValue & i_rData)153 PageMaker_Index::do_Process( const ary::cpp::EnumValue & i_rData )
154 {
155 Write_CeIndexEntry( i_rData, "enum value", "" );
156 }
157
158 void
do_Process(const ary::cpp::Define & i_rData)159 PageMaker_Index::do_Process( const ary::cpp::Define & i_rData )
160 {
161 String sFileName;
162
163 pCurIndex->AddEntry();
164 pCurIndex->Term()
165 >> *new html::Link( Link2CppDefinition(Env(), i_rData) )
166 >> *new html::Bold
167 << i_rData.LocalName();
168 pCurIndex->Term()
169 << " - define";
170 pCurIndex->Def() << " ";
171 }
172
173 void
do_Process(const ary::cpp::Macro & i_rData)174 PageMaker_Index::do_Process( const ary::cpp::Macro & i_rData )
175 {
176 String sFileName;
177
178 pCurIndex->AddEntry();
179 pCurIndex->Term()
180 >> *new html::Link( Link2CppDefinition(Env(), i_rData) )
181 >> *new html::Bold
182 << i_rData.LocalName();
183 pCurIndex->Term()
184 << " - macro";
185
186 pCurIndex->Def() << " ";
187 }
188
189 const ary::cpp::Gate *
inq_Get_ReFinder() const190 PageMaker_Index::inq_Get_ReFinder() const
191 {
192 return &Env().Gate();
193 }
194
195 void
Write_NavBar()196 PageMaker_Index::Write_NavBar()
197 {
198 pNavi->Write( CurOut() );
199 CurOut() << new html::HorizontalLine;
200 }
201
202
203 const String C_sAlphabet(
204 "<a href=\"index-1.html\"><B>A</B></a> <a href=\"index-2.html\"><B>B</B></a> <a href=\"index-3.html\"><B>C</B></a> <a href=\"index-4.html\"><B>D</B></a> <a href=\"index-5.html\"><B>E</B></a> "
205 "<a href=\"index-6.html\"><B>F</B></a> <a href=\"index-7.html\"><B>G</B></a> <a href=\"index-8.html\"><B>H</B></a> <a href=\"index-9.html\"><B>I</B></a> <a href=\"index-10.html\"><B>J</B></a> "
206 "<a href=\"index-11.html\"><B>K</B></a> <a href=\"index-12.html\"><B>L</B></a> <a href=\"index-13.html\"><B>M</B></a> <a href=\"index-14.html\"><B>N</B></a> <a href=\"index-15.html\"><B>O</B></a> "
207 "<a href=\"index-16.html\"><B>P</B></a> <a href=\"index-17.html\"><B>Q</B></a> <a href=\"index-18.html\"><B>R</B></a> <a href=\"index-19.html\"><B>S</B></a> <a href=\"index-20.html\"><B>T</B></a> "
208 "<a href=\"index-21.html\"><B>U</B></a> <a href=\"index-22.html\"><B>V</B></a> <a href=\"index-23.html\"><B>W</B></a> <a href=\"index-24.html\"><B>X</B></a> <a href=\"index-25.html\"><B>Y</B></a> "
209 "<a href=\"index-26.html\"><B>Z</B></a> <a href=\"index-27.html\"><B>_</B></a>" );
210
211 void
Write_TopArea()212 PageMaker_Index::Write_TopArea()
213 {
214 String sLetter(&c, 1);
215
216 adcdisp::PageTitle_Std fTitle;
217 fTitle( CurOut(), "Global Index", sLetter );
218
219 CurOut() >>* new html::Paragraph
220 << new html::AlignAttr("center")
221 << new xml::XmlCode(C_sAlphabet);
222
223 CurOut() << new html::HorizontalLine;
224 }
225
226 void
Write_CompleteAlphabeticalList()227 PageMaker_Index::Write_CompleteAlphabeticalList()
228 {
229 std::vector<GlobalId>
230 aThisPagesItems;
231 const ary::cpp::Gate &
232 rGate = Env().Gate();
233
234 static char sBegin[] = "X";
235 static char sEnd[] = "Y";
236
237 switch ( c )
238 {
239 case 'Z': sBegin[0] = 'Z';
240 sEnd[0] = '_';
241 break;
242 case '_': sBegin[0] = '_';
243 sEnd[0] = '0';
244 break;
245 default: sBegin[0] = c;
246 sEnd[0] = char(c + 1);
247 break;
248 }
249
250 uintt
251 nCount = rGate.Get_AlphabeticalList( aThisPagesItems, sBegin, sEnd );
252 if (nCount > 0 )
253 {
254 adcdisp::IndexList
255 aIndex(CurOut());
256 pCurIndex = &aIndex;
257
258 std::vector<GlobalId>::const_iterator itEnd = aThisPagesItems.end();
259 for ( std::vector<GlobalId>::const_iterator it = aThisPagesItems.begin();
260 it != itEnd;
261 ++it )
262 {
263 const ary::Entity *
264 pRe = rGate.Search_Entity( *it );
265 if ( pRe != 0 )
266 pRe->Accept(*this);
267 } // end for
268
269 pCurIndex = 0;
270 } // endif (nCount > 0)
271 }
272
273 void
Write_CeIndexEntry(const ary::cpp::CodeEntity & i_rCe,const char * i_sType,const char * i_sOwnerType)274 PageMaker_Index::Write_CeIndexEntry( const ary::cpp::CodeEntity &
275 i_rCe,
276 const char * i_sType,
277 const char * i_sOwnerType )
278 {
279 if ( Ce_IsInternal(i_rCe) )
280 return;
281
282 static csv::StreamStr aQualification(500);
283
284 const ary::cpp::CodeEntity &
285 rOwner = Env().Gate().Ces().Find_Ce(i_rCe.Owner());
286
287 pCurIndex->AddEntry();
288 pCurIndex->Term()
289 >> *new html::Link( Link2Ce(Env(), i_rCe) )
290 >> *new html::Bold
291 << i_rCe.LocalName();
292 pCurIndex->Term()
293 << " - "
294 << i_sType;
295
296 if ( rOwner.Owner().IsValid() )
297 {
298 aQualification.seekp(0);
299 Env().Gate().Ces().Get_QualifiedName( aQualification,
300 rOwner.LocalName(),
301 rOwner.Owner() );
302
303 pCurIndex->Term()
304 << " in "
305 << i_sOwnerType
306 << " "
307 << aQualification.c_str();
308 }
309
310 pCurIndex->Def() << " ";
311 }
312