LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/animations - animationnodehelper.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 15 27 55.6 %
Date: 2013-07-09 Functions: 1 5 20.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX
      21             : #define INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX
      22             : 
      23             : #include <com/sun/star/uno/Reference.hxx>
      24             : #include <com/sun/star/animations/XAnimationNode.hpp>
      25             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      26             : #include <com/sun/star/container/XEnumeration.hpp>
      27             : 
      28             : #include <vector>
      29             : 
      30             : /* Declaration and definition of AnimationNode helper */
      31             : 
      32             : namespace anim
      33             : {
      34             :     // TODO(Q1): this could possibly be implemented with a somewhat
      35             :     // more lightweight template, by having the actual worker receive
      36             :     // only a function pointer, and a thin templated wrapper around
      37             :     // that which converts member functions into that.
      38             : 
      39             :     /** Apply given functor to every animation node child.
      40             : 
      41             :         @param xNode
      42             :         Parent node
      43             : 
      44             :         @param rFunctor
      45             :         Functor to apply. The functor must have an appropriate
      46             :         operator()( const ::com::sun::star::uno::Reference<
      47             :         ::com::sun::star::animations::XAnimationNode >& ) member.
      48             : 
      49             :         @return true, if the functor was successfully applied to
      50             :         all children, false otherwise.
      51             :     */
      52           0 :     template< typename Functor > inline bool for_each_childNode( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >&    xNode,
      53             :                                                           Functor&                                                                                  rFunctor )
      54             :     {
      55             :         try
      56             :         {
      57             :             // get an XEnumerationAccess to the children
      58             :             ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumerationAccess >
      59             :                   xEnumerationAccess( xNode,
      60           0 :                                       ::com::sun::star::uno::UNO_QUERY_THROW );
      61             :             ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >
      62           0 :                   xEnumeration( xEnumerationAccess->createEnumeration(),
      63           0 :                                 ::com::sun::star::uno::UNO_QUERY_THROW );
      64             : 
      65           0 :             while( xEnumeration->hasMoreElements() )
      66             :             {
      67             :                 ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >
      68           0 :                       xChildNode( xEnumeration->nextElement(),
      69           0 :                                   ::com::sun::star::uno::UNO_QUERY_THROW );
      70             : 
      71           0 :                 rFunctor( xChildNode );
      72             :             }
      73             : 
      74           0 :             return true;
      75             :         }
      76           0 :         catch( ::com::sun::star::uno::Exception& )
      77             :         {
      78           0 :             return false;
      79             :         }
      80             :     }
      81             : 
      82             : 
      83             :     /** pushes the given node to the given vector and recursivly calls itself for each child node.
      84             :     */
      85           8 :     inline void create_deep_vector( const ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >& xNode,
      86             :                                 std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode > >& rVector )
      87             :     {
      88           8 :         rVector.push_back( xNode );
      89             : 
      90             :         try
      91             :         {
      92             :             // get an XEnumerationAccess to the children
      93             :             ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumerationAccess >
      94             :                   xEnumerationAccess( xNode,
      95           8 :                                       ::com::sun::star::uno::UNO_QUERY );
      96             : 
      97           8 :             if( xEnumerationAccess.is() )
      98             :             {
      99             :                 ::com::sun::star::uno::Reference< ::com::sun::star::container::XEnumeration >
     100           5 :                       xEnumeration( xEnumerationAccess->createEnumeration(),
     101           5 :                                     ::com::sun::star::uno::UNO_QUERY );
     102             : 
     103           5 :                 if( xEnumeration.is() )
     104             :                 {
     105          17 :                     while( xEnumeration->hasMoreElements() )
     106             :                     {
     107             :                         ::com::sun::star::uno::Reference< ::com::sun::star::animations::XAnimationNode >
     108           7 :                             xChildNode( xEnumeration->nextElement(),
     109           7 :                                         ::com::sun::star::uno::UNO_QUERY_THROW );
     110             : 
     111           7 :                         create_deep_vector( xChildNode, rVector );
     112           7 :                     }
     113           5 :                 }
     114           8 :             }
     115             :         }
     116           0 :         catch( ::com::sun::star::uno::Exception& )
     117             :         {
     118             :         }
     119           8 :     }
     120             : }
     121             : 
     122             : #endif /* INCLUDED_ANIMATIONS_ANIMATIONNODEHELPER_HXX */
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10