Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

error C2440: 'const_cast' : cannot convert from 'std::_String_const_iterator' to 'std::_String_iterator'

$
0
0

Hi

I am migrating my application from vc++6.0 to vc++2013. I am getting error which iam unable to fix. I am sending the code and higlighting the error line in the code.

=========================CODE============================

#include "stdafx.h"
#include "Assignment.h"
#include "AutoAssign.h"


HRESULT CAutoAssign::ComError(_com_error& roComExcept)
{
 IErrorInfo *pErrorInfo = roComExcept.ErrorInfo();
 ::SetErrorInfo(0, pErrorInfo);
 pErrorInfo->Release();
 return roComExcept.Error();
}


HRESULT CAutoAssign::FinalConstruct()
{
 // Creates a komponenet for special db handling purposes
 m_spDBUtils.CoCreateInstance(_uuidof(DBUtils));

 // A component for supporting string operations within COLA conventions.
 m_spStringTools.CoCreateInstance(_uuidof(COLAStrings));

 return S_OK;
}


STDMETHODIMP CAutoAssign::InterfaceSupportsErrorInfo(REFIID riid)
{
 static const IID* arr[] =
 {
  &IID_IAutoAssign
 };
 for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
 {
  if (InlineIsEqualGUID(*arr[i],riid))
   return S_OK;
 }
 return S_FALSE;
}


STDMETHODIMP CAutoAssign::SetConnection(BSTR connection)
{
 // Check argument
 if ( NULL == connection )
 {
  this->Error(IDS_ERR_CONNECTION_MISSING, IID_IAutoAssign, E_INVALIDARG);
 }
 USES_CONVERSION;
 m_oSql.SetConnectionName(OLE2CT(connection));

 return S_OK;
}


/** Converts the Date stored in as string to a numer in a DATE format.

 @param szSource:  Reference to the String with the date
 */

DATE CAutoAssign::GetDateFromBSTR(CComBSTR &szSource)
{
 CComVariant container(szSource);
 container.ChangeType(VT_DATE);
 return (container.date);
}


/** Tries to find an reass.offer or an assessment which accomplishes the
 spezified parameters.

 @param, in:  po_in, An Interface Pointer to the input parameters.
 @param, out: pbFound, Points to an VARIANT_BOOL indicator to deliver,
      if a candidate could be found.
 */

STDMETHODIMP CAutoAssign::TryAutoAssign(IAssignSearch *po_in, VARIANT_BOOL *pbFound)
{
 CComPtr<IAssignSearch> spParams(po_in);
 CCandidateDataVector data;
 long lOppId = -1;
 double dPolicySum, dSumLevel;

 *pbFound = VARIANT_FALSE;
 this->ResetStatus();

 // Now we select every original contract part id with the same
 // Number as the contract or the cession.
 try
 {
  CComBSTR szPolicy, szCession;
  spParams->get_Policy(&szPolicy);
  spParams->get_Cession(&szCession);

  if (szPolicy.Length() > 0 && szCession.Length() > 0)
   m_oSql.SelectEqualPolicyCessionName(m_spDBUtils, spParams, data);
  else
  {
   if (szPolicy.Length() > 0)
    m_oSql.SelectEqualName(m_spDBUtils, szPolicy, spParams, data);
   if (szCession.Length() > 0)
    m_oSql.SelectEqualName(m_spDBUtils, szCession, spParams, data);
  }

  lOppId = this->CanAssignByNumbers(spParams, data);
  
  // Second try for assignenment. In this case, the person, the plan the
  // starting date and open sum have to be equal.
  if (lOppId < 0)
  {
   m_oSql.SelectEqualPerson(m_spDBUtils, spParams, data);
   lOppId = this->CanAssignByPersonAndPlanData(spParams, data);
  }

  // Evaluation of the resulting values. Attention: There is no warning if
  // no assignment candidate is found.
  if (lOppId > -1)
  { 
   // If the difference between the open sum and the contract sum is too
   // high then an warning message is generated.
   spParams->get_PolicySum(&dPolicySum);
   spParams->get_SumLevel(&dSumLevel);

   if (this->CountAssignmendCandidates(data) > 1)
    if (m_szErrorMsg.Length() == 0)
     m_szErrorMsg = "audi_multi_assign_candidates";

   if (abs(dPolicySum - m_dOpenSum) > m_dOpenSum * dSumLevel)
    if (m_szErrorMsg.Length() == 0)
     m_szErrorMsg = "audi_difference_open_sum";
   m_dOpenSum = max(m_dOpenSum - dPolicySum, 0);
  }
 }
 catch (CSQLException &e) {  
  return this->Error(e.m_szMsg.c_str(), IID_IAutoAssign, E_FAIL);
 }
 catch (std::exception &e) {
  return this->Error(e.what(), IID_IAutoAssign, E_FAIL);
 }

 m_lAssignId = lOppId;
 *pbFound = (-1 == m_lAssignId) ? VARIANT_FALSE : VARIANT_TRUE;
 return S_OK;
}


