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_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX 25 #define INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX 26 27 #include "attributableshape.hxx" 28 #include "shapeattributelayer.hxx" 29 30 #include <boost/noncopyable.hpp> 31 32 namespace slideshow 33 { 34 namespace internal 35 { 36 /** Holds a ShapeAttributeLayer, together with the associated 37 Shape 38 39 Use this class to hold ShapeAttributeLayer objects the 40 RAII way. When this object gets deleted, it will 41 automatically revoke the attribute layer for the given 42 shape (this encapsulates the somewhat clumsy notification 43 process that is required for shape and attribute layer 44 interaction). 45 */ 46 class ShapeAttributeLayerHolder : private boost::noncopyable 47 { 48 public: 49 /** Create a ShapeAttributeLayerHolder instance. 50 51 This constructor creates an empty attribute holder, to 52 generate an attribute layer, you have to manually call 53 createAttributeLayer(). 54 */ ShapeAttributeLayerHolder()55 ShapeAttributeLayerHolder() : 56 mpShape(), 57 mpAttributeLayer() 58 { 59 } 60 ~ShapeAttributeLayerHolder()61 ~ShapeAttributeLayerHolder() 62 { 63 reset(); // ensures that the last attribute layer is 64 // correctly deregistered from the shape. 65 } 66 reset()67 void reset() 68 { 69 if( mpShape && mpAttributeLayer ) 70 mpShape->revokeAttributeLayer( mpAttributeLayer ); 71 } 72 73 /** This constructor receives a pointer to the Shape, from 74 which attribute layers should be generated. Initially, 75 this object does not create an attribute layer, you 76 have to manually call createAttributeLayer(). 77 78 @param rShape 79 Shape for which attribute layers should be generated. 80 */ createAttributeLayer(const AttributableShapeSharedPtr & rShape)81 bool createAttributeLayer( const AttributableShapeSharedPtr& rShape ) 82 { 83 reset(); 84 85 mpShape = rShape; 86 87 if( mpShape ) 88 mpAttributeLayer = mpShape->createAttributeLayer(); 89 90 return (mpAttributeLayer.get() != NULL); 91 } 92 get() const93 ShapeAttributeLayerSharedPtr get() const 94 { 95 return mpAttributeLayer; 96 } 97 98 private: 99 AttributableShapeSharedPtr mpShape; 100 ShapeAttributeLayerSharedPtr mpAttributeLayer; 101 }; 102 103 } 104 } 105 106 #endif /* INCLUDED_SLIDESHOW_SHAPEATTRIBUTELAYERHOLDER_HXX */ 107