summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-12-12 17:00:50 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-12-12 17:04:47 +0100
commitd79b96cf6564187c96f5a1451ca98e2c93adee77 (patch)
treed3cedc2a45b77e4e2e0109b62d359afca94f7a78
parent7a85674c93150d6f5a59e998158909365b47d761 (diff)
css::uno::Sequence ctor with initializer_list
(though LIBO_INTERNAL_ONLY, as it needs C++11, so cannot in general be used in URE client code; I think it's better to not offer it outside LO at all, than based on a feature-check macro, and thus catch accidental misuses of it via CppunitTest_odk_checkapi) ...plus adapting binaryurp/ to use the new feature Change-Id: I9a88a0e9eac5daf72896470e8b6a1deb1a6fc88f
-rw-r--r--binaryurp/qa/test-unmarshal.cxx42
-rw-r--r--binaryurp/source/bridgefactory.cxx3
-rw-r--r--include/com/sun/star/uno/Sequence.h14
-rw-r--r--include/com/sun/star/uno/Sequence.hxx11
4 files changed, 43 insertions, 27 deletions
diff --git a/binaryurp/qa/test-unmarshal.cxx b/binaryurp/qa/test-unmarshal.cxx
index 759b120a2d20..13ab9f6f99e7 100644
--- a/binaryurp/qa/test-unmarshal.cxx
+++ b/binaryurp/qa/test-unmarshal.cxx
@@ -50,20 +50,15 @@ private:
void Test::testTypeOfBooleanSequence() {
binaryurp::ReaderState state;
- css::uno::Sequence< sal_Int8 > buf(13);
- buf[0] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(20 | 0x80)); // sequence type | cache flag
- buf[1] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore >> 8));
- buf[2] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore & 0xFF));
- buf[3] = RTL_CONSTASCII_LENGTH("[]boolean");
- buf[4] = '[';
- buf[5] = ']';
- buf[6] = 'b';
- buf[7] = 'o';
- buf[8] = 'o';
- buf[9] = 'l';
- buf[10] = 'e';
- buf[11] = 'a';
- buf[12] = 'n';
+ css::uno::Sequence<sal_Int8> buf{
+ static_cast<sal_Int8>(static_cast<sal_uInt8>(20 | 0x80)),
+ // sequence type | cache flag
+ static_cast<sal_Int8>(
+ static_cast<sal_uInt8>(binaryurp::cache::ignore >> 8)),
+ static_cast<sal_Int8>(
+ static_cast<sal_uInt8>(binaryurp::cache::ignore & 0xFF)),
+ RTL_CONSTASCII_LENGTH("[]boolean"),
+ '[', ']', 'b', 'o', 'o', 'l', 'e', 'a', 'n' };
binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
css::uno::TypeDescription t(m.readType());
CPPUNIT_ASSERT(
@@ -75,17 +70,14 @@ void Test::testTypeOfBooleanSequence() {
void Test::testTypeOfVoidSequence() {
binaryurp::ReaderState state;
- css::uno::Sequence< sal_Int8 > buf(10);
- buf[0] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(20 | 0x80)); // sequence type | cache flag
- buf[1] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore >> 8));
- buf[2] = static_cast< sal_Int8 >(static_cast< sal_uInt8 >(binaryurp::cache::ignore & 0xFF));
- buf[3] = RTL_CONSTASCII_LENGTH("[]void");
- buf[4] = '[';
- buf[5] = ']';
- buf[6] = 'v';
- buf[7] = 'o';
- buf[8] = 'i';
- buf[9] = 'd';
+ css::uno::Sequence<sal_Int8> buf{
+ static_cast<sal_Int8>(static_cast<sal_uInt8>(20 | 0x80)),
+ // sequence type | cache flag
+ static_cast<sal_Int8>(
+ static_cast<sal_uInt8>(binaryurp::cache::ignore >> 8)),
+ static_cast<sal_Int8>(
+ static_cast<sal_uInt8>(binaryurp::cache::ignore & 0xFF)),
+ RTL_CONSTASCII_LENGTH("[]void"), '[', ']', 'v', 'o', 'i', 'd' };
binaryurp::Unmarshal m(rtl::Reference< binaryurp::Bridge >(), state, buf);
try {
m.readType();
diff --git a/binaryurp/source/bridgefactory.cxx b/binaryurp/source/bridgefactory.cxx
index 6b8994dbb152..c9d0a04259eb 100644
--- a/binaryurp/source/bridgefactory.cxx
+++ b/binaryurp/source/bridgefactory.cxx
@@ -52,8 +52,7 @@ OUString BridgeFactory::static_getImplementationName() {
css::uno::Sequence< OUString >
BridgeFactory::static_getSupportedServiceNames() {
- OUString name("com.sun.star.bridge.BridgeFactory");
- return css::uno::Sequence< OUString >(&name, 1);
+ return css::uno::Sequence<OUString>{ "com.sun.star.bridge.BridgeFactory" };
}
void BridgeFactory::removeBridge(
diff --git a/include/com/sun/star/uno/Sequence.h b/include/com/sun/star/uno/Sequence.h
index fa2aa96f3fc9..21e3e9df6156 100644
--- a/include/com/sun/star/uno/Sequence.h
+++ b/include/com/sun/star/uno/Sequence.h
@@ -26,6 +26,10 @@
#include <new>
+#if defined LIBO_INTERNAL_ONLY
+#include <initializer_list>
+#endif
+
namespace rtl
{
class ByteSequence;
@@ -109,6 +113,16 @@ public:
*/
inline explicit Sequence( sal_Int32 len );
+#if defined LIBO_INTERNAL_ONLY
+ /** Create a sequence with the given elements.
+
+ @param init an initializer_list
+
+ @since LibreOffice 4.5
+ */
+ inline Sequence(std::initializer_list<E> init);
+#endif
+
/** Destructor: Releases sequence handle. Last handle will destruct
elements and free memory.
*/
diff --git a/include/com/sun/star/uno/Sequence.hxx b/include/com/sun/star/uno/Sequence.hxx
index 1ee59aebac45..dce2609c2d77 100644
--- a/include/com/sun/star/uno/Sequence.hxx
+++ b/include/com/sun/star/uno/Sequence.hxx
@@ -92,6 +92,17 @@ inline Sequence< E >::Sequence( sal_Int32 len )
throw ::std::bad_alloc();
}
+#if defined LIBO_INTERNAL_ONLY
+template<typename E> Sequence<E>::Sequence(std::initializer_list<E> init) {
+ if (!uno_type_sequence_construct(
+ &_pSequence, cppu::getTypeFavourUnsigned(this).getTypeLibType(),
+ const_cast<E *>(init.begin()), init.size(), cpp_acquire))
+ {
+ throw std::bad_alloc();
+ }
+}
+#endif
+
template< class E >
inline Sequence< E >::~Sequence()
{