xref: /aoo4110/main/autodoc/inc/ary/getncast.hxx (revision b1cdbd2c)
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_GETNCAST_HXX
25 #define ARY_GETNCAST_HXX
26 
27 
28 // USED SERVICES
29 #include <ary/object.hxx>
30 
31 
32 
33 
34 namespace ary
35 {
36 
37 
38 template <class DEST>
39 inline bool
is_type(const ary::Object & i_obj)40 is_type(const ary::Object & i_obj)
41 {
42     return i_obj.AryClass() == DEST::class_id;
43 }
44 
45 
46 template <class DEST>
47 inline const DEST &
ary_cast(const Object & ce)48 ary_cast( const Object & ce)
49 {
50     csv_assert( is_type<DEST>(ce) );
51     return static_cast< const DEST& >(ce);
52 }
53 
54 template <class DEST>
55 inline DEST &
ary_cast(Object & ce)56 ary_cast( Object & ce)
57 {
58     csv_assert( is_type<DEST>(ce) );
59     return static_cast< DEST& >(ce);
60 }
61 
62 template <class DEST>
63 inline const DEST *
ary_cast(const Object * ce)64 ary_cast( const Object * ce)
65 {
66     if ( ce ? is_type<DEST>(*ce) : false )
67         return static_cast< const DEST* >(ce);
68     return 0;
69 }
70 
71 template <class DEST>
72 inline DEST *
ary_cast(Object * ce)73 ary_cast( Object * ce)
74 {
75     if ( ce ? is_type<DEST>(*ce) : false )
76         return static_cast< DEST* >(ce);
77     return 0;
78 }
79 
80 
81 
82 
83 }   // namespace ary
84 #endif
85