code: Сохранение данных из сети в буфер(WIP)

main
VeretennikovMA 11 месяцев назад
Родитель 2e7aee8210
Сommit 12e53cae4c

@ -13,7 +13,12 @@
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add directory="C:/Users/al/Desktop/cs-lab34/curl/include" />
</Compiler>
<Linker>
<Add library="libcurl.dll.a" />
<Add directory="C:/Users/al/Desktop/cs-lab34/curl/lib" />
</Linker>
</Target>
<Target title="Release">
<Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" />

@ -5,6 +5,7 @@
#include "svg.h"
#include <string>
#include <curl/curl.h>
#include <sstream>
using namespace std;
@ -16,50 +17,61 @@ struct Input {
};
Input
input_data(istream& Newcin){
input_data(istream& Newcin, bool prompt){
size_t number_count;
cerr << "Enter number count: ";
Newcin >> number_count;
bool prompt;
cerr << "Do you want any prompts? Enter 'true' if yes, 'false' if no: ";
Newcin >> prompt;
cin >> number_count;
if (prompt){
cerr << "Prompt";
cerr << "Prompt" << endl;
}
Input in;
in.numbers.resize(number_count);
cerr << "Enter numbers: ";
for (size_t i = 0; i < number_count; i++) {
Newcin >> in.numbers[i];
cin >> in.numbers[i];
}
cerr << "Enter bin count: ";
Newcin >> in.bin_count;
cin >> in.bin_count;
cerr << "Enter stroke in format RGB: ";
Newcin >> in.stroke;
cin >> in.stroke;
cerr << "Enter fill in format RGB: ";
Newcin >> in.fill;
cin >> in.fill;
return in;
}
Input
download(const string& address) {
curl_global_init(CURL_GLOBAL_ALL);
stringstream buffer;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, address);
res = curl_easy_perform(curl);
if (res != 0){
cout << curl_easy_strerror(res);
exit(1);
}
}
curl_easy_cleanup(curl);
return input_data(buffer, false);
}
size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
return 0;
}
int
main(int argc, char* argv[]) {
Input input;
if (argc > 1) {
CURL *curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
res = curl_easy_perform(curl);
if (res != 0){
cout << curl_easy_strerror(res);
exit(1);
}
curl_easy_cleanup(curl);
}
return 0;
input = download(argv[1]);
} else {
input = input_data(cin, true);
}
curl_global_init(CURL_GLOBAL_ALL);
auto in = input_data(cin);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins, in.stroke, in.fill);
const auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins);
}

@ -26,7 +26,7 @@ svg_rect(double x, double y, double width, double height, string stroke, string
cout << "<rect x='" << x << "' y='" << y <<"' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "'/>";
}
void
show_histogram_svg(const vector<size_t>& bins, string stroke, string fill) {
show_histogram_svg(const vector<size_t>& bins) {
const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20;
@ -48,7 +48,7 @@ show_histogram_svg(const vector<size_t>& bins, string stroke, string fill) {
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
svg_end();
@ -58,7 +58,7 @@ show_histogram_svg(const vector<size_t>& bins, string stroke, string fill) {
for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin * kf;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, stroke, fill);
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
top += BIN_HEIGHT;
}
svg_end();

@ -12,4 +12,4 @@ svg_text(double left, double baseline, std::string text);
void
svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black");
void
show_histogram_svg(const std::vector<size_t>& bins, std::string stroke, std::string fill);
show_histogram_svg(const std::vector<size_t>& bins);

Загрузка…
Отмена
Сохранить