LibreOffice Module oox (master)  1
modelbase.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_OOX_DRAWINGML_CHART_MODELBASE_HXX
21 #define INCLUDED_OOX_DRAWINGML_CHART_MODELBASE_HXX
22 
23 #include <memory>
24 
25 #include <oox/helper/refmap.hxx>
26 #include <oox/helper/refvector.hxx>
27 #include <rtl/ustring.hxx>
28 #include <sal/types.h>
29 
30 namespace oox { class AttributeList; }
31 
32 namespace oox::drawingml::chart {
33 
34 template< typename ModelType >
35 class ModelRef : public std::shared_ptr< ModelType >
36 {
37 public:
38  ModelRef() {}
39  ModelRef( const std::shared_ptr< ModelType >& rxModel ) : std::shared_ptr< ModelType >( rxModel ) {}
40 
41  bool is() const { return this->get() != 0; }
42 
43  ModelType& create() { (*this) = std::make_shared<ModelType>(); return **this; }
44  template< typename Param1Type >
45  ModelType& create( const Param1Type& rParam1 ) { (*this) = std::make_shared<ModelType>( rParam1 ); return **this; }
46  template< typename Param1Type, typename Param2Type >
47  ModelType& create( const Param1Type& rParam1, const Param2Type& rParam2 ) { (*this) = std::make_shared<ModelType>( rParam1, rParam2 ); return **this; }
48 
49  ModelType& getOrCreate() { if( !*this ) (*this) = std::make_shared<ModelType>(); return **this; }
50  template< typename Param1Type >
51  ModelType& getOrCreate( const Param1Type& rParam1 ) { if( !*this ) (*this) = std::make_shared<ModelType>( rParam1 ); return **this; }
52 };
53 
54 template< typename ModelType >
55 class ModelVector : public RefVector< ModelType >
56 {
57 public:
60 
62 
63  ModelType& create() { return append( std::make_shared<ModelType>() ); }
64  template< typename Param1Type >
65  ModelType& create( const Param1Type& rParam1 ) { return append( std::make_shared<ModelType>( rParam1 ) ); }
66  template< typename Param1Type, typename Param2Type >
67  ModelType& create( const Param1Type& rParam1, const Param2Type& rParam2 ) { return append( std::make_shared<ModelType>( rParam1, rParam2 ) ); }
68 
69 private:
70  ModelType& append( std::shared_ptr<ModelType> pModel )
71  {
72  assert(pModel);
73  auto pTmp = pModel.get();
74  this->push_back( std::move(pModel) );
75  return *pTmp;
76  }
77 };
78 
79 template< typename KeyType, typename ModelType >
80 class ModelMap : public RefMap< KeyType, ModelType >
81 {
82 public:
86 
87  ModelMap() {}
88 
89  ModelType& create( KeyType eKey ) { return insert( eKey, new ModelType ); }
90 
91 private:
92  ModelType& insert( KeyType eKey, ModelType* pModel ) { (*this)[ eKey ].reset( pModel ); return *pModel; }
93 };
94 
96 {
97  OUString maFormatCode;
99 
100  NumberFormat();
101 
102  void setAttributes( const AttributeList& rAttribs );
103 };
104 
106 {
107  double mfX;
108  double mfY;
109  double mfW;
110  double mfH;
111  sal_Int32 mnXMode;
112  sal_Int32 mnYMode;
113  sal_Int32 mnWMode;
114  sal_Int32 mnHMode;
115  sal_Int32 mnTarget;
117 
118  LayoutModel();
119  ~LayoutModel();
120 };
121 
122 } // namespace oox::drawingml::chart
123 
124 #endif
125 
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 mnHMode
Mode for width.
Definition: modelbase.hxx:114
ModelType & append(std::shared_ptr< ModelType > pModel)
Definition: modelbase.hxx:70
LayoutModel()
True = automatic positioning.
Definition: modelbase.cxx:38
RefVector< ModelType >::size_type size_type
Definition: modelbase.hxx:59
ModelType & create(const Param1Type &rParam1, const Param2Type &rParam2)
Definition: modelbase.hxx:67
ModelType & insert(KeyType eKey, ModelType *pModel)
Definition: modelbase.hxx:92
double mfW
Top position of this object.
Definition: modelbase.hxx:109
ModelType & create(const Param1Type &rParam1)
Definition: modelbase.hxx:65
Template for a map of ref-counted objects with additional accessor functions.
Definition: refmap.hxx:39
RefMap< KeyType, ModelType >::mapped_type mapped_type
Definition: modelbase.hxx:84
double mfH
Width of this object.
Definition: modelbase.hxx:110
RefMap< KeyType, ModelType >::key_type key_type
Definition: modelbase.hxx:83
ModelType & getOrCreate(const Param1Type &rParam1)
Definition: modelbase.hxx:51
sal_Int32 mnWMode
Mode for top position.
Definition: modelbase.hxx:113
double mfY
Left position of this object.
Definition: modelbase.hxx:108
ModelType & create(const Param1Type &rParam1, const Param2Type &rParam2)
Definition: modelbase.hxx:47
ModelRef(const std::shared_ptr< ModelType > &rxModel)
Definition: modelbase.hxx:39
sal_Int32 mnTarget
Mode for height.
Definition: modelbase.hxx:115
Provides access to attribute values of an element.
bool mbSourceLinked
Number format code.
Definition: modelbase.hxx:98
RefVector< ModelType >::value_type value_type
Definition: modelbase.hxx:58
NumberFormat()
True = number format linked to source data.
Definition: modelbase.cxx:27
sal_Int32 mnYMode
Mode for left position.
Definition: modelbase.hxx:112
ModelType & create(const Param1Type &rParam1)
Definition: modelbase.hxx:45
void setAttributes(const AttributeList &rAttribs)
Definition: modelbase.cxx:32
sal_Int32 mnXMode
Height of this object.
Definition: modelbase.hxx:111
Template for a vector of ref-counted objects with additional accessor functions.
Definition: refvector.hxx:41
bool mbAutoLayout
Layout target for plot area.
Definition: modelbase.hxx:116
ModelType & create(KeyType eKey)
Definition: modelbase.hxx:89
RefMap< KeyType, ModelType >::value_type value_type
Definition: modelbase.hxx:85