bump product version to 6.3.0.0.beta1
[LibreOffice.git] / configmgr / source / type.cxx
blobab84fcb9c3bb10554ac6dea95042e7cbb309b6cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
22 #include <cassert>
24 #include <com/sun/star/uno/Any.hxx>
25 #include <com/sun/star/uno/RuntimeException.hpp>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/uno/Type.hxx>
28 #include <com/sun/star/uno/TypeClass.hpp>
29 #include <com/sun/star/uno/XInterface.hpp>
30 #include <cppu/unotype.hxx>
31 #include <rtl/string.h>
32 #include <rtl/ustring.h>
33 #include <rtl/ustring.hxx>
34 #include <sal/types.h>
36 #include "type.hxx"
38 namespace configmgr {
40 bool isListType(Type type) {
41 return type >= TYPE_BOOLEAN_LIST;
44 Type elementType(Type type) {
45 switch (type) {
46 case TYPE_BOOLEAN_LIST:
47 return TYPE_BOOLEAN;
48 case TYPE_SHORT_LIST:
49 return TYPE_SHORT;
50 case TYPE_INT_LIST:
51 return TYPE_INT;
52 case TYPE_LONG_LIST:
53 return TYPE_LONG;
54 case TYPE_DOUBLE_LIST:
55 return TYPE_DOUBLE;
56 case TYPE_STRING_LIST:
57 return TYPE_STRING;
58 case TYPE_HEXBINARY_LIST:
59 return TYPE_HEXBINARY;
60 default:
61 assert(false);
62 throw css::uno::RuntimeException("this cannot happen");
66 css::uno::Type const & mapType(Type type) {
67 switch (type) {
68 case TYPE_ANY:
69 return cppu::UnoType< css::uno::Any >::get();
70 case TYPE_BOOLEAN:
71 return cppu::UnoType< sal_Bool >::get();
72 case TYPE_SHORT:
73 return cppu::UnoType< sal_Int16 >::get();
74 case TYPE_INT:
75 return cppu::UnoType< sal_Int32 >::get();
76 case TYPE_LONG:
77 return cppu::UnoType< sal_Int64 >::get();
78 case TYPE_DOUBLE:
79 return cppu::UnoType< double >::get();
80 case TYPE_STRING:
81 return cppu::UnoType< OUString >::get();
82 case TYPE_HEXBINARY:
83 return cppu::UnoType< css::uno::Sequence< sal_Int8 > >::get();
84 case TYPE_BOOLEAN_LIST:
85 return cppu::UnoType< css::uno::Sequence< sal_Bool > >::get();
86 case TYPE_SHORT_LIST:
87 return cppu::UnoType< css::uno::Sequence< sal_Int16 > >::get();
88 case TYPE_INT_LIST:
89 return cppu::UnoType< css::uno::Sequence< sal_Int32 > >::get();
90 case TYPE_LONG_LIST:
91 return cppu::UnoType< css::uno::Sequence< sal_Int64 > >::get();
92 case TYPE_DOUBLE_LIST:
93 return cppu::UnoType< css::uno::Sequence< double > >::get();
94 case TYPE_STRING_LIST:
95 return cppu::UnoType< css::uno::Sequence< OUString > >::get();
96 case TYPE_HEXBINARY_LIST:
97 return cppu::UnoType<
98 css::uno::Sequence< css::uno::Sequence< sal_Int8 > > >::get();
99 default:
100 assert(false);
101 throw css::uno::RuntimeException("this cannot happen");
105 Type getDynamicType(css::uno::Any const & value) {
106 switch (value.getValueType().getTypeClass()) {
107 case css::uno::TypeClass_VOID:
108 return TYPE_NIL;
109 case css::uno::TypeClass_BOOLEAN:
110 return TYPE_BOOLEAN;
111 case css::uno::TypeClass_BYTE:
112 return TYPE_SHORT;
113 case css::uno::TypeClass_SHORT:
114 return TYPE_SHORT;
115 case css::uno::TypeClass_UNSIGNED_SHORT:
116 return value.has< sal_Int16 >() ? TYPE_SHORT : TYPE_INT;
117 case css::uno::TypeClass_LONG:
118 return TYPE_INT;
119 case css::uno::TypeClass_UNSIGNED_LONG:
120 return value.has< sal_Int32 >() ? TYPE_INT : TYPE_LONG;
121 case css::uno::TypeClass_HYPER:
122 return TYPE_LONG;
123 case css::uno::TypeClass_UNSIGNED_HYPER:
124 return value.has< sal_Int64 >() ? TYPE_LONG : TYPE_ERROR;
125 case css::uno::TypeClass_FLOAT:
126 case css::uno::TypeClass_DOUBLE:
127 return TYPE_DOUBLE;
128 case css::uno::TypeClass_STRING:
129 return TYPE_STRING;
130 case css::uno::TypeClass_SEQUENCE: //TODO
132 OUString name(value.getValueType().getTypeName());
133 if ( name == "[]byte" ) {
134 return TYPE_HEXBINARY;
135 } else if (name == "[]boolean")
137 return TYPE_BOOLEAN_LIST;
138 } else if ( name == "[]short" )
140 return TYPE_SHORT_LIST;
141 } else if ( name == "[]long" )
143 return TYPE_INT_LIST;
144 } else if ( name == "[]hyper" )
146 return TYPE_LONG_LIST;
147 } else if (name == "[]double")
149 return TYPE_DOUBLE_LIST;
150 } else if (name == "[]string")
152 return TYPE_STRING_LIST;
153 } else if (name == "[][]byte")
155 return TYPE_HEXBINARY_LIST;
158 [[fallthrough]];
159 default:
160 return TYPE_ERROR;
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */