Hi Jean:
I Google a way to new this object in the static functor via
http://www.gamedev.net/community/forums/topic.asp?topic_id=305990,
RichardS pasted the HTTPDownloader class source code, he re-new the
HTTPDownloader object in his httpFetch static functor.
Thanks Jean again ^_^
sirtoozee
2007/11/23, Jean-Philippe Barrette-LaPierre <jpb_at_rrette.com>:
>
> On 22-Nov-07, at 9:15 PM, sirtoozee wrote:
>
> > Hi curlpp geek:
> >
> > I read the source code of the example05.cpp(Function functor for
> > WriteFunction example), the callback WriteMemoryCallback must be
> > declared static, otherwise it won't link...
> >
> > So it acts like a class member use a static function pointer only
> > based on curl but not curlpp, such as
>
> Well, you can use expample06.cpp for home made functors, or just use
> the more versatile boost functor (which in fact uses home made
> functors),
> which is demonstrated in expample18.cpp
>
> All of these examples are in the latest release.
>
> >
> > static size_t
> > WriteFunction(char *ptr, size_t size, size_t nmemb, std::string
> > *stream)
> > {
> > if (stream == NULL)
> > {
> > return 0;
> > }
> >
> > stream->append(ptr, size * nmemb);
> > cout << ptr << endl;
> >
> > return size * nmemb;
> > }
> >
> > void *
> > CGI::Print()
> > {
> > curl_easy_setopt(this->curl, CURLOPT_WRITEDATA, &this->buffer);
> > curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteFunction);
> >
> > return NULL;
> > }
> >
> > When I even know the callback functor can not use a member function
> > pointer, I still modified the example05.cpp to see whether it work or
> > not, such as:
> >
> > size_t
> > Callback::WriteMemoryCallback(char* ptr, size_t size, size_t nmemb)
> > {
> > size_t realsize = size * nmemb;
> >
> > this->m_pBuffer = (char*) this->Realloc(this->m_pBuffer,
> > this->m_Size + realsize);
> >
> > if (this->m_pBuffer == NULL) {
> > realsize = 0;
> > }
> >
> > memcpy(&(this->m_pBuffer[this->m_Size]), ptr, realsize);
> > this->m_Size += realsize;
> >
> > return realsize;
> > };
> >
> > void Callback::print()
> > {
> > cURLpp::Types::WriteFunctionFunctor functor(this-
> > >*WriteMemoryCallback);
> > cURLpp::Options::WriteFunction *test = new
> > cURLpp::Options::WriteFunction(functor);
> > this->request.setOpt(test);
> > this->request.perform();
> >
> > std::cout << "Content: " << std::endl << this->m_pBuffer <<
> > std::endl;
> > }
> >
> > And yes '((Callback*)this)->Callback::WriteMemoryCallback' cannot be
> > used as a member pointer, since it is of type '<unresolved overloaded
> > function type>'
> >
> > So the C++ wrapper of curl still can not make callback functor to use
> > the member function pointer, right?
> >
> > sirtoozee
> >
> > --
> > An individual human existence should be like a river - small at first,
> > narrowly contained within its banks, and rushing passionately past
> > boulders and over waterfalls. Gradually the river grows wider, the
> > banks recede, the waters flow more quietly, and in the end, without
> > any visible break, they become merged in the sea, and painlessly lose
> > their individual being.
> > _______________________________________________
> > cURLpp mailing list
> > cURLpp_at_rrette.com
> > http://www.rrette.com/mailman/listinfo/curlpp
>
> _______________________________________________
> cURLpp mailing list
> cURLpp_at_rrette.com
> http://www.rrette.com/mailman/listinfo/curlpp
>
--
An individual human existence should be like a river - small at first,
narrowly contained within its banks, and rushing passionately past
boulders and over waterfalls. Gradually the river grows wider, the
banks recede, the waters flow more quietly, and in the end, without
any visible break, they become merged in the sea, and painlessly lose
their individual being.
_______________________________________________
cURLpp mailing list
cURLpp_at_rrette.com
http://www.rrette.com/mailman/listinfo/curlpp
Received on 2007-11-24