merged tag ooo/DEV300_m102
[LibreOffice.git] / configmgr / source / type.cxx
blobe1b8a95859ef52cf9faecd66987869ab41df8bed
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include "precompiled_configmgr.hxx"
29 #include "sal/config.h"
31 #include "com/sun/star/uno/Any.hxx"
32 #include "com/sun/star/uno/Reference.hxx"
33 #include "com/sun/star/uno/RuntimeException.hpp"
34 #include "com/sun/star/uno/Sequence.hxx"
35 #include "com/sun/star/uno/Type.hxx"
36 #include "com/sun/star/uno/TypeClass.hpp"
37 #include "com/sun/star/uno/XInterface.hpp"
38 #include "cppu/unotype.hxx"
39 #include "osl/diagnose.h"
40 #include "rtl/string.h"
41 #include "rtl/ustring.h"
42 #include "rtl/ustring.hxx"
43 #include "sal/types.h"
45 #include "type.hxx"
47 namespace configmgr {
49 namespace {
51 namespace css = com::sun::star;
55 bool isListType(Type type) {
56 return type >= TYPE_BOOLEAN_LIST;
59 Type elementType(Type type) {
60 switch (type) {
61 case TYPE_BOOLEAN_LIST:
62 return TYPE_BOOLEAN;
63 case TYPE_SHORT_LIST:
64 return TYPE_SHORT;
65 case TYPE_INT_LIST:
66 return TYPE_INT;
67 case TYPE_LONG_LIST:
68 return TYPE_LONG;
69 case TYPE_DOUBLE_LIST:
70 return TYPE_DOUBLE;
71 case TYPE_STRING_LIST:
72 return TYPE_STRING;
73 case TYPE_HEXBINARY_LIST:
74 return TYPE_HEXBINARY;
75 default:
76 OSL_ASSERT(false);
77 throw css::uno::RuntimeException(
78 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
79 css::uno::Reference< css::uno::XInterface >());
83 css::uno::Type mapType(Type type) {
84 switch (type) {
85 case TYPE_ANY:
86 return cppu::UnoType< css::uno::Any >::get();
87 case TYPE_BOOLEAN:
88 return cppu::UnoType< sal_Bool >::get();
89 case TYPE_SHORT:
90 return cppu::UnoType< sal_Int16 >::get();
91 case TYPE_INT:
92 return cppu::UnoType< sal_Int32 >::get();
93 case TYPE_LONG:
94 return cppu::UnoType< sal_Int64 >::get();
95 case TYPE_DOUBLE:
96 return cppu::UnoType< double >::get();
97 case TYPE_STRING:
98 return cppu::UnoType< rtl::OUString >::get();
99 case TYPE_HEXBINARY:
100 return cppu::UnoType< css::uno::Sequence< sal_Int8 > >::get();
101 case TYPE_BOOLEAN_LIST:
102 return cppu::UnoType< css::uno::Sequence< sal_Bool > >::get();
103 case TYPE_SHORT_LIST:
104 return cppu::UnoType< css::uno::Sequence< sal_Int16 > >::get();
105 case TYPE_INT_LIST:
106 return cppu::UnoType< css::uno::Sequence< sal_Int32 > >::get();
107 case TYPE_LONG_LIST:
108 return cppu::UnoType< css::uno::Sequence< sal_Int64 > >::get();
109 case TYPE_DOUBLE_LIST:
110 return cppu::UnoType< css::uno::Sequence< double > >::get();
111 case TYPE_STRING_LIST:
112 return cppu::UnoType< css::uno::Sequence< rtl::OUString > >::get();
113 case TYPE_HEXBINARY_LIST:
114 return cppu::UnoType<
115 css::uno::Sequence< css::uno::Sequence< sal_Int8 > > >::get();
116 default:
117 OSL_ASSERT(false);
118 throw css::uno::RuntimeException(
119 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
120 css::uno::Reference< css::uno::XInterface >());
124 Type getDynamicType(css::uno::Any const & value) {
125 switch (value.getValueType().getTypeClass()) {
126 case css::uno::TypeClass_VOID:
127 return TYPE_NIL;
128 case css::uno::TypeClass_BOOLEAN:
129 return TYPE_BOOLEAN;
130 case css::uno::TypeClass_BYTE:
131 return TYPE_SHORT;
132 case css::uno::TypeClass_SHORT:
133 return TYPE_SHORT;
134 case css::uno::TypeClass_UNSIGNED_SHORT:
135 return value.has< sal_Int16 >() ? TYPE_SHORT : TYPE_INT;
136 case css::uno::TypeClass_LONG:
137 return TYPE_INT;
138 case css::uno::TypeClass_UNSIGNED_LONG:
139 return value.has< sal_Int32 >() ? TYPE_INT : TYPE_LONG;
140 case css::uno::TypeClass_HYPER:
141 return TYPE_LONG;
142 case css::uno::TypeClass_UNSIGNED_HYPER:
143 return value.has< sal_Int64 >() ? TYPE_LONG : TYPE_ERROR;
144 case css::uno::TypeClass_FLOAT:
145 case css::uno::TypeClass_DOUBLE:
146 return TYPE_DOUBLE;
147 case css::uno::TypeClass_STRING:
148 return TYPE_STRING;
149 case css::uno::TypeClass_SEQUENCE: //TODO
151 rtl::OUString name(value.getValueType().getTypeName());
152 if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]byte"))) {
153 return TYPE_HEXBINARY;
154 } else if (name.equalsAsciiL(
155 RTL_CONSTASCII_STRINGPARAM("[]boolean")))
157 return TYPE_BOOLEAN_LIST;
158 } else if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]short")))
160 return TYPE_SHORT_LIST;
161 } else if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]long")))
163 return TYPE_INT_LIST;
164 } else if (name.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]hyper")))
166 return TYPE_LONG_LIST;
167 } else if (name.equalsAsciiL(
168 RTL_CONSTASCII_STRINGPARAM("[]double")))
170 return TYPE_DOUBLE_LIST;
171 } else if (name.equalsAsciiL(
172 RTL_CONSTASCII_STRINGPARAM("[]string")))
174 return TYPE_STRING_LIST;
175 } else if (name.equalsAsciiL(
176 RTL_CONSTASCII_STRINGPARAM("[][]byte")))
178 return TYPE_HEXBINARY_LIST;
181 // fall through
182 default:
183 return TYPE_ERROR;