Overview
Features
Download
Documentation
Community
Add-Ons & Services

TypeHandler Weird Error

Please post support and help requests here.

TypeHandler Weird Error

Postby HerveM » 09 May 2013, 16:58

Hello,

I tried to implement a TypeHandler :
Base Class
Code: Select all
class IPlayer
{
public:
   IPlayer(void);
   ~IPlayer(void);

   const std::string getID() const { return p_sID; };
   const std::string getName() const { return p_sName; };
   const std::string getMail() const { return p_sMail; };
   const std::string getPwd() const { return p_sPwd; };
   const std::string getRole() const { return p_sRole; };
   const std::string getDateCreation() const { return p_sDateCreation; };
   const std::string getDateLastCnx() const { return p_sDateLastCnx; };

   std::string operator() () const { return p_sID; };
//Juste for testing
//private:
   std::string p_sID;
   std::string p_sName;
   std::string p_sMail;
   std::string p_sPwd;
   std::string p_sRole;
   std::string p_sDateCreation;
   std::string p_sDateLastCnx;
};

TypeHandler Impl.:
Code: Select all
#include <Poco\Data\TypeHandler.h>
#include "IPlayer.h"

namespace Poco {
namespace Data {

   template<>
   class TypeHandler<class IPlayer>
   {
   public:
      static std::size_t size()
      {
         return 7;
      }

      static void bind(std::size_t pos, const IPlayer& obj, AbstractBinder* pBinder){
          poco_assert_dbg (pBinder != 0);
          TypeHandler<std::string>::bind(pos++, obj.getID(),pBinder);
          TypeHandler<std::string>::bind(pos++, obj.getName(),pBinder);
          TypeHandler<std::string>::bind(pos++, obj.getMail(),pBinder);
          TypeHandler<std::string>::bind(pos++, obj.getPwd(),pBinder);
          TypeHandler<std::string>::bind(pos++, obj.getRole(),pBinder);
          TypeHandler<std::string>::bind(pos++, obj.getDateCreation(),pBinder);
          TypeHandler<std::string>::bind(pos++, obj.getDateLastCnx(),pBinder);
      }

      static void prepare(std::size_t pos, const IPlayer& obj, AbstractPreparation* pPrepare){
         poco_assert_dbg (pPrepare != 0);
         TypeHandler<std::string>::prepare(pos++, obj.getID(),pPrepare);
         TypeHandler<std::string>::prepare(pos++, obj.getName(),pPrepare);
         TypeHandler<std::string>::prepare(pos++, obj.getMail(),pPrepare);
         TypeHandler<std::string>::prepare(pos++, obj.getPwd(),pPrepare);
         TypeHandler<std::string>::prepare(pos++, obj.getRole(),pPrepare);
         TypeHandler<std::string>::prepare(pos++, obj.getDateCreation(),pPrepare);
         TypeHandler<std::string>::prepare(pos++, obj.getDateLastCnx(),pPrepare);
      }

      static void extract(std::size_t pos, IPlayer& obj, const IPlayer& defVal, AbstractExtractor* pExt){
         poco_assert_dbg (pExt != 0);
         std::string p_sID;
         std::string p_sName;
         std::string p_sMail;
         std::string p_sPwd;
         std::string p_sRole;
         std::string p_sDateCreation;
         std::string p_sDateLastCnx;
         TypeHandler<std::string>::extract(pos++, p_sID, defVal.getID(),pExt);
         TypeHandler<std::string>::extract(pos++, p_sName,defVal.getName(),pExt);
         TypeHandler<std::string>::extract(pos++, p_sMail,defVal.getMail(),pExt);
         TypeHandler<std::string>::extract(pos++, p_sPwd,defVal.getPwd(),pExt);
         TypeHandler<std::string>::extract(pos++, p_sRole,defVal.getRole(),pExt);
         TypeHandler<std::string>::extract(pos++, p_sDateCreation,defVal.getDateCreation(),pExt);
         TypeHandler<std::string>::extract(pos++, p_sDateLastCnx,defVal.getDateLastCnx(),pExt);
         obj.p_sID = p_sID;
         obj.p_sName = p_sName;
         obj.p_sMail = p_sMail;
         obj.p_sPwd = p_sPwd;
         obj.p_sRole = p_sRole;
         obj.p_sDateCreation = p_sDateCreation;
         obj.p_sDateLastCnx = p_sDateLastCnx;
      }
   };
}}

And I get this error :
Error 1 error C2664: 'bool Poco::Data::AbstractExtractor::extract(size_t,Poco::Int8 &)' : cannot convert parameter 2 from 'IPlayer' to 'Poco::Int8 &' \INCLUDE\Poco\Data\TypeHandler.h 135 1 Server_Imp

And at line 135 we have :
Code: Select all
static void extract(std::size_t pos, T& obj, const T& defVal, AbstractExtractor* pExt)
{
   poco_assert_dbg (pExt != 0);
   if (!pExt->extract(pos, obj))
      obj = defVal;
}

