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

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

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

@ -5,6 +5,7 @@
#include "svg.h" #include "svg.h"
#include <string> #include <string>
#include <curl/curl.h> #include <curl/curl.h>
#include <sstream>
using namespace std; using namespace std;
@ -16,50 +17,61 @@ struct Input {
}; };
Input Input
input_data(istream& Newcin){ input_data(istream& Newcin, bool prompt){
size_t number_count; size_t number_count;
cerr << "Enter number count: "; cerr << "Enter number count: ";
Newcin >> number_count; cin >> number_count;
bool prompt;
cerr << "Do you want any prompts? Enter 'true' if yes, 'false' if no: ";
Newcin >> prompt;
if (prompt){ if (prompt){
cerr << "Prompt"; cerr << "Prompt" << endl;
} }
Input in; Input in;
in.numbers.resize(number_count); in.numbers.resize(number_count);
cerr << "Enter numbers: "; cerr << "Enter numbers: ";
for (size_t i = 0; i < number_count; i++) { for (size_t i = 0; i < number_count; i++) {
Newcin >> in.numbers[i]; cin >> in.numbers[i];
} }
cerr << "Enter bin count: "; cerr << "Enter bin count: ";
Newcin >> in.bin_count; cin >> in.bin_count;
cerr << "Enter stroke in format RGB: "; cerr << "Enter stroke in format RGB: ";
Newcin >> in.stroke; cin >> in.stroke;
cerr << "Enter fill in format RGB: "; cerr << "Enter fill in format RGB: ";
Newcin >> in.fill; cin >> in.fill;
return in; return in;
} }
int Input
main(int argc, char* argv[]) { download(const string& address) {
if (argc > 1) { curl_global_init(CURL_GLOBAL_ALL);
stringstream buffer;
CURL *curl = curl_easy_init(); CURL *curl = curl_easy_init();
if(curl) { if(curl) {
CURLcode res; CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, argv[1]); curl_easy_setopt(curl, CURLOPT_URL, address);
res = curl_easy_perform(curl); res = curl_easy_perform(curl);
if (res != 0){ if (res != 0){
cout << curl_easy_strerror(res); cout << curl_easy_strerror(res);
exit(1); exit(1);
} }
}
curl_easy_cleanup(curl); 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; return 0;
} }
curl_global_init(CURL_GLOBAL_ALL);
auto in = input_data(cin); int
auto bins = make_histogram(in.numbers, in.bin_count); main(int argc, char* argv[]) {
show_histogram_svg(bins, in.stroke, in.fill); Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(cin, true);
}
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 << "'/>"; cout << "<rect x='" << x << "' y='" << y <<"' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "'/>";
} }
void 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_WIDTH = 400;
const auto IMAGE_HEIGHT = 300; const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20; 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) { for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin; const double bin_width = BLOCK_WIDTH * bin;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(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; top += BIN_HEIGHT;
} }
svg_end(); svg_end();
@ -58,7 +58,7 @@ show_histogram_svg(const vector<size_t>& bins, string stroke, string fill) {
for (size_t bin : bins) { for (size_t bin : bins) {
const double bin_width = BLOCK_WIDTH * bin * kf; const double bin_width = BLOCK_WIDTH * bin * kf;
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(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; top += BIN_HEIGHT;
} }
svg_end(); svg_end();

@ -12,4 +12,4 @@ svg_text(double left, double baseline, std::string text);
void void
svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black"); svg_rect(double x, double y, double width, double height, std::string stroke = "black", std::string fill = "black");
void 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);

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