1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef ADC_DISPLAY_OUT_NODE_HXX
29 #define ADC_DISPLAY_OUT_NODE_HXX
30 
31 
32 
33 
34 namespace output
35 {
36 
37 
38 /**	@resp
39     Represents a tree of names where each node can have only one parent,
40     but a list of children.
41 
42 	@see    Position
43 	@see    Tree
44 */
45 class Node
46 {
47   public:
48     typedef std::vector< Node* >    List;
49     typedef UINT32                  relative_id;
50 
51   	// LIFECYCLE
52   	enum E_NullObject { null_object };
53 
54   	                    Node();
55   	explicit            Node(
56   	                        E_NullObject        );
57   						~Node();
58 
59   	// OPERATORS
60   	bool                operator==(
61   	                        const Node &        i_node ) const
62   	                                            { return pParent == i_node.pParent AND sName == i_node.sName; }
63   	bool                operator!=(
64   	                        const Node &        i_node ) const
65   	                                            { return NOT operator==(i_node); }
66 
67   	// OPERATIONS
68   	/// Seek, and if not existent, create.
69   	Node &              Provide_Child(
70   	                        const String &      i_name );
71   	/// Seek, and if not existent, create.
72   	Node &              Provide_Child(
73   	                        const StringVector &
74   	                                            i_path )
75   	                                            { return provide_Child(i_path.begin(), i_path.end()); }
76   	// INQUIRY
77   	intt                Depth() const           { return nDepth; }
78 
79     const String &      Name() const            { return sName; }
80     /// @return Id of a namespace or class etc. this directory represents.
81     relative_id         RelatedNameRoom() const { return nNameRoomId; }
82     /// @return No delimiter at start, with delimiter at end.
83     void                Get_Path(
84                             StreamStr &         o_result,
85                             intt                i_maxDepth = -1 ) const;
86     void                Get_Chain(
87                             StringVector &      o_result,
88                             intt                i_maxDepth = -1 ) const;
89     // ACCESS
90     void                Set_RelatedNameRoom(
91                             relative_id         i_nNameRoomId )
92                                                 { nNameRoomId = i_nNameRoomId; }
93   	Node *              Parent()                { return pParent; }
94   	Node *              Child(
95   	                        const String &      i_name )
96   	                                            { return find_Child(i_name); }
97     List &              Children()              { return aChildren; }
98 
99     /// @return a reference to a Node with Depth() == -1.
100     static Node &       Null_();
101 
102   private:
103   	// Local
104   						Node(
105   						    const String &      i_name,
106   						    Node &              i_parent );
107 
108   	Node *              find_Child(
109   	                        const String &      i_name );
110   	Node &              add_Child(
111   	                        const String &      i_name );
112   	Node &              provide_Child(
113   	                        StringVector::const_iterator
114   	                                            i_next,
115   	                        StringVector::const_iterator
116   	                                            i_end );
117   	// Data
118   	String              sName;
119   	Node *              pParent;
120   	List                aChildren;
121   	intt                nDepth;
122     relative_id         nNameRoomId;
123 };
124 
125 
126 
127 
128 }   // namespace output
129 #endif
130