/** Tries to find an assignment by the number of the policy / cession
 ...

 @param,in:  Komponent with the input parameter,
      Collection of the database records found
 @ret    true if an assignment could be found.
 
*/

long CAutoAssign::CanAssignByNumbers(CComPtr<IAssignSearch> &spParams,
  CCandidateDataVector &coll)
{
 int iAssessmentFound = 0;
 int iOfferFound = 0;
 long lErg = -1, lCurrencyId;
 CCandidateDataVector::iterator it;

 spParams->get_CurrencyId(&lCurrencyId);

 // Goes through the collection and finds out, how many assessments and
 // offers could be found.
 for (it = coll.begin(); it != coll.end(); it++)
 {
  if ((*it).m_lCurrencyId == lCurrencyId)
  {
   if (3 == (*it).m_sRvCode)
    iAssessmentFound++;
   else
    iOfferFound++;
  }
 }

 // Now, where we have the count of assessments and offers, we can copy
 // the fitting parts to the AssignCandidates and give back the first
 // fitting item.
 if (iAssessmentFound + iOfferFound > 0)
 {
  for (it = coll.begin(); it != coll.end(); it++)
  {
   if ((*it).m_lCurrencyId == lCurrencyId)
   {
    if (2 == (*it).m_sRvCode || 0 == iOfferFound)
    {
     if (lErg == -1)
      this->SetHit((*it).m_lOppId, (*it).m_sRvCode,
       (*it).m_dOpenSum, lErg);
     (*it).m_bSelected = true;
    }
   }
  }

  // if no result is set although we had found at least one fitting
  // assessment or offer the currency are not fitting.
  if (-1 == lErg)
   m_szErrorMsg = "audi_assign_missmatch";
 }
 return (lErg);
}


/** This implements the second chance to find an assignment for a new contract.
 After comparing the numbers, this effort tries the same with different
 personal and plan data.

 @param, in:  Pointer to the input Parameters (spParams) and a reference
      to a collection of database records to be examined.
 @ret:    the OcpId for the first fitting database record.
 */

long CAutoAssign::CanAssignByPersonAndPlanData(CComPtr<IAssignSearch>
                 &spParams,
                 CCandidateDataVector &coll)
{
 long lErg = -1, lCurrencyId;
 CComBSTR szSystematicKeyHelp;
 DATE datePolicyStart;
 double dPolicySum, dSumLevel, dOpenSum = 0, dTemp;
 CCandidateDataVector::iterator it;
 short sKeyLevelHigh = 0;
 int iDays;

 // Getting the parameter of the police
 spParams->get_PolicyStartDate(&datePolicyStart);
 spParams->get_PolicySum(&dPolicySum);
 spParams->get_SumLevel(&dSumLevel);
 spParams->get_SystematicKey(&szSystematicKeyHelp);
 spParams->get_CurrencyId(&lCurrencyId);

 tstring szSystematicKey(szSystematicKeyHelp);

 // For every fitting item of the database query we compute the level
 // of fitting the systematic keys. The highest found is stored in
 // sKeyLevelHigh.
 it = coll.begin();
 if (it == coll.end())
  return -1;

 for (; it != coll.end(); it++)
 {
  // Computing the days between start by the assessment/offer
  // and start by the police.
  (*it).m_datePolicyStart = abs((*it).m_datePolicyStart -
   datePolicyStart);

  if ((*it).m_datePolicyStart < 367 && (*it).m_lCurrencyId == lCurrencyId
   && dPolicySum <= (*it).m_dOpenSum * (1 + dSumLevel))
  {
   (*it).m_sSystematicKeyLevel = this->CountEqualSystematicKeys(
    szSystematicKey, (*it).m_szSystematicKey);
   if ((*it).m_sSystematicKeyLevel >= sKeyLevelHigh)
   {
    // Now we choose the item of the highest sKeyLevelHigh that has
    // the smallest difference in open sum. If the open sum is equal
    // for two, then the one with the smallest difference in days will
    // be taken.
    dTemp = this->CalculateMinOpenSum(dPolicySum, (*it).m_dOpenSum,
     dSumLevel);

    if ((*it).m_sSystematicKeyLevel > sKeyLevelHigh)
    {
     dOpenSum = dTemp;     
     iDays = 367;
    }
    sKeyLevelHigh = (*it).m_sSystematicKeyLevel;

    if (dOpenSum > dTemp ||
     (dOpenSum == dTemp && iDays > (*it).m_datePolicyStart))
    {
     iDays = (*it).m_datePolicyStart;
     dOpenSum = dTemp;
    }
   }
  }
 }

 if (sKeyLevelHigh == 0)
 {
  m_szErrorMsg = "audi_assign_missmatch";  
  return (-1);
 }
 
 // As we have now the best fitting parameters we can look at the
 // result set because there can be more than one fitting item.
 for (it = coll.begin(); it != coll.end(); it++)
 {
  if ((*it).m_sSystematicKeyLevel == sKeyLevelHigh &&
   iDays == (*it).m_datePolicyStart &&
   dOpenSum == this->CalculateMinOpenSum(dPolicySum,
   (*it).m_dOpenSum, dSumLevel))
  {
   if (lErg == -1)
    this->SetHit((*it).m_lOppId, (*it).m_sRvCode, (*it).m_dOpenSum, lErg);
   (*it).m_bSelected = true;
  }
 }
 return (lErg);
}