As I know T& must be IPlayer and not a Poco::Int8. I only found on post about this error but with no answer.. (viewtopic.php?f=12&t=4988&p=7913&hilit=TypeHandler#p7913)

HerveM
HerveM
 
Posts: 5
Joined: 19 Dec 2012, 17:25

Re: TypeHandler Weird Error

Postby HerveM » 09 May 2013, 19:05

I tested a implementation like in the MySQL testsuite but don't run.
Only difference is that in Test, they use struct and I use class like in the documentation.
Code: Select all
#include <Poco\Data\TypeHandler.h>
#include "IPlayer.h"

namespace Poco {
namespace Data {

   template<>
   class TypeHandler<class IPlayer>
   {
   public:
      static std::size_t size()
      {
         return 7;
      }

      static void bind(std::size_t pos, const IPlayer& obj, AbstractBinder* pBinder){
          poco_assert_dbg (pBinder != 0);
          pBinder->bind(pos++, obj.sID);
          pBinder->bind(pos++, obj.sName);
          pBinder->bind(pos++, obj.sMail);
          pBinder->bind(pos++, obj.sPwd);
          pBinder->bind(pos++, obj.sRole);
          pBinder->bind(pos++, obj.sDateCreation);
          pBinder->bind(pos++, obj.sDateLastCnx);
      }

      static void prepare(std::size_t pos, const IPlayer& obj, AbstractPreparation* pPrepare){
         poco_assert_dbg (pPrepare != 0);
         pPrepare->prepare(pos++, obj.sID);
         pPrepare->prepare(pos++, obj.sName);
         pPrepare->prepare(pos++, obj.sMail);
         pPrepare->prepare(pos++, obj.sPwd);
         pPrepare->prepare(pos++, obj.sRole);
         pPrepare->prepare(pos++, obj.sDateCreation);
         pPrepare->prepare(pos++, obj.sDateLastCnx);
      }

      static void extract(std::size_t pos, IPlayer& obj, const IPlayer& defVal, AbstractExtractor* pExt){
         poco_assert_dbg (pExt != 0);
         if(!pExt->extract(pos++, obj.sID))
            obj.sID = defVal.sID;
         if(!pExt->extract(pos++, obj.sName))
            obj.sName = defVal.sName;
         if(!pExt->extract(pos++, obj.sMail))
            obj.sMail = defVal.sMail;
         if(!pExt->extract(pos++, obj.sPwd))
            obj.sPwd = defVal.sPwd;
         if(!pExt->extract(pos++, obj.sRole))
            obj.sRole = defVal.sRole;
         if(!pExt->extract(pos++, obj.sDateCreation))
            obj.sDateCreation = defVal.sDateCreation;
         if(!pExt->extract(pos++, obj.sDateLastCnx))
            obj.sDateLastCnx = defVal.sDateLastCnx;
      }
   private:
      TypeHandler();
      ~TypeHandler();
      TypeHandler(const TypeHandler&);
      TypeHandler& operator=(const TypeHandler&);
   };
}}

Code: Select all
#pragma once

#include <string>

class IPlayer
{
public:
   IPlayer(void);
   ~IPlayer(void);

   const std::string operator() () const { return sID; };
   bool operator < (const IPlayer& p) const
   {
      if(sID < p.sID)
         return true;
      if(sName < p.sName)
         return true;
      if(sMail < p.sMail)
         return true;
      if(sPwd < p.sPwd)
         return true;
      if(sRole < p.sRole)
         return true;
      if(sDateCreation < p.sDateCreation)
         return true;
      return sDateLastCnx < p.sDateLastCnx;
   };

   std::string sID;
   std::string sName;
   std::string sMail;
   std::string sPwd;
   std::string sRole;
   std::string sDateCreation;
   std::string sDateLastCnx;
};

Build error output :
1>------ Build started: Project: Server_Imp, Configuration: Release Win32 ------
1> SubMySQL.cpp
1> D:\Projet\Cpp\PW_LON\INCLUDE\Poco/Data/TypeHandler.h(135): error C2664: 'bool Poco::Data::AbstractExtractor::extract(size_t,Poco::Int8 &)' : cannot convert parameter 2 from 'IPlayer' to 'Poco::Int8 &'
1> D:\Projet\Cpp\PW_LON\INCLUDE\Poco/Data/TypeHandler.h(133) : while compiling class template member function 'void Poco::Data::TypeHandler<T>::extract(size_t,T &,const T &,Poco::Data::AbstractExtractor *)'
1> with
1> [
1> T=IPlayer
1> ]
1> D:\Projet\Cpp\PW_LON\INCLUDE\Poco/Data/Extraction.h(154) : see reference to function template instantiation 'void Poco::Data::TypeHandler<T>::extract(size_t,T &,const T &,Poco::Data::AbstractExtractor *)' being compiled
1> with
1> [
1> T=IPlayer
1> ]
1> D:\Projet\Cpp\PW_LON\INCLUDE\Poco/Data/Extraction.h(138) : see reference to class template instantiation 'Poco::Data::TypeHandler<T>' being compiled
1> with
1> [
1> T=IPlayer
1> ]
1> D:\Projet\Cpp\PW_LON\INCLUDE\Poco/Data/Extraction.h(137) : while compiling class template member function 'size_t Poco::Data::Extraction<T>::numOfColumnsHandled(void) const'
1> with
1> [
1> T=std::vector<IPlayer>
1> ]
1> SubMySQL.cpp(76) : see reference to class template instantiation 'Poco::Data::Extraction<T>' being compiled
1> with
1> [
1> T=std::vector<IPlayer>
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
HerveM
 
Posts: 5
Joined: 19 Dec 2012, 17:25


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest