bump product version to 6.4.0.3
[LibreOffice.git] / sccomp / source / solver / SolverComponent.hxx
blobd4ead688929143fb562d9e9f9521100d430ab789
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SCCOMP_SOURCE_SOLVER_SOLVERCOMPONENT_HXX
21 #define INCLUDED_SCCOMP_SOURCE_SOLVER_SOLVERCOMPONENT_HXX
23 #include <com/sun/star/sheet/XSolver.hpp>
24 #include <com/sun/star/sheet/XSolverDescription.hpp>
25 #include <com/sun/star/table/CellAddress.hpp>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <cppuhelper/implbase.hxx>
28 #include <comphelper/broadcasthelper.hxx>
29 #include <comphelper/propertycontainer.hxx>
30 #include <comphelper/proparrhlp.hxx>
32 #include <unordered_map>
34 namespace com::sun::star::table { class XCell; }
36 // hash map for the coefficients of a dependent cell (objective or constraint)
37 // The size of each vector is the number of columns (variable cells) plus one, first entry is initial value.
39 struct ScSolverCellHash
41 size_t operator()( const css::table::CellAddress& rAddress ) const;
44 inline bool AddressEqual( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 )
46 return rAddr1.Sheet == rAddr2.Sheet && rAddr1.Column == rAddr2.Column && rAddr1.Row == rAddr2.Row;
49 struct ScSolverCellEqual
51 bool operator()( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 ) const;
54 typedef std::unordered_map< css::table::CellAddress, std::vector<double>, ScSolverCellHash, ScSolverCellEqual > ScSolverCellHashMap;
56 typedef cppu::WeakImplHelper<
57 css::sheet::XSolver,
58 css::sheet::XSolverDescription,
59 css::lang::XServiceInfo >
60 SolverComponent_Base;
62 class SolverComponent : public comphelper::OMutexAndBroadcastHelper,
63 public comphelper::OPropertyContainer,
64 public comphelper::OPropertyArrayUsageHelper< SolverComponent >,
65 public SolverComponent_Base
67 protected:
68 // settings
69 css::uno::Reference< css::sheet::XSpreadsheetDocument > mxDoc;
70 css::table::CellAddress maObjective;
71 css::uno::Sequence< css::table::CellAddress > maVariables;
72 css::uno::Sequence< css::sheet::SolverConstraint > maConstraints;
73 bool mbMaximize;
74 // set via XPropertySet
75 bool mbNonNegative;
76 bool mbInteger;
77 sal_Int32 mnTimeout;
78 sal_Int32 mnEpsilonLevel;
79 bool mbLimitBBDepth;
80 // results
81 bool mbSuccess;
82 double mfResultValue;
83 css::uno::Sequence< double > maSolution;
84 OUString maStatus;
86 static OUString GetResourceString(const char* pId);
87 static css::uno::Reference<css::table::XCell> GetCell(
88 const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
89 const css::table::CellAddress& rPos );
90 static void SetValue(
91 const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
92 const css::table::CellAddress& rPos, double fValue );
93 static double GetValue(
94 const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
95 const css::table::CellAddress& rPos );
97 public:
98 SolverComponent();
99 virtual ~SolverComponent() override;
101 DECLARE_XINTERFACE()
102 DECLARE_XTYPEPROVIDER()
104 virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
105 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; // from OPropertySetHelper
106 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const override; // from OPropertyArrayUsageHelper
108 // XSolver
109 virtual css::uno::Reference< css::sheet::XSpreadsheetDocument > SAL_CALL getDocument() override;
110 virtual void SAL_CALL setDocument( const css::uno::Reference<
111 css::sheet::XSpreadsheetDocument >& _document ) override;
112 virtual css::table::CellAddress SAL_CALL getObjective() override;
113 virtual void SAL_CALL setObjective( const css::table::CellAddress& _objective ) override;
114 virtual css::uno::Sequence< css::table::CellAddress > SAL_CALL getVariables() override;
115 virtual void SAL_CALL setVariables( const css::uno::Sequence<
116 css::table::CellAddress >& _variables ) override;
117 virtual css::uno::Sequence< css::sheet::SolverConstraint > SAL_CALL getConstraints() override;
118 virtual void SAL_CALL setConstraints( const css::uno::Sequence<
119 css::sheet::SolverConstraint >& _constraints ) override;
120 virtual sal_Bool SAL_CALL getMaximize() override;
121 virtual void SAL_CALL setMaximize( sal_Bool _maximize ) override;
123 virtual sal_Bool SAL_CALL getSuccess() override;
124 virtual double SAL_CALL getResultValue() override;
125 virtual css::uno::Sequence< double > SAL_CALL getSolution() override;
127 virtual void SAL_CALL solve() override = 0;
129 // XSolverDescription
130 virtual OUString SAL_CALL getComponentDescription() override = 0;
131 virtual OUString SAL_CALL getStatusDescription() override;
132 virtual OUString SAL_CALL getPropertyDescription( const OUString& aPropertyName ) override;
134 // XServiceInfo
135 virtual OUString SAL_CALL getImplementationName() override = 0;
136 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
137 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
140 #endif
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */