Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "codemaker/exceptiontree.hxx"
22 : #include "codemaker/typemanager.hxx"
23 :
24 : #include "osl/diagnose.h"
25 : #include "rtl/ref.hxx"
26 : #include "rtl/string.hxx"
27 : #include "rtl/textenc.h"
28 : #include "rtl/ustring.hxx"
29 : #include "unoidl/unoidl.hxx"
30 :
31 : #include <memory>
32 : #include <vector>
33 :
34 : using codemaker::ExceptionTree;
35 : using codemaker::ExceptionTreeNode;
36 :
37 96 : ExceptionTreeNode * ExceptionTreeNode::add(rtl::OString const & theName) {
38 96 : std::auto_ptr< ExceptionTreeNode > node(new ExceptionTreeNode(theName));
39 96 : children.push_back(node.get());
40 96 : return node.release();
41 : }
42 :
43 1412 : void ExceptionTreeNode::clearChildren() {
44 1508 : for (Children::iterator i(children.begin()); i != children.end(); ++i) {
45 96 : delete *i;
46 : }
47 1412 : children.clear();
48 1412 : }
49 :
50 285 : void ExceptionTree::add(
51 : rtl::OString const & name, rtl::Reference< TypeManager > const & manager)
52 : {
53 285 : std::vector< rtl::OString > list;
54 285 : bool runtimeException = false;
55 844 : for (rtl::OString n(name); n != "com.sun.star.uno.Exception";) {
56 449 : if (n == "com.sun.star.uno.RuntimeException") {
57 175 : runtimeException = true;
58 175 : break;
59 : }
60 274 : list.push_back(n);
61 274 : rtl::Reference< unoidl::Entity > ent;
62 274 : codemaker::UnoType::Sort s = manager->getSort(b2u(n), &ent);
63 : (void) s; // WaE: unused variable
64 : assert(s == codemaker::UnoType::SORT_EXCEPTION_TYPE);
65 548 : n = u2b(
66 274 : static_cast< unoidl::ExceptionTypeEntity * >(ent.get())->
67 274 : getDirectBase());
68 : assert(!n.isEmpty());
69 559 : }
70 285 : if (!runtimeException) {
71 110 : ExceptionTreeNode * node = &m_root;
72 412 : for (std::vector< rtl::OString >::reverse_iterator i(list.rbegin());
73 206 : !node->present; ++i)
74 : {
75 204 : if (i == list.rend()) {
76 108 : node->setPresent();
77 108 : break;
78 : }
79 47 : for (ExceptionTreeNode::Children::iterator j(
80 96 : node->children.begin());;
81 : ++j)
82 : {
83 143 : if (j == node->children.end()) {
84 96 : node = node->add(*i);
85 96 : break;
86 : }
87 47 : if ((*j)->name == *i) {
88 0 : node = *j;
89 0 : break;
90 : }
91 47 : }
92 : }
93 285 : }
94 285 : }
95 :
96 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|