xref: /trunk/main/codemaker/source/codemaker/exceptiontree.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_codemaker.hxx"
26 
27 #include "codemaker/exceptiontree.hxx"
28 #include "codemaker/typemanager.hxx"
29 
30 #include "osl/diagnose.h"
31 #include "registry/reader.hxx"
32 #include "registry/types.h"
33 #include "rtl/string.hxx"
34 #include "rtl/textenc.h"
35 #include "rtl/ustring.hxx"
36 
37 #include <memory>
38 #include <vector>
39 
40 using codemaker::ExceptionTree;
41 using codemaker::ExceptionTreeNode;
42 
add(rtl::OString const & theName)43 ExceptionTreeNode * ExceptionTreeNode::add(rtl::OString const & theName) {
44     std::auto_ptr< ExceptionTreeNode > node(new ExceptionTreeNode(theName));
45     children.push_back(node.get());
46     return node.release();
47 }
48 
clearChildren()49 void ExceptionTreeNode::clearChildren() {
50     for (Children::iterator i(children.begin()); i != children.end(); ++i) {
51         delete *i;
52     }
53     children.clear();
54 }
55 
add(rtl::OString const & name,TypeManager const & manager)56 void ExceptionTree::add(rtl::OString const & name, TypeManager const & manager)
57 {
58     typedef std::vector< rtl::OString > List;
59     List list;
60     bool runtimeException = false;
61     for (rtl::OString n(name); n != "com/sun/star/uno/Exception";) {
62         if (n == "com/sun/star/uno/RuntimeException") {
63             runtimeException = true;
64             break;
65         }
66         list.push_back(n);
67         typereg::Reader reader(manager.getTypeReader(n));
68         if (!reader.isValid())
69             throw CannotDumpException(
70                 ::rtl::OString("Unknown type '" + n.replace('/', '.')
71                                + "', incomplete type library."));
72 
73         OSL_ASSERT(
74             reader.getTypeClass() == RT_TYPE_EXCEPTION
75             && reader.getSuperTypeCount() == 1);
76         n = rtl::OUStringToOString(
77             reader.getSuperTypeName(0), RTL_TEXTENCODING_UTF8);
78     }
79     if (!runtimeException) {
80         ExceptionTreeNode * node = &m_root;
81         for (List::reverse_iterator i(list.rbegin()); !node->present; ++i) {
82             if (i == list.rend()) {
83                 node->setPresent();
84                 break;
85             }
86             for (ExceptionTreeNode::Children::iterator j(
87                      node->children.begin());;
88                  ++j)
89             {
90                 if (j == node->children.end()) {
91                     node = node->add(*i);
92                     break;
93                 }
94                 if ((*j)->name == *i) {
95                     node = *j;
96                     break;
97                 }
98             }
99         }
100     }
101 }
102