Сравнить коммиты
10 Коммитов
138de1fe70
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 891f04064c | |||
| 5c8ec71bea | |||
| 8ae80f4cf1 | |||
| a8ac553361 | |||
| 6e057edf3b | |||
| b6d0cfc3e5 | |||
| 7a0450a4b9 | |||
| a03f162faf | |||
| dcfdc59a63 | |||
| 46e21dec49 |
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -1,2 +1,3 @@
|
||||
*.exe
|
||||
*.dSYM/
|
||||
/curl
|
||||
114
l03.cpp
114
l03.cpp
@@ -3,62 +3,114 @@
|
||||
#include "histogram.h"
|
||||
#include "svg.h"
|
||||
#include "text.h"
|
||||
//#include "mycheck.h"
|
||||
#include <curl/curl.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const size_t SCREEN_WIDTH = 80;
|
||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
||||
|
||||
struct Input
|
||||
{
|
||||
vector<double> numbers;
|
||||
size_t bin_count{};
|
||||
size_t IMAGE_WIDTH{};
|
||||
|
||||
};
|
||||
|
||||
Input input_data()
|
||||
Input input_data(istream &in, bool promt)
|
||||
{
|
||||
|
||||
size_t number_count, bin_count, IMAGE_WIDTH;
|
||||
size_t number_count, bin_count;
|
||||
|
||||
if (promt)
|
||||
{
|
||||
cerr << "Enter number count: ";
|
||||
cin >> number_count;
|
||||
}
|
||||
in >> number_count;
|
||||
|
||||
Input in;
|
||||
|
||||
cerr << " Input width of image, >70 but not >800 : ";
|
||||
cin >> in.IMAGE_WIDTH;
|
||||
|
||||
//size_t number_count = in.number_counts;
|
||||
|
||||
in.numbers.resize(number_count);
|
||||
Input input;
|
||||
|
||||
input.numbers.resize(number_count);
|
||||
if (promt)
|
||||
{
|
||||
cerr << "Enter numbers: ";
|
||||
// vector<double> numbers(number_count);
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < number_count; i++)
|
||||
{
|
||||
cin >> in.numbers[i];
|
||||
in >> input.numbers[i];
|
||||
}
|
||||
|
||||
if (promt)
|
||||
{
|
||||
cerr << "Count of baskets: ";
|
||||
cin >> in.bin_count;
|
||||
}
|
||||
in >> input.bin_count;
|
||||
|
||||
return in;
|
||||
return input;
|
||||
}
|
||||
size_t
|
||||
write_data(void *items, size_t item_size, size_t item_count, void *ctx)
|
||||
{
|
||||
size_t data_size = item_count * item_size;
|
||||
|
||||
stringstream *buffer = reinterpret_cast<stringstream *>(ctx);
|
||||
char *item = reinterpret_cast<char *>(items);
|
||||
//(*buffer).write(item, data_size);
|
||||
buffer->write(item, data_size);
|
||||
|
||||
return data_size;
|
||||
}
|
||||
|
||||
int main()
|
||||
Input download(const string &address)
|
||||
{
|
||||
stringstream buffer;
|
||||
|
||||
// address.c_str();
|
||||
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
CURLcode res;
|
||||
double total;
|
||||
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||
|
||||
res = curl_easy_perform(curl);
|
||||
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
|
||||
auto in = input_data();
|
||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||
//int chek_block_width(in.IMAGE_WIDTH);
|
||||
//chek_block_width(in.IMAGE_WIDTH, in.number_count);
|
||||
//if (chek_block_width==1)
|
||||
show_histogram_svg(bins,in.IMAGE_WIDTH);
|
||||
//if(chek_block_width==0) return 0;
|
||||
//show_histogram_svg(bins);
|
||||
|
||||
fprintf(stderr, "curl_easy_perform() failed: %s\n",
|
||||
curl_easy_strerror(res));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (CURLE_OK == res)
|
||||
{
|
||||
res = curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &total);
|
||||
cerr << "Time spending for downloading file: " << total << endl;
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
}
|
||||
|
||||
return input_data(buffer, false);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
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);
|
||||
}
|
||||
Ссылка в новой задаче
Block a user