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 #pragma once
21 
22 #include <canvas/canvastools.hxx>
23 
24 #include <functional>
25 #include <vector>
26 #include <memory>
27 
29 
30 namespace com::sun::star::beans { class XPropertyChangeListener; }
31 namespace com::sun::star::beans { class XPropertySetInfo; }
32 namespace com::sun::star::beans { class XVetoableChangeListener; }
33 
34 namespace canvas
35 {
52  {
53  public:
54  typedef std::function<css::uno::Any ()> GetterType;
55  typedef std::function<void (const css::uno::Any&)> SetterType;
56  struct Callbacks
57  {
58  GetterType getter;
59  SetterType setter;
60  };
62  typedef std::vector< MapType::MapEntry > InputMap;
63 
64  class MakeMap : public InputMap
65  {
66  public:
67  MakeMap(const char* name,
68  const GetterType& getter,
69  const SetterType& setter)
70  {
71  MapType::MapEntry aEntry={name, {getter, setter}};
72  push_back(aEntry);
73  }
74  MakeMap(const char* name,
75  const GetterType& getter)
76  {
77  MapType::MapEntry aEntry={name, {getter, SetterType()}};
78  push_back(aEntry);
79  }
80  MakeMap& operator()(const char* name,
81  const GetterType& getter,
82  const SetterType& setter)
83  {
84  MapType::MapEntry aEntry={name, {getter, setter}};
85  push_back(aEntry);
86  return *this;
87  }
88  MakeMap& operator()(const char* name,
89  const GetterType& getter)
90  {
91  MapType::MapEntry aEntry={name, {getter, SetterType()}};
92  push_back(aEntry);
93  return *this;
94  }
95  };
96 
100 
108  void initProperties( const InputMap& rMap );
109 
118  void addProperties( const InputMap& rMap );
119 
125  bool isPropertyName( const OUString& aPropertyName ) const;
126 
127  // XPropertySet implementation
128  css::uno::Reference< css::beans::XPropertySetInfo > getPropertySetInfo() const;
129  void setPropertyValue( const OUString& aPropertyName,
130  const css::uno::Any& aValue );
131  css::uno::Any getPropertyValue( const OUString& PropertyName ) const;
132  void addPropertyChangeListener( const OUString& aPropertyName,
133  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener );
134  void addVetoableChangeListener( const OUString& aPropertyName,
135  const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener );
136 
137  private:
138  std::unique_ptr<MapType> mpMap;
139  InputMap maMapEntries;
140  };
141 }
142 
143 /* 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)