LibreOffice Module canvas (master)  1
propertysethelper.hxx
Go to the documentation of this file.
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_CANVAS_PROPERTYSETHELPER_HXX
21 #define INCLUDED_CANVAS_PROPERTYSETHELPER_HXX
22 
23 #include <canvas/canvastools.hxx>
24 
25 #include <functional>
26 #include <vector>
27 #include <memory>
28 
30 
31 namespace com::sun::star::beans { class XPropertyChangeListener; }
32 namespace com::sun::star::beans { class XPropertySetInfo; }
33 namespace com::sun::star::beans { class XVetoableChangeListener; }
34 
35 namespace canvas
36 {
53  {
54  public:
55  typedef std::function<css::uno::Any ()> GetterType;
56  typedef std::function<void (const css::uno::Any&)> SetterType;
57  struct Callbacks
58  {
59  GetterType getter;
60  SetterType setter;
61  };
63  typedef std::vector< MapType::MapEntry > InputMap;
64 
65  class MakeMap : public InputMap
66  {
67  public:
68  MakeMap(const char* name,
69  const GetterType& getter,
70  const SetterType& setter)
71  {
72  MapType::MapEntry aEntry={name, {getter, setter}};
73  push_back(aEntry);
74  }
75  MakeMap(const char* name,
76  const GetterType& getter)
77  {
78  MapType::MapEntry aEntry={name, {getter, SetterType()}};
79  push_back(aEntry);
80  }
81  MakeMap& operator()(const char* name,
82  const GetterType& getter,
83  const SetterType& setter)
84  {
85  MapType::MapEntry aEntry={name, {getter, setter}};
86  push_back(aEntry);
87  return *this;
88  }
89  MakeMap& operator()(const char* name,
90  const GetterType& getter)
91  {
92  MapType::MapEntry aEntry={name, {getter, SetterType()}};
93  push_back(aEntry);
94  return *this;
95  }
96  };
97 
101 
109  void initProperties( const InputMap& rMap );
110 
119  void addProperties( const InputMap& rMap );
120 
126  bool isPropertyName( const OUString& aPropertyName ) const;
127 
128  // XPropertySet implementation
129  css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo() const;
130  void setPropertyValue( const OUString& aPropertyName,
131  const css::uno::Any& aValue );
132  css::uno::Any getPropertyValue( const OUString& PropertyName ) const;
133  void addPropertyChangeListener( const OUString& aPropertyName,
134  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener );
135  void addVetoableChangeListener( const OUString& aPropertyName,
136  const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener );
137 
138  private:
139  std::unique_ptr<MapType> mpMap;
140  InputMap maMapEntries;
141  };
142 }
143 
144 #endif /* INCLUDED_CANVAS_PROPERTYSETHELPER_HXX */
145 
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define CANVASTOOLS_DLLPUBLIC
A very simplistic map for ASCII strings and arbitrary value types.
MakeMap(const char *name, const GetterType &getter, const SetterType &setter)
std::unique_ptr< MapType > mpMap
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
MakeMap(const char *name, const GetterType &getter)
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
tools::ValueMap< Callbacks > MapType
MakeMap & operator()(const char *name, const GetterType &getter)
Really simplistic XPropertySet helper for properties.
std::function< css::uno::Any()> GetterType
std::vector< MapType::MapEntry > InputMap
std::function< void(const css::uno::Any &)> SetterType
MakeMap & operator()(const char *name, const GetterType &getter, const SetterType &setter)