#include using namespace std; #include "histogram.h" #include "text.h" #include "svg.h" #include #include struct Input { std::vector numbers; size_t bin_count{}; }; Input input_data(istream& in, bool promt); Input download(const string& address); int main(int argc, char* argv[]) { curl_global_init(CURL_GLOBAL_ALL); Input input; if(argc > 1 ){ input = download(argv[1]); }else{ input = input_data(cin,true); } std::vector bins = make_histogram(input.numbers, input.bin_count); show_histogram_svg(bins); return 0; } Input download(const string& address) { stringstream buffer; CURL* curl = curl_easy_init(); if(curl) { CURLcode res; curl_easy_setopt(curl, CURLOPT_URL, address); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, input_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); res = curl_easy_perform(curl); if(res!=0){ cout << curl_easy_strerror(res) << endl; 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) { size_t data_size = item_size * item_count; stringstream* buffer = reinterpret_cast(ctx); buffer->write(reinterpret_cast(items), data_size); return data_size; } Input input_data(istream& in, bool promt) { Input input_struct; size_t countOfNumbers; if(promt){cerr << "Input your count of numbers:\n";} in >> countOfNumbers; input_struct.numbers.resize(countOfNumbers); if(promt){cerr << "Input numbers:\n";} for (int i = 0; i < countOfNumbers; i++) { if(promt){cerr << i << ":" << endl;} in >> input_struct.numbers[i]; } if(promt){ cerr << endl; cerr << "Input bin count:\n"; } in >> input_struct.bin_count; return input_struct; }