00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00055
00056
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
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