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 ARY_TRAITS_IMPL_HXX
29 #define ARY_TRAITS_IMPL_HXX
30 
31 
32 // USED SERVICES
33 #include <ary/getncast.hxx>
34 
35 
36 namespace ary
37 {
38 namespace traits
39 {
40 
41 
42 /** Finds the node assigned to an entity, if that entity has a specific
43     actual type.
44 
45     @tpl NODE
46     The assumed actual type of io_node.
47 */
48 template<class NODE>
49 const typename NODE::node_t *
50                     NodeOf(
51                         const typename NODE::traits_t::entity_base_type &
52                                                 io_node );
53 
54 /** Finds the node assigned to an entity, if that entity has a specific
55     actual type.
56 
57     @tpl NODE
58     The assumed actual type of io_node.
59 */
60 template<class NODE>
61 typename NODE::node_t *
62                     NodeOf(
63                         typename NODE::traits_t::entity_base_type &
64                                                 io_node );
65 
66 /** Finds a child to a node.
67 */
68 template<class NODE, class KEY>
69 typename NODE::traits_t::id_type
70                     Search_Child(
71                         const typename NODE::traits_t::entity_base_type &
72                                                 i_node,
73                         const KEY &             i_localKey );
74 
75 
76 
77 
78 // IMPLEMENTATION
79 
80 template<class NODE>
81 const typename NODE::node_t *
82 NodeOf(const typename NODE::traits_t::entity_base_type & io_node)
83 {
84     const NODE *
85         pn = ary_cast<NODE>(&io_node);
86     if (pn != 0)
87         return & pn->AsNode();
88     return 0;
89 }
90 
91 template<class NODE>
92 typename NODE::node_t *
93 NodeOf(typename NODE::traits_t::entity_base_type & io_node)
94 {
95     NODE *
96         pn = ary_cast<NODE>(&io_node);
97     if (pn != 0)
98         return & pn->AsNode();
99     return 0;
100 }
101 
102 template<class NODE, class KEY>
103 typename NODE::traits_t::id_type
104 Search_Child( const typename NODE::traits_t::entity_base_type & i_node,
105               const KEY &                                       i_localKey )
106 {
107     const NODE *
108         pn = ary_cast<NODE>(&i_node);
109     if (pn != 0)
110         return pn->Search_Child(i_localKey);
111     return typename NODE::traits_t::id_type(0);
112 }
113 
114 
115 
116 
117 }   // namespace traits
118 }   // namespace ary
119 #endif
120