Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 111: change all examples to eliminate deprecated class. #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions examples/example00.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* \file
* The most simple example.
*
*
*/

#include <curlpp/cURLpp.hpp>
@@ -15,8 +15,7 @@ int main(int, char **)
{
try
{
// That's all that is needed to do cleanup of used resources (RAII style).
curlpp::Cleanup myCleanup;
curlpp::initialize();

// Our request to be sent.
curlpp::Easy myRequest;
@@ -38,6 +37,8 @@ int main(int, char **)
{
std::cout << e.what() << std::endl;
}

return 0;

curlpp::terminate();

return 0;
}
48 changes: 25 additions & 23 deletions examples/example01.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
/*
* Copyright (c) <2002-2005> <Jean-Philippe Barrette-LaPierre>
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (curlpp), to deal in the Software without restriction,
* a copy of this software and associated documentation files
* (curlpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/**
* \file
* Setting and copying options.
*
*
*/


@@ -42,14 +42,14 @@ namespace
const long MyPort = 80;
}

/**
/**
* This example is made to show you how you can use the Options.
*/
int main(int, char **)
{
try
{
curlpp::Cleanup myCleanup;
curlpp::initialize();

// First easy example.
{
@@ -65,11 +65,11 @@ int main(int, char **)

// More elaborate example.
{
// What the previous example done there was simply
// What the previous example done there was simply
// to create a curlpp::Easy class, which is the basic
// object in cURLpp, and then set the Url option.
// curlpp::options classes are the primitives that allow to specify
// values to the requests.
// curlpp::options classes are the primitives that allow to specify
// values to the requests.
curlpp::options::Url myUrl(std::string("http://example.com"));
curlpp::Easy myRequest;
myRequest.setOpt(myUrl);
@@ -81,7 +81,7 @@ int main(int, char **)
myRequest.perform();

// If we wanted to put the content of the URL within a string stream
// (or any type of std::ostream, for that matter), like the first example,
// (or any type of std::ostream, for that matter), like the first example,
// we would use the WriteStrem option like this:
std::ostringstream os;
curlpp::options::WriteStream ws(&os);
@@ -112,23 +112,23 @@ int main(int, char **)
myRequest.setOpt(*mytest);

// You can reuse the base option for other type of option
// and set the option to the request. but first, don't forget
// to delete the previous memory. You can delete it since the
// and set the option to the request. but first, don't forget
// to delete the previous memory. You can delete it since the
// option is internally duplicated for the request.
delete mytest;
mytest = myPort.clone();
myRequest.setOpt(*mytest);
delete mytest;

// You can clone an option directly to the same type of
// You can clone an option directly to the same type of
// option.
curlpp::options::Url *myUrl3 = myUrl.clone();
myRequest.setOpt(myUrl3);
// Now myUrl3 is owned by the request we will NOT use
// Now myUrl3 is owned by the request we will NOT use
// it anymore.


// You don't need to declare an option if you just want
// You don't need to declare an option if you just want
// to use it once.
myRequest.setOpt(curlpp::options::Url("example.com"));

@@ -166,6 +166,8 @@ int main(int, char **)
{
std::cout << e.what() << std::endl;
}

return 0;

curlpp::terminate();

return 0;
}
32 changes: 16 additions & 16 deletions examples/example02.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
* Copyright (c) <2002-2005> <Jean-Philippe Barrette-LaPierre>
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (curlpp), to deal in the Software without restriction,
* a copy of this software and associated documentation files
* (curlpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
@@ -37,7 +37,7 @@
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Exception.hpp>

/*
anonymous namespace to prevent name clash in case other examples using the same global entities
would be compiled in the same project
@@ -59,8 +59,8 @@ int main(int argc, char *argv[])
{
if(argc != 3)
{
std::cerr << "Example 2: Missing argument" << std::endl
<< "Example 2: Usage: example02 url string-to-send"
std::cerr << "Example 2: Missing argument" << std::endl
<< "Example 2: Usage: example02 url string-to-send"
<< std::endl;
return EXIT_FAILURE;
}
@@ -72,12 +72,12 @@ int main(int argc, char *argv[])
char buf[50];
try
{
curlpp::Cleanup cleaner;
curlpp::initialize();
curlpp::Easy request;

std::list<std::string> headers;
headers.push_back("Content-Type: text/*");
sprintf(buf, "Content-Length: %d", size);
headers.push_back("Content-Type: text/*");
sprintf(buf, "Content-Length: %d", size);
headers.push_back(buf);

using namespace curlpp::Options;
@@ -98,7 +98,7 @@ int main(int argc, char *argv[])
{
std::cout << e.what() << std::endl;
}
curlpp::terminate();

return 0;
}

30 changes: 15 additions & 15 deletions examples/example03.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/*
* Copyright (c) <2002-2005> <Jean-Philippe Barrette-LaPierre>
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
* (curlpp), to deal in the Software without restriction,
* a copy of this software and associated documentation files
* (curlpp), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so,
* and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
@@ -50,18 +50,18 @@ int main(int argc, char *argv[])

if(argc != 2)
{
std::cerr << "Example 3: Wrong number of arguments" << std::endl
<< "Example 3: Usage: example3 url"
std::cerr << "Example 3: Wrong number of arguments" << std::endl
<< "Example 3: Usage: example3 url"
<< std::endl;
return EXIT_FAILURE;
}
char *url = argv[1];

MyWindow myWindow;

try
try
{
curlpp::Cleanup cleaner;
curlpp::initialize();
curlpp::Easy request;

using namespace curlpp::Options;
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
request.perform();
}

catch ( curlpp::LogicError & e )
catch ( curlpp::LogicError & e )
{
std::cout << e.what() << std::endl;
}
@@ -82,7 +82,7 @@ int main(int argc, char *argv[])
{
std::cout << e.what() << std::endl;
}
curlpp::terminate();

return 0;
}

Loading