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 ADC_DISPLAY_OUT_NODE_HXX
25 #define ADC_DISPLAY_OUT_NODE_HXX
26 
27 
28 
29 
30 namespace output
31 {
32 
33 
34 /**	@resp
35     Represents a tree of names where each node can have only one parent,
36     but a list of children.
37 
38 	@see    Position
39 	@see    Tree
40 */
41 class Node
42 {
43   public:
44     typedef std::vector< Node* >    List;
45     typedef UINT32                  relative_id;
46 
47   	// LIFECYCLE
48   	enum E_NullObject { null_object };
49 
50   	                    Node();
51   	explicit            Node(
52   	                        E_NullObject        );
53   						~Node();
54 
55   	// OPERATORS
operator ==(const Node & i_node) const56   	bool                operator==(
57   	                        const Node &        i_node ) const
58   	                                            { return pParent == i_node.pParent AND sName == i_node.sName; }
operator !=(const Node & i_node) const59   	bool                operator!=(
60   	                        const Node &        i_node ) const
61   	                                            { return NOT operator==(i_node); }
62 
63   	// OPERATIONS
64   	/// Seek, and if not existent, create.
65   	Node &              Provide_Child(
66   	                        const String &      i_name );
67   	/// Seek, and if not existent, create.
Provide_Child(const StringVector & i_path)68   	Node &              Provide_Child(
69   	                        const StringVector &
70   	                                            i_path )
71   	                                            { return provide_Child(i_path.begin(), i_path.end()); }
72   	// INQUIRY
Depth() const73   	intt                Depth() const           { return nDepth; }
74 
Name() const75     const String &      Name() const            { return sName; }
76     /// @return Id of a namespace or class etc. this directory represents.
RelatedNameRoom() const77     relative_id         RelatedNameRoom() const { return nNameRoomId; }
78     /// @return No delimiter at start, with delimiter at end.
79     void                Get_Path(
80                             StreamStr &         o_result,
81                             intt                i_maxDepth = -1 ) const;
82     void                Get_Chain(
83                             StringVector &      o_result,
84                             intt                i_maxDepth = -1 ) const;
85     // ACCESS
Set_RelatedNameRoom(relative_id i_nNameRoomId)86     void                Set_RelatedNameRoom(
87                             relative_id         i_nNameRoomId )
88                                                 { nNameRoomId = i_nNameRoomId; }
Parent()89   	Node *              Parent()                { return pParent; }
Child(const String & i_name)90   	Node *              Child(
91   	                        const String &      i_name )
92   	                                            { return find_Child(i_name); }
Children()93     List &              Children()              { return aChildren; }
94 
95     /// @return a reference to a Node with Depth() == -1.
96     static Node &       Null_();
97 
98   private:
99   	// Local
100   						Node(
101   						    const String &      i_name,
102   						    Node &              i_parent );
103 
104   	Node *              find_Child(
105   	                        const String &      i_name );
106   	Node &              add_Child(
107   	                        const String &      i_name );
108   	Node &              provide_Child(
109   	                        StringVector::const_iterator
110   	                                            i_next,
111   	                        StringVector::const_iterator
112   	                                            i_end );
113   	// Data
114   	String              sName;
115   	Node *              pParent;
116   	List                aChildren;
117   	intt                nDepth;
118     relative_id         nNameRoomId;
119 };
120 
121 
122 
123 
124 }   // namespace output
125 #endif
126