LCOV - code coverage report
Current view: top level - sccomp/source/solver - SolverComponent.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 2 0.0 %
Date: 2014-11-03 Functions: 0 1 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_SCCOMP_SOURCE_SOLVER_SOLVERCOMPONENT_HXX
      21             : #define INCLUDED_SCCOMP_SOURCE_SOLVER_SOLVERCOMPONENT_HXX
      22             : 
      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/table/XCell.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : #include <cppuhelper/implbase3.hxx>
      29             : #include <comphelper/broadcasthelper.hxx>
      30             : #include <comphelper/propertycontainer.hxx>
      31             : #include <comphelper/proparrhlp.hxx>
      32             : 
      33             : #include <boost/unordered_map.hpp>
      34             : 
      35             : class ResMgr;
      36             : 
      37             : // hash map for the coefficients of a dependent cell (objective or constraint)
      38             : // The size of each vector is the number of columns (variable cells) plus one, first entry is initial value.
      39             : 
      40             : struct ScSolverCellHash
      41             : {
      42             :     size_t operator()( const css::table::CellAddress& rAddress ) const;
      43             : };
      44             : 
      45           0 : inline bool AddressEqual( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 )
      46             : {
      47           0 :     return rAddr1.Sheet == rAddr2.Sheet && rAddr1.Column == rAddr2.Column && rAddr1.Row == rAddr2.Row;
      48             : }
      49             : 
      50             : struct ScSolverCellEqual
      51             : {
      52             :     bool operator()( const css::table::CellAddress& rAddr1, const css::table::CellAddress& rAddr2 ) const;
      53             : };
      54             : 
      55             : typedef boost::unordered_map< css::table::CellAddress, std::vector<double>, ScSolverCellHash, ScSolverCellEqual > ScSolverCellHashMap;
      56             : 
      57             : typedef cppu::WeakImplHelper3<
      58             :                 com::sun::star::sheet::XSolver,
      59             :                 com::sun::star::sheet::XSolverDescription,
      60             :                 com::sun::star::lang::XServiceInfo >
      61             :         SolverComponent_Base;
      62             : 
      63             : class SolverComponent : public comphelper::OMutexAndBroadcastHelper,
      64             :                         public comphelper::OPropertyContainer,
      65             :                         public comphelper::OPropertyArrayUsageHelper< SolverComponent >,
      66             :                         public SolverComponent_Base
      67             : {
      68             : protected:
      69             :     static ResMgr* pSolverResMgr;
      70             : 
      71             :     // settings
      72             :     com::sun::star::uno::Reference< com::sun::star::sheet::XSpreadsheetDocument > mxDoc;
      73             :     com::sun::star::table::CellAddress                                            maObjective;
      74             :     com::sun::star::uno::Sequence< com::sun::star::table::CellAddress >           maVariables;
      75             :     com::sun::star::uno::Sequence< com::sun::star::sheet::SolverConstraint >      maConstraints;
      76             :     bool                                                                      mbMaximize;
      77             :     // set via XPropertySet
      78             :     bool                                                                      mbNonNegative;
      79             :     bool                                                                      mbInteger;
      80             :     sal_Int32                                                                     mnTimeout;
      81             :     sal_Int32                                                                     mnEpsilonLevel;
      82             :     bool                                                                      mbLimitBBDepth;
      83             :     // results
      84             :     bool                                                                      mbSuccess;
      85             :     double                                                                        mfResultValue;
      86             :     com::sun::star::uno::Sequence< double >                                       maSolution;
      87             :     OUString                                                                 maStatus;
      88             : 
      89             :     static OUString GetResourceString( sal_uInt32 nId );
      90             :     static css::uno::Reference<css::table::XCell> GetCell(
      91             :             const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
      92             :             const css::table::CellAddress& rPos );
      93             :     static void SetValue(
      94             :             const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
      95             :             const css::table::CellAddress& rPos, double fValue );
      96             :     static double GetValue(
      97             :             const css::uno::Reference<css::sheet::XSpreadsheetDocument>& xDoc,
      98             :             const css::table::CellAddress& rPos );
      99             : 
     100             : public:
     101             :                             SolverComponent();
     102             :     virtual                 ~SolverComponent();
     103             : 
     104             :     DECLARE_XINTERFACE()
     105             :     DECLARE_XTYPEPROVIDER()
     106             : 
     107             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
     108             :                                 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     109             :     virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() SAL_OVERRIDE;     // from OPropertySetHelper
     110             :     virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const SAL_OVERRIDE;    // from OPropertyArrayUsageHelper
     111             : 
     112             :                             // XSolver
     113             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheetDocument > SAL_CALL getDocument()
     114             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     115             :     virtual void SAL_CALL   setDocument( const ::com::sun::star::uno::Reference<
     116             :                                     ::com::sun::star::sheet::XSpreadsheetDocument >& _document )
     117             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     118             :     virtual ::com::sun::star::table::CellAddress SAL_CALL getObjective() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     119             :     virtual void SAL_CALL   setObjective( const ::com::sun::star::table::CellAddress& _objective )
     120             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     121             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::table::CellAddress > SAL_CALL getVariables()
     122             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     123             :     virtual void SAL_CALL   setVariables( const ::com::sun::star::uno::Sequence<
     124             :                                     ::com::sun::star::table::CellAddress >& _variables )
     125             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     126             :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::SolverConstraint > SAL_CALL getConstraints()
     127             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     128             :     virtual void SAL_CALL   setConstraints( const ::com::sun::star::uno::Sequence<
     129             :                                     ::com::sun::star::sheet::SolverConstraint >& _constraints )
     130             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     131             :     virtual sal_Bool SAL_CALL getMaximize() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     132             :     virtual void SAL_CALL   setMaximize( sal_Bool _maximize ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     133             : 
     134             :     virtual sal_Bool SAL_CALL getSuccess() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     135             :     virtual double SAL_CALL getResultValue() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     136             :     virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getSolution()
     137             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     138             : 
     139             :     virtual void SAL_CALL solve() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE = 0;
     140             : 
     141             :                             // XSolverDescription
     142             :     virtual OUString SAL_CALL getComponentDescription() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE = 0;
     143             :     virtual OUString SAL_CALL getStatusDescription() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     144             :     virtual OUString SAL_CALL getPropertyDescription( const OUString& aPropertyName )
     145             :                                 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     146             : 
     147             :                             // XServiceInfo
     148             :     virtual OUString SAL_CALL getImplementationName()
     149             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE = 0;
     150             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
     151             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     152             :     virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
     153             :                                 throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     154             : };
     155             : 
     156             : #endif
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10