xref: /aoo41x/main/autodoc/inc/ary/getncast.hxx (revision 1c78a5d6)
1*1c78a5d6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1c78a5d6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1c78a5d6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1c78a5d6SAndrew Rist  * distributed with this work for additional information
6*1c78a5d6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1c78a5d6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1c78a5d6SAndrew Rist  * "License"); you may not use this file except in compliance
9*1c78a5d6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1c78a5d6SAndrew Rist  *
11*1c78a5d6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1c78a5d6SAndrew Rist  *
13*1c78a5d6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1c78a5d6SAndrew Rist  * software distributed under the License is distributed on an
15*1c78a5d6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1c78a5d6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1c78a5d6SAndrew Rist  * specific language governing permissions and limitations
18*1c78a5d6SAndrew Rist  * under the License.
19*1c78a5d6SAndrew Rist  *
20*1c78a5d6SAndrew Rist  *************************************************************/
21*1c78a5d6SAndrew Rist 
22*1c78a5d6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef ARY_GETNCAST_HXX
25cdf0e10cSrcweir #define ARY_GETNCAST_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // USED SERVICES
29cdf0e10cSrcweir #include <ary/object.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace ary
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir 
38cdf0e10cSrcweir template <class DEST>
39cdf0e10cSrcweir inline bool
is_type(const ary::Object & i_obj)40cdf0e10cSrcweir is_type(const ary::Object & i_obj)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     return i_obj.AryClass() == DEST::class_id;
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 
46cdf0e10cSrcweir template <class DEST>
47cdf0e10cSrcweir inline const DEST &
ary_cast(const Object & ce)48cdf0e10cSrcweir ary_cast( const Object & ce)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir     csv_assert( is_type<DEST>(ce) );
51cdf0e10cSrcweir     return static_cast< const DEST& >(ce);
52cdf0e10cSrcweir }
53cdf0e10cSrcweir 
54cdf0e10cSrcweir template <class DEST>
55cdf0e10cSrcweir inline DEST &
ary_cast(Object & ce)56cdf0e10cSrcweir ary_cast( Object & ce)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     csv_assert( is_type<DEST>(ce) );
59cdf0e10cSrcweir     return static_cast< DEST& >(ce);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir template <class DEST>
63cdf0e10cSrcweir inline const DEST *
ary_cast(const Object * ce)64cdf0e10cSrcweir ary_cast( const Object * ce)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     if ( ce ? is_type<DEST>(*ce) : false )
67cdf0e10cSrcweir         return static_cast< const DEST* >(ce);
68cdf0e10cSrcweir     return 0;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir template <class DEST>
72cdf0e10cSrcweir inline DEST *
ary_cast(Object * ce)73cdf0e10cSrcweir ary_cast( Object * ce)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     if ( ce ? is_type<DEST>(*ce) : false )
76cdf0e10cSrcweir         return static_cast< DEST* >(ce);
77cdf0e10cSrcweir     return 0;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir }   // namespace ary
84cdf0e10cSrcweir #endif
85