xref: /AOO41X/main/configmgr/source/type.cxx (revision 3a7cf181c55416e69e525ddc0b38c22235ec1569)
1*3a7cf181SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*3a7cf181SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3a7cf181SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3a7cf181SAndrew Rist  * distributed with this work for additional information
6*3a7cf181SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3a7cf181SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3a7cf181SAndrew Rist  * "License"); you may not use this file except in compliance
9*3a7cf181SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*3a7cf181SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*3a7cf181SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3a7cf181SAndrew Rist  * software distributed under the License is distributed on an
15*3a7cf181SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3a7cf181SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3a7cf181SAndrew Rist  * specific language governing permissions and limitations
18*3a7cf181SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*3a7cf181SAndrew Rist  *************************************************************/
21*3a7cf181SAndrew Rist 
22*3a7cf181SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_configmgr.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
28cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
29cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
30cdf0e10cSrcweir #include "com/sun/star/uno/Sequence.hxx"
31cdf0e10cSrcweir #include "com/sun/star/uno/Type.hxx"
32cdf0e10cSrcweir #include "com/sun/star/uno/TypeClass.hpp"
33cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
34cdf0e10cSrcweir #include "cppu/unotype.hxx"
35cdf0e10cSrcweir #include "osl/diagnose.h"
36cdf0e10cSrcweir #include "rtl/string.h"
37cdf0e10cSrcweir #include "rtl/ustring.h"
38cdf0e10cSrcweir #include "rtl/ustring.hxx"
39cdf0e10cSrcweir #include "sal/types.h"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include "type.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace configmgr {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace {
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace css = com::sun::star;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
isListType(Type type)51cdf0e10cSrcweir bool isListType(Type type) {
52cdf0e10cSrcweir     return type >= TYPE_BOOLEAN_LIST;
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
elementType(Type type)55cdf0e10cSrcweir Type elementType(Type type) {
56cdf0e10cSrcweir     switch (type) {
57cdf0e10cSrcweir     case TYPE_BOOLEAN_LIST:
58cdf0e10cSrcweir         return TYPE_BOOLEAN;
59cdf0e10cSrcweir     case TYPE_SHORT_LIST:
60cdf0e10cSrcweir         return TYPE_SHORT;
61cdf0e10cSrcweir     case TYPE_INT_LIST:
62cdf0e10cSrcweir         return TYPE_INT;
63cdf0e10cSrcweir     case TYPE_LONG_LIST:
64cdf0e10cSrcweir         return TYPE_LONG;
65cdf0e10cSrcweir     case TYPE_DOUBLE_LIST:
66cdf0e10cSrcweir         return TYPE_DOUBLE;
67cdf0e10cSrcweir     case TYPE_STRING_LIST:
68cdf0e10cSrcweir         return TYPE_STRING;
69cdf0e10cSrcweir     case TYPE_HEXBINARY_LIST:
70cdf0e10cSrcweir         return TYPE_HEXBINARY;
71cdf0e10cSrcweir     default:
72cdf0e10cSrcweir         OSL_ASSERT(false);
73cdf0e10cSrcweir         throw css::uno::RuntimeException(
74cdf0e10cSrcweir             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
75cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
mapType(Type type)79cdf0e10cSrcweir css::uno::Type mapType(Type type) {
80cdf0e10cSrcweir     switch (type) {
81cdf0e10cSrcweir     case TYPE_ANY:
82cdf0e10cSrcweir         return cppu::UnoType< css::uno::Any >::get();
83cdf0e10cSrcweir     case TYPE_BOOLEAN:
84cdf0e10cSrcweir         return cppu::UnoType< sal_Bool >::get();
85cdf0e10cSrcweir     case TYPE_SHORT:
86cdf0e10cSrcweir         return cppu::UnoType< sal_Int16 >::get();
87cdf0e10cSrcweir     case TYPE_INT:
88cdf0e10cSrcweir         return cppu::UnoType< sal_Int32 >::get();
89cdf0e10cSrcweir     case TYPE_LONG:
90cdf0e10cSrcweir         return cppu::UnoType< sal_Int64 >::get();
91cdf0e10cSrcweir     case TYPE_DOUBLE:
92cdf0e10cSrcweir         return cppu::UnoType< double >::get();
93cdf0e10cSrcweir     case TYPE_STRING:
94cdf0e10cSrcweir         return cppu::UnoType< rtl::OUString >::get();
95cdf0e10cSrcweir     case TYPE_HEXBINARY:
96cdf0e10cSrcweir         return cppu::UnoType< css::uno::Sequence< sal_Int8 > >::get();
97cdf0e10cSrcweir     case TYPE_BOOLEAN_LIST:
98cdf0e10cSrcweir         return cppu::UnoType< css::uno::Sequence< sal_Bool > >::get();
99cdf0e10cSrcweir     case TYPE_SHORT_LIST:
100cdf0e10cSrcweir         return cppu::UnoType< css::uno::Sequence< sal_Int16 > >::get();
101cdf0e10cSrcweir     case TYPE_INT_LIST:
102cdf0e10cSrcweir         return cppu::UnoType< css::uno::Sequence< sal_Int32 > >::get();
103cdf0e10cSrcweir     case TYPE_LONG_LIST:
104cdf0e10cSrcweir         return cppu::UnoType< css::uno::Sequence< sal_Int64 > >::get();
105cdf0e10cSrcweir     case TYPE_DOUBLE_LIST:
106cdf0e10cSrcweir         return cppu::UnoType< css::uno::Sequence< double > >::get();
107cdf0e10cSrcweir     case TYPE_STRING_LIST:
108cdf0e10cSrcweir         return cppu::UnoType< css::uno::Sequence< rtl::OUString > >::get();
109cdf0e10cSrcweir     case TYPE_HEXBINARY_LIST:
110cdf0e10cSrcweir         return cppu::UnoType<
111cdf0e10cSrcweir             css::uno::Sequence< css::uno::Sequence< sal_Int8 > > >::get();
112cdf0e10cSrcweir     default:
113cdf0e10cSrcweir         OSL_ASSERT(false);
114cdf0e10cSrcweir         throw css::uno::RuntimeException(
115cdf0e10cSrcweir             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
116cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
getDynamicType(css::uno::Any const & value)120cdf0e10cSrcweir Type getDynamicType(css::uno::Any const & value) {
121cdf0e10cSrcweir     switch (value.getValueType().getTypeClass()) {
122cdf0e10cSrcweir     case css::uno::TypeClass_VOID:
123cdf0e10cSrcweir         return TYPE_NIL;
124cdf0e10cSrcweir     case css::uno::TypeClass_BOOLEAN:
125cdf0e10cSrcweir         return TYPE_BOOLEAN;
126cdf0e10cSrcweir     case css::uno::TypeClass_BYTE:
127cdf0e10cSrcweir         return TYPE_SHORT;
128cdf0e10cSrcweir     case css::uno::TypeClass_SHORT:
129cdf0e10cSrcweir         return TYPE_SHORT;
130cdf0e10cSrcweir     case css::uno::TypeClass_UNSIGNED_SHORT:
131cdf0e10cSrcweir         return value.has< sal_Int16 >() ? TYPE_SHORT : TYPE_INT;
132cdf0e10cSrcweir     case css::uno::TypeClass_LONG:
133cdf0e10cSrcweir         return TYPE_INT;
134cdf0e10cSrcweir     case css::uno::TypeClass_UNSIGNED_LONG:
135cdf0e10cSrcweir         return value.has< sal_Int32 >() ? TYPE_INT : TYPE_LONG;
136cdf0e10cSrcweir     case css::uno::TypeClass_HYPER:
137cdf0e10cSrcweir         return TYPE_LONG;
138cdf0e10cSrcweir     case css::uno::TypeClass_UNSIGNED_HYPER:
139cdf0e10cSrcweir         return value.has< sal_Int64 >() ? TYPE_LONG : TYPE_ERROR;
140cdf0e10cSrcweir     case css::uno::TypeClass_FLOAT:
141cdf0e10cSrcweir     case css::uno::TypeClass_DOUBLE:
142cdf0e10cSrcweir         return TYPE_DOUBLE;
143cdf0e10cSrcweir     case css::uno::TypeClass_STRING:
144cdf0e10cSrcweir         return TYPE_STRING;
145cdf0e10cSrcweir     case css::uno::TypeClass_SEQUENCE: //TODO
146cdf0e10cSrcweir         {
147cdf0e10cSrcweir             rtl::OUString name(value.getValueType().getTypeName());
148cdf0e10cSrcweir             if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]byte"))) {
149cdf0e10cSrcweir                 return TYPE_HEXBINARY;
150cdf0e10cSrcweir             } else if (name.equalsAsciiL(
151cdf0e10cSrcweir                            RTL_CONSTASCII_STRINGPARAM("[]boolean")))
152cdf0e10cSrcweir             {
153cdf0e10cSrcweir                 return TYPE_BOOLEAN_LIST;
154cdf0e10cSrcweir             } else if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]short")))
155cdf0e10cSrcweir             {
156cdf0e10cSrcweir                 return TYPE_SHORT_LIST;
157cdf0e10cSrcweir             } else if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]long")))
158cdf0e10cSrcweir             {
159cdf0e10cSrcweir                 return TYPE_INT_LIST;
160cdf0e10cSrcweir             } else if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]hyper")))
161cdf0e10cSrcweir             {
162cdf0e10cSrcweir                 return TYPE_LONG_LIST;
163cdf0e10cSrcweir             } else if (name.equalsAsciiL(
164cdf0e10cSrcweir                            RTL_CONSTASCII_STRINGPARAM("[]double")))
165cdf0e10cSrcweir             {
166cdf0e10cSrcweir                 return TYPE_DOUBLE_LIST;
167cdf0e10cSrcweir             } else if (name.equalsAsciiL(
168cdf0e10cSrcweir                            RTL_CONSTASCII_STRINGPARAM("[]string")))
169cdf0e10cSrcweir             {
170cdf0e10cSrcweir                 return TYPE_STRING_LIST;
171cdf0e10cSrcweir             } else if (name.equalsAsciiL(
172cdf0e10cSrcweir                            RTL_CONSTASCII_STRINGPARAM("[][]byte")))
173cdf0e10cSrcweir             {
174cdf0e10cSrcweir                 return TYPE_HEXBINARY_LIST;
175cdf0e10cSrcweir             }
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir         // fall through
178cdf0e10cSrcweir     default:
179cdf0e10cSrcweir         return TYPE_ERROR;
180cdf0e10cSrcweir     }
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir }
184