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 #ifndef INCLUDED_CODEMAKER_EXCEPTIONTREE_HXX
25 #define INCLUDED_CODEMAKER_EXCEPTIONTREE_HXX
26 
27 #include "codemaker/global.hxx"
28 #include "rtl/string.hxx"
29 
30 #include <vector>
31 
32 class TypeManager;
33 
34 namespace codemaker {
35 
36 /**
37    Represents a node of the hierarchy from the ExceptionTree class.
38  */
39 struct ExceptionTreeNode {
40     typedef std::vector< ExceptionTreeNode * > Children;
41 
42     // Internally used by ExceptionTree:
ExceptionTreeNodecodemaker::ExceptionTreeNode43     ExceptionTreeNode(rtl::OString const & theName):
44         name(theName), present(false) {}
45 
46     // Internally used by ExceptionTree:
~ExceptionTreeNodecodemaker::ExceptionTreeNode47     ~ExceptionTreeNode() { clearChildren(); }
48 
49     // Internally used by ExceptionTree:
setPresentcodemaker::ExceptionTreeNode50     void setPresent() { present = true; clearChildren(); }
51 
52     // Internally used by ExceptionTree:
53     ExceptionTreeNode * add(rtl::OString const & theName);
54 
55     rtl::OString name;
56     bool present;
57     Children children;
58 
59 private:
60     ExceptionTreeNode(ExceptionTreeNode &); // not implemented
61     void operator =(ExceptionTreeNode); // not implemented
62 
63     void clearChildren();
64 };
65 
66 /**
67    Represents the hierarchy formed by a set of UNO exception types.
68 
69    The hierarchy is rooted at com.sun.star.uno.Exception.  For each exception E
70    from the given set S, the hierarchy from com.sun.star.uno.Exception to the
71    first supertype E' of E which is itself a member of S is represented (i.e.,
72    subtypes that are hidden by supertypes are pruned from the hierarchy).  The
73    exception com.sun.star.uno.RuntimeException and its subtypes are pruned
74    completely from the hierarchy.  Each node of the hierarchy is represented by
75    an instance of ExceptionTreeNode, where name gives the slashified name of
76    the UNO exception type, present is true iff the given exception type is a
77    member of the set S, and children contains all the relevant direct subtypes
78    of the given exception type, in no particular order (for nodes other than the
79    root node it holds that children is non-empty iff present is false).
80  */
81 class ExceptionTree {
82 public:
ExceptionTree()83     ExceptionTree(): m_root("com/sun/star/uno/Exception") {}
84 
~ExceptionTree()85     ~ExceptionTree() {}
86 
87     /**
88        Builds the exception hierarchy, by adding one exception type at a time.
89 
90        This function can be called more than once for the same exception name.
91 
92        @param name the name of a UNO exception type, in slashified form; it is
93        an error if the given name does not represent a UNO exception type
94 
95        @param manager a type manager, used to resolve type names; it is an error
96        if different calls to this member function use different, incompatible
97        type managers
98      */
99     void add(rtl::OString const & name, TypeManager const & manager)
100         throw( CannotDumpException );
101 
102     /**
103        Gives access to the resultant exception hierarchy.
104 
105        @return a non-null pointer to the root of the exception hierarchy, as
106        formed by all previous calls to add; it is an error if any calls to add
107        follow the first call to getRoot
108      */
getRoot() const109     ExceptionTreeNode const * getRoot() const { return &m_root; }
110 
111 private:
112     ExceptionTree(ExceptionTree &); // not implemented
113     void operator =(ExceptionTree); // not implemented
114 
115     ExceptionTreeNode m_root;
116 };
117 
118 }
119 
120 #endif
121