source/numeric/cellfuncobj.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  The Contents of this file are made available subject to
00004  *  the terms of GNU Lesser General Public License Version 2.1.
00005  *
00006  *
00007  *    GNU Lesser General Public License Version 2.1
00008  *    =============================================
00009  *    Copyright 2005 by Kohei Yoshida.
00010  *    1039 Kingsway Dr., Apex, NC 27502, USA
00011  *
00012  *    This library is free software; you can redistribute it and/or
00013  *    modify it under the terms of the GNU Lesser General Public
00014  *    License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *    This library is distributed in the hope that it will be useful,
00017  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *    Lesser General Public License for more details.
00020  *
00021  *    You should have received a copy of the GNU Lesser General Public
00022  *    License along with this library; if not, write to the Free Software
00023  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *    MA  02111-1307  USA
00025  *
00026  ************************************************************************/
00027 
00028 #include "numeric/cellfuncobj.hxx"
00029 #include "xcalc.hxx"
00030 #include "unoglobal.hxx"
00031 #include "com/sun/star/table/CellAddress.hpp"
00032 #include <vector>
00033 #include <sstream>
00034 #include <iostream>
00035 #include <stdio.h>
00036 
00037 using com::sun::star::table::CellAddress;
00038 using ::std::vector;
00039 using ::std::string;
00040 using ::std::ostringstream;
00041 
00042 namespace scsolver { namespace numeric {
00043 
00044 struct CellFuncObjImpl
00045 {
00046         CalcInterface* pCalc;
00047         CellAddress TargetCell;
00048         vector<CellAddress> DecVarCells;
00049 };
00050 
00051 //-----------------------------------------------------------------
00052 
00053 /*
00054 CellFuncObj::CellFuncObj()
00055 {
00056         // disabled
00057 }
00058 */
00059 
00060 CellFuncObj::CellFuncObj( CalcInterface* pCalc ) :
00061         m_pImpl( new CellFuncObjImpl )
00062 {
00063         m_pImpl->pCalc = pCalc;
00064 }
00065 
00066 CellFuncObj::~CellFuncObj() throw()
00067 {
00068 }
00069 
00070 const vector<double>& CellFuncObj::getVars() const
00071 {
00072     // Does absolutely nothing....
00073     return mFakeVars;
00074 }
00075 
00076 void CellFuncObj::setVars(const vector<double>& vars) const
00077 {
00078         vector<CellAddress>::const_iterator itr, 
00079                 itrBeg = m_pImpl->DecVarCells.begin(), 
00080                 itrEnd = m_pImpl->DecVarCells.end();
00081 
00082     vector<double>::const_iterator itrVar,
00083         itrVarBeg = vars.begin(), itrVarEnd = vars.end();
00084 
00085     for (itr = itrBeg, itrVar = itrVarBeg; itr != itrEnd && itrVar != itrVarEnd; ++itr, ++itrVar)
00086         m_pImpl->pCalc->setCellValue(*itr, *itrVar);
00087 }
00088 
00089 void CellFuncObj::setVar(size_t index, double var) const
00090 {
00091     if ( index >= m_pImpl->DecVarCells.size() )
00092         return;
00093 
00094     m_pImpl->pCalc->setCellValue( m_pImpl->DecVarCells.at(index), var);
00095 }
00096 
00097 double CellFuncObj::eval() const
00098 {
00099         return m_pImpl->pCalc->getCellValue( m_pImpl->TargetCell );
00100 }
00101 
00102 const std::string CellFuncObj::getFuncString() const
00103 {
00104         ostringstream os;
00105         int sheet = m_pImpl->TargetCell.Sheet;
00106         int column = m_pImpl->TargetCell.Column;
00107         int row = m_pImpl->TargetCell.Row;
00108         os << "(" << sheet << ", " << column << ", " << row << ")";
00109 
00110         return os.str();
00111 }
00112 
00113 void CellFuncObj::setTargetCell( const CellAddress& addr )
00114 {
00115         m_pImpl->TargetCell = addr;
00116 }
00117 
00118 void CellFuncObj::appendDecVarCell( const CellAddress& addr )
00119 {
00120         m_pImpl->DecVarCells.push_back(addr);
00121 }
00122 
00123 }}
00124 

Generated on Mon Jul 28 09:13:20 2008 for scsolver by  doxygen 1.5.3