Kaydet (Commit) 2e7b8067 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Some clean-up

Change-Id: I6a46af4e6ba42f1c104662e7a035b7ecfc404752
Reviewed-on: https://gerrit.libreoffice.org/30111Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 5034914c
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* except in compliance with the License. You may obtain a copy of * except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#ifndef INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX #ifndef INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
#define INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX #define INCLUDED_CPPUHELPER_PROPTYPEHLP_HXX
...@@ -26,13 +27,6 @@ ...@@ -26,13 +27,6 @@
namespace cppu namespace cppu
{ {
/** Converts the value stored in an any to a concrete C++ type.
The function does the same as the operator >>= () at the
Any class, except that it throws an IllegalArgumentException in case of
failures (the value cannot be extracted without data loss )
@exception css::lang::IllegalArgumentException when the type could not be converted.
*/
template < class target > template < class target >
inline void SAL_CALL convertPropertyValue( target &value , const css::uno::Any & a) inline void SAL_CALL convertPropertyValue( target &value , const css::uno::Any & a)
{ {
...@@ -42,48 +36,38 @@ inline void SAL_CALL convertPropertyValue( target &value , const css::uno::Any ...@@ -42,48 +36,38 @@ inline void SAL_CALL convertPropertyValue( target &value , const css::uno::Any
} }
} }
/**
conversion of basic types
*/
inline void SAL_CALL convertPropertyValue( sal_Bool & b , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_Bool & b , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= b) ) {
switch( a.getValueType().getTypeClass() ) {
if( css::uno::TypeClass_LONG == tc ) { case css::uno::TypeClass_BYTE:
sal_Int32 i32 = 0; b = a.get<sal_Int8>() != 0;
a >>= i32; break;
b = i32 != 0; case css::uno::TypeClass_SHORT:
} b = a.get<sal_Int16>() != 0;
else if ( css::uno::TypeClass_CHAR == tc ) { break;
sal_Unicode c = *static_cast<sal_Unicode const *>(a.getValue()); case css::uno::TypeClass_UNSIGNED_SHORT:
b = c != 0; {
} sal_uInt16 i16 = 0;
else if ( css::uno::TypeClass_SHORT == tc ) { a >>= i16;
sal_Int16 i16 = 0; b = i16 != 0;
a >>= i16; break;
b = i16 != 0; }
} case css::uno::TypeClass_LONG:
else if ( css::uno::TypeClass_BOOLEAN == tc ) { b = a.get<sal_Int32>() != 0;
a >>= b; break;
} case css::uno::TypeClass_UNSIGNED_LONG:
else if ( css::uno::TypeClass_BYTE == tc ) { b = a.get<sal_uInt32>() != 0;
sal_Int8 i8 = 0; break;
a >>= i8; case css::uno::TypeClass_CHAR:
b = i8 != 0; {
} sal_Unicode c = *static_cast<sal_Unicode const *>(a.getValue());
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) { b = c != 0;
sal_uInt16 i16 = 0; break;
a >>= i16; }
b = i16 != 0; default:
} throw css::lang::IllegalArgumentException();
else if ( css::uno::TypeClass_UNSIGNED_LONG == tc ) { }
sal_uInt32 i32 = 0;
a >>= i32;
b = i32 != 0;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
...@@ -95,410 +79,202 @@ void convertPropertyValue(bool & target, css::uno::Any const & source) { ...@@ -95,410 +79,202 @@ void convertPropertyValue(bool & target, css::uno::Any const & source) {
inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_Int64 & i , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= i) ) {
switch( a.getValueType().getTypeClass() ) {
if( css::uno::TypeClass_HYPER == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= i; i = static_cast<sal_Int64>(a.get<bool>());
} break;
else if( css::uno::TypeClass_UNSIGNED_HYPER == tc ) { case css::uno::TypeClass_CHAR:
sal_uInt64 i64 = 0; {
a >>= i64; sal_Unicode c;
i = ( sal_Int64 ) i64; c = *static_cast<sal_Unicode const *>(a.getValue());
} i = ( sal_Int64 ) c;
else if( css::uno::TypeClass_LONG == tc ) { break;
sal_Int32 i32 = 0; }
a >>= i32; default:
i = ( sal_Int64 )i32; throw css::lang::IllegalArgumentException();
} }
else if ( css::uno::TypeClass_CHAR == tc ) {
sal_Unicode c;
c = *static_cast<sal_Unicode const *>(a.getValue());
i = ( sal_Int64 ) c;
}
else if ( css::uno::TypeClass_SHORT == tc ) {
sal_Int16 i16 = 0;
a >>= i16;
i = ( sal_Int64 ) i16;
}
else if ( css::uno::TypeClass_BOOLEAN == tc ) {
bool b;
a >>= b;
i = ( sal_Int64 ) b;
}
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8 = 0;
a >>= i8;
i = ( sal_Int64 ) i8;
}
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) {
sal_uInt16 i16 = 0;
a >>= i16;
i = ( sal_Int64 ) i16;
}
else if ( css::uno::TypeClass_UNSIGNED_LONG == tc ) {
sal_uInt32 i32 = 0;
a >>= i32;
i = ( sal_Int64 ) i32;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_uInt64 & i , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= i) ) {
switch( a.getValueType().getTypeClass() ) {
if( css::uno::TypeClass_UNSIGNED_HYPER == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= i; i = static_cast<sal_uInt64>(a.get<bool>());
} break;
if( css::uno::TypeClass_HYPER == tc ) { case css::uno::TypeClass_CHAR:
sal_Int64 i64; {
a >>= i64; sal_Unicode c;
i = ( sal_uInt64 ) i64; c = *static_cast<sal_Unicode const *>(a.getValue());
} i = ( sal_uInt64 ) c;
else if( css::uno::TypeClass_LONG == tc ) { break;
sal_Int32 i32; }
a >>= i32; default:
i = ( sal_uInt64 )i32; throw css::lang::IllegalArgumentException();
} }
else if ( css::uno::TypeClass_CHAR == tc ) {
sal_Unicode c;
c = *static_cast<sal_Unicode const *>(a.getValue());
i = ( sal_uInt64 ) c;
}
else if ( css::uno::TypeClass_SHORT == tc ) {
sal_Int16 i16;
a >>= i16;
i = ( sal_uInt64 ) i16;
}
else if ( css::uno::TypeClass_BOOLEAN == tc ) {
bool b;
a >>= b;
i = ( sal_uInt64 ) b;
}
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8;
a >>= i8;
i = ( sal_uInt64 ) i8;
}
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) {
sal_uInt16 i16;
a >>= i16;
i = ( sal_uInt64 ) i16;
}
else if ( css::uno::TypeClass_UNSIGNED_LONG == tc ) {
sal_uInt32 i32;
a >>= i32;
i = ( sal_uInt64 ) i32;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
// the basic types
// sal_Int32
inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_Int32 & i , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= i) ) {
switch( a.getValueType().getTypeClass() ) {
if( css::uno::TypeClass_LONG == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= i; i = static_cast<sal_Int32>(a.get<bool>());
} break;
else if ( css::uno::TypeClass_CHAR == tc ) { case css::uno::TypeClass_CHAR:
sal_Unicode c; {
c = *static_cast<sal_Unicode const *>(a.getValue()); sal_Unicode c;
i = ( sal_Int32 ) c; c = *static_cast<sal_Unicode const *>(a.getValue());
} i = ( sal_Int32 ) c;
else if ( css::uno::TypeClass_SHORT == tc ) { break;
sal_Int16 i16 = 0; }
a >>= i16; default:
i = ( sal_Int32 ) i16; throw css::lang::IllegalArgumentException();
} }
else if ( css::uno::TypeClass_BOOLEAN == tc ) {
bool b;
a >>= b;
i = ( sal_Int32 ) b;
}
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8 = 0;
a >>= i8;
i = ( sal_Int32 ) i8;
}
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) {
sal_uInt16 i16 = 0;
a >>= i16;
i = ( sal_Int32 ) i16;
}
else if ( css::uno::TypeClass_UNSIGNED_LONG == tc ) {
sal_uInt32 i32 = 0;
a >>= i32;
i = ( sal_Int32 ) i32;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_uInt32 & i , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= i) ) {
switch( a.getValueType().getTypeClass() ) {
if ( css::uno::TypeClass_UNSIGNED_LONG == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= i; i = static_cast<sal_uInt32>(a.get<bool>());
} break;
else if( css::uno::TypeClass_LONG == tc ) { case css::uno::TypeClass_CHAR:
sal_Int32 i32; {
a >>= i32; sal_Unicode c;
i = (sal_uInt32 ) i32; c = *static_cast<sal_Unicode const *>(a.getValue());
} i = ( sal_uInt32 ) c;
else if ( css::uno::TypeClass_CHAR == tc ) { break;
sal_Unicode c; }
c = *static_cast<sal_Unicode const *>(a.getValue()); default:
i = ( sal_uInt32 ) c; throw css::lang::IllegalArgumentException();
} }
else if ( css::uno::TypeClass_SHORT == tc ) {
sal_Int16 i16;
a >>= i16;
i = ( sal_uInt32 ) i16;
}
else if ( css::uno::TypeClass_BOOLEAN == tc ) {
bool b;
a >>= b;
i = ( sal_uInt32 ) b;
}
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8;
a >>= i8;
i = ( sal_uInt32 ) i8;
}
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) {
sal_uInt16 i16;
a >>= i16;
i = ( sal_uInt32 ) i16;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_Int16 & i , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= i) ) {
switch( a.getValueType().getTypeClass() ) {
if ( css::uno::TypeClass_SHORT == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= i; i = static_cast<sal_Int16>(a.get<bool>());
} break;
else if ( css::uno::TypeClass_CHAR == tc ) { case css::uno::TypeClass_CHAR:
sal_Unicode c; {
c = *static_cast<sal_Unicode const *>(a.getValue()); sal_Unicode c;
i = ( sal_Int16 ) c; c = *static_cast<sal_Unicode const *>(a.getValue());
} i = ( sal_Int16 ) c;
else if ( css::uno::TypeClass_BOOLEAN == tc ) { break;
bool b; }
a >>= b; default:
i = ( sal_Int16 ) b; throw css::lang::IllegalArgumentException();
} }
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8 = 0;
a >>= i8;
i = ( sal_Int16 ) i8;
}
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) {
sal_uInt16 i16 = 0;
a >>= i16;
i = ( sal_Int16 ) i16;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_uInt16 & i , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= i) ) {
switch( a.getValueType().getTypeClass() ) {
if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= i; i = static_cast<sal_uInt16>(a.get<bool>());
} break;
else if ( css::uno::TypeClass_CHAR == tc ) { case css::uno::TypeClass_CHAR:
sal_Unicode c; {
c = *static_cast<sal_Unicode const *>(a.getValue()); sal_Unicode c;
i = ( sal_Int16 ) c; c = *static_cast<sal_Unicode const *>(a.getValue());
} i = ( sal_Int16 ) c;
else if ( css::uno::TypeClass_BOOLEAN == tc ) { break;
bool b; }
a >>= b; default:
i = ( sal_Int16 ) b; throw css::lang::IllegalArgumentException();
} }
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8 = 0;
a >>= i8;
i = ( sal_Int16 ) i8;
}
else if ( css::uno::TypeClass_SHORT == tc ) {
sal_Int16 i16 = 0;
a >>= i16;
i = ( sal_Int16 ) i16;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const css::uno::Any & a ) inline void SAL_CALL convertPropertyValue( sal_Int8 & i , const css::uno::Any & a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= i) ) {
switch( a.getValueType().getTypeClass() ) {
if ( css::uno::TypeClass_BYTE == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= i; i = static_cast<sal_Int8>(a.get<bool>());
} break;
else if ( css::uno::TypeClass_BOOLEAN == tc ) { default:
bool b; throw css::lang::IllegalArgumentException();
a >>= b; }
i = ( sal_Int8 ) b;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( float &f , const css::uno::Any &a ) inline void SAL_CALL convertPropertyValue( float &f , const css::uno::Any &a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= f) ) {
switch( a.getValueType().getTypeClass() ) {
if ( css::uno::TypeClass_FLOAT == tc ) { case css::uno::TypeClass_BOOLEAN:
a >>= f; f = static_cast<float>(a.get<bool>());
} break;
else if( css::uno::TypeClass_DOUBLE == tc ) { case css::uno::TypeClass_LONG:
double d = 0; f = static_cast<float>(a.get<sal_Int32>());
a >>= d; break;
f = ( float ) d; case css::uno::TypeClass_UNSIGNED_LONG:
} f = static_cast<float>(a.get<sal_uInt32>());
else if( css::uno::TypeClass_HYPER == tc ) { break;
sal_Int64 i64 = 0; case css::uno::TypeClass_HYPER:
a >>= i64; f = static_cast<float>(a.get<sal_Int64>());
f = ( float ) i64; break;
} case css::uno::TypeClass_UNSIGNED_HYPER:
else if( css::uno::TypeClass_UNSIGNED_HYPER == tc ) { f = static_cast<float>(a.get<sal_uInt64>());
sal_uInt64 i64 = 0; break;
a >>= i64; case css::uno::TypeClass_DOUBLE:
f = ( float ) i64; f = static_cast<float>(a.get<double>());
} break;
else if( css::uno::TypeClass_LONG == tc ) { case css::uno::TypeClass_CHAR:
sal_Int32 i32 = 0; {
a >>= i32; sal_Unicode c;
f = ( float )i32; c = *static_cast<sal_Unicode const *>(a.getValue());
} f = ( float ) c;
else if ( css::uno::TypeClass_CHAR == tc ) { break;
sal_Unicode c; }
c = *static_cast<sal_Unicode const *>(a.getValue()); default:
f = ( float ) c; throw css::lang::IllegalArgumentException();
} }
else if ( css::uno::TypeClass_SHORT == tc ) {
sal_Int16 i16 = 0;
a >>= i16;
f = ( float ) i16;
}
else if ( css::uno::TypeClass_BOOLEAN == tc ) {
bool b;
a >>= b;
f = ( float ) b;
}
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8 = 0;
a >>= i8;
f = ( float ) i8;
}
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) {
sal_uInt16 i16 = 0;
a >>= i16;
f = ( float ) i16;
}
else if ( css::uno::TypeClass_UNSIGNED_LONG == tc ) {
sal_uInt32 i32 = 0;
a >>= i32;
f = ( float ) i32;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( double &d , const css::uno::Any &a ) inline void SAL_CALL convertPropertyValue( double &d , const css::uno::Any &a )
{ {
const enum css::uno::TypeClass tc = a.getValueType().getTypeClass(); if( !(a >>= d) ) {
switch( a.getValueType().getTypeClass() ) {
if( css::uno::TypeClass_DOUBLE == tc ) { case css::uno::TypeClass_BOOLEAN:
float f; d = static_cast<double>(a.get<bool>());
a >>= f; break;
d = ( double ) f; case css::uno::TypeClass_HYPER:
} d = static_cast<double>(a.get<sal_Int64>());
else if ( css::uno::TypeClass_FLOAT == tc ) { break;
float f; case css::uno::TypeClass_UNSIGNED_HYPER:
a >>= f; d = static_cast<double>(a.get<sal_uInt64>());
d = (double) f; break;
} case css::uno::TypeClass_CHAR:
else if( css::uno::TypeClass_HYPER == tc ) { {
sal_Int64 i64; sal_Unicode c;
a >>= i64; c = *static_cast<sal_Unicode const *>(a.getValue());
d = (double) i64; d = (double) c;
} break;
else if( css::uno::TypeClass_UNSIGNED_HYPER == tc ) { }
sal_uInt64 i64 = 0; default:
a >>= i64; throw css::lang::IllegalArgumentException();
d = (double) i64; }
}
else if( css::uno::TypeClass_LONG == tc ) {
sal_Int32 i32;
a >>= i32;
d = (double)i32;
}
else if ( css::uno::TypeClass_CHAR == tc ) {
sal_Unicode c;
c = *static_cast<sal_Unicode const *>(a.getValue());
d = (double) c;
}
else if ( css::uno::TypeClass_SHORT == tc ) {
sal_Int16 i16;
a >>= i16;
d = (double) i16;
}
else if ( css::uno::TypeClass_BOOLEAN == tc ) {
bool b;
a >>= b;
d = (double) b;
}
else if ( css::uno::TypeClass_BYTE == tc ) {
sal_Int8 i8;
a >>= i8;
d = (double) i8;
}
else if ( css::uno::TypeClass_UNSIGNED_SHORT == tc ) {
sal_uInt16 i16;
a >>= i16;
d = (double) i16;
}
else if ( css::uno::TypeClass_UNSIGNED_LONG == tc ) {
sal_uInt32 i32;
a >>= i32;
d = (double) i32;
}
else {
throw css::lang::IllegalArgumentException();
} }
} }
inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const css::uno::Any &a ) inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const css::uno::Any &a )
{ {
if( css::uno::TypeClass_STRING == a.getValueType().getTypeClass() ) { if( !(a >>= ow) ) {
a >>= ow;
}
else {
throw css::lang::IllegalArgumentException(); throw css::lang::IllegalArgumentException();
} }
} }
...@@ -507,5 +283,4 @@ inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const css::uno: ...@@ -507,5 +283,4 @@ inline void SAL_CALL convertPropertyValue( ::rtl::OUString &ow , const css::uno:
#endif #endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment