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