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