double CAutoAssign::CalculateMinOpenSum(double dPolice, double dOffer,
              double dLevel)
{
 // the differ is in the range that is o.k.
 if (abs(dPolice - dOffer) <= dOffer * dLevel)
  return (abs(dPolice - dOffer));

 // If the police value is lower than the offer the real difference is
 // returned.
 if (dPolice < dOffer)
  return (dOffer - dPolice);
 
 return (dPolice);
}


/** Compares to systematic numbers. As they are divided in parts, iParts gives
 the number of parts that have to be equal.

 @param, in:  szFirst, szSecond: the two systematic numbers
      iParts: the number of parts to be compared. 0 means, that
      every existing part is eximaned, so that different numbers
      of parts that they are not equal.
 @ret:    equal return true, false otherwise.
 */

short CAutoAssign::CountEqualSystematicKeys(const tstring &szFirst,
               const tstring &szSecond)
{
 tstring::iterator itFirst = const_cast<tstring::iterator>(szFirst.begin()); //error line
 tstring::iterator itSecond = const_cast<tstring::iterator>(szSecond.begin());
 int iPartFirst, iPartSecond;
 short sErg = 0;

 while (itFirst != szFirst.end() && itSecond != szSecond.end())
 {
  // Compute the next parts for both systematic numbers.
  iPartFirst = 0;
  for (; itFirst != szFirst.end(); itFirst++)
  {
   if (*itFirst < '0' || *itFirst > '9')
    break;
   else
    iPartFirst = iPartFirst * 10 + *itFirst - '0';
  }
  if (itFirst != szFirst.end())
   itFirst++;

  iPartSecond = 0;
  for (; itSecond != szSecond.end(); itSecond++)
  {
   if (*itSecond < '0' || *itSecond > '9')
    break;
   else
    iPartSecond = iPartSecond * 10 + *itSecond - '0';
  }
  if (itSecond != szSecond.end())
   itSecond++;

  // Compare it
  if (iPartFirst != iPartSecond || 0 == iPartFirst)
   break;
  
  sErg++;
 }
 return (sErg);
}


/** Counts the records in the database collection for items which are
 assignment candidates. Thes records have set the field m_bSelected to true.

 @param,in:  The Collection with database records.
 @ret:    the number of records
 */

long CAutoAssign::CountAssignmendCandidates(const CCandidateDataVector &coll)
{
 long lErg = 0;
 CCandidateDataVector::iterator it =
  const_cast<CCandidateDataVector::iterator> (coll.begin());

 for (; it != coll.end(); it++)
 {
  if ((*it).m_bSelected)
   lErg++;
 }
 return (lErg);
}


/** Allows the setting of the selected item.
 */

void CAutoAssign::SetHit(long lId, short sType, double dOpenSum, long &lErg)
{
 m_lAssignId = lId;
 m_sTyp = sType;
 m_dOpenSum = dOpenSum;
 lErg = lId;
}


/** Clears the actual error message so that the next call of the property
 ErrorMsg will return an empty item.
 */

STDMETHODIMP CAutoAssign::ResetStatus()
{
 m_lAssignId = -1;
 m_sTyp = 1;
 m_dOpenSum = 0.0;
 m_szErrorMsg = "";

 return S_OK;
}


STDMETHODIMP CAutoAssign::get_CandidateType(short *pVal)
{
 *pVal = m_sTyp;
 return S_OK;
}

STDMETHODIMP CAutoAssign::get_CandidateId(long *pVal)
{
 *pVal = m_lAssignId;
 return S_OK;
}

STDMETHODIMP CAutoAssign::get_CandidateOpenSum(double *pVal)
{
 *pVal = m_dOpenSum;
 return S_OK;
}

/** Returns the value of the error message string.
 */

STDMETHODIMP CAutoAssign::get_ErrorMsg(BSTR *pVal)
{
 return m_szErrorMsg.CopyTo(pVal);
===================================CODE===============================

can anyone please suggest anything

Thanks Ankush


Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>