1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX 25 #define INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX 26 27 #include <com/sun/star/uno/Reference.hxx> 28 #include <com/sun/star/animations/XAnimationNode.hpp> 29 #include <com/sun/star/container/XEnumerationAccess.hpp> 30 #include <com/sun/star/container/XEnumeration.hpp> 31 32 #include <vector> 33 34 /* Declaration and definition of AnimationNode helper */ 35 36 namespace anim 37 { 38 // TODO(Q1): this could possibly be implemented with a somewhat 39 // more lightweight template, by having the actual worker receive 40 // only a function pointer, and a thin templated wrapper around 41 // that which converts member functions into that. 42 43 /** Apply given functor to every animation node child. 44 45 @param xNode 46 Parent node 47 48 @param rFunctor 49 Functor to apply. The functor must have an appropriate 50 operator()( const ::com::sun::star::uno::Reference< 51 ::com::sun::star::animations::XAnimationNode >& ) member. 52 53 @return true, if the functor was successfully applied to 54 all children, false otherwise. 55 */ for_each_childNode(const::com::sun::star::uno::Reference<::com::sun::star::animations::XAnimationNode> & xNode,Functor & rFunctor)56 template< typename Functor > inline bool for_each_childNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode, 57 Functor& rFunctor ) 58 { 59 try 60 { 61 // get an XEnumerationAccess to the children 62 ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumerationAccess > 63 xEnumerationAccess( xNode, 64 ::com::sun::star::uno::UNO_QUERY_THROW ); 65 ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > 66 xEnumeration( xEnumerationAccess->createEnumeration(), 67 ::com::sun::star::uno::UNO_QUERY_THROW ); 68 69 while( xEnumeration->hasMoreElements() ) 70 { 71 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > 72 xChildNode( xEnumeration->nextElement(), 73 ::com::sun::star::uno::UNO_QUERY_THROW ); 74 75 rFunctor( xChildNode ); 76 } 77 78 return true; 79 } 80 catch( ::com::sun::star::uno::Exception& ) 81 { 82 return false; 83 } 84 } 85 86 87 /** pushes the given node to the given vector and recursivly calls itself for each child node. 88 */ create_deep_vector(const::com::sun::star::uno::Reference<::com::sun::star::animations::XAnimationNode> & xNode,std::vector<::com::sun::star::uno::Reference<::com::sun::star::animations::XAnimationNode>> & rVector)89 inline void create_deep_vector( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode, 90 std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > >& rVector ) 91 { 92 rVector.push_back( xNode ); 93 94 try 95 { 96 // get an XEnumerationAccess to the children 97 ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumerationAccess > 98 xEnumerationAccess( xNode, 99 ::com::sun::star::uno::UNO_QUERY ); 100 101 if( xEnumerationAccess.is() ) 102 { 103 ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration > 104 xEnumeration( xEnumerationAccess->createEnumeration(), 105 ::com::sun::star::uno::UNO_QUERY ); 106 107 if( xEnumeration.is() ) 108 { 109 while( xEnumeration->hasMoreElements() ) 110 { 111 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > 112 xChildNode( xEnumeration->nextElement(), 113 ::com::sun::star::uno::UNO_QUERY_THROW ); 114 115 create_deep_vector( xChildNode, rVector ); 116 } 117 } 118 } 119 } 120 catch( ::com::sun::star::uno::Exception& ) 121 { 122 } 123 } 124 } 125 126 #endif /* INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX */ 127