From e37945362ea047b9d5dd4c6107d4afa5f6911a40 Mon Sep 17 00:00:00 2001 From: ksv Date: Sun, 27 Mar 2022 18:21:03 +0300 Subject: [PATCH] Initial commit --- .gitignore | 1 + CMakeLists.txt | 12 ++++++++++++ ConverterJSON.cpp | 11 +++++++++++ ConverterJSON.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ main.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 114 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 ConverterJSON.cpp create mode 100644 ConverterJSON.h create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4a25d57 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..fadb50d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.21) +project(search_engine) +include(FetchContent) + +set(CMAKE_CXX_STANDARD 14) + +FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.10.5/json.tar.xz) +FetchContent_MakeAvailable(json) + +add_executable(search_engine main.cpp ConverterJSON.cpp ConverterJSON.h) + +target_link_libraries(search_engine PRIVATE nlohmann_json::nlohmann_json) \ No newline at end of file diff --git a/ConverterJSON.cpp b/ConverterJSON.cpp new file mode 100644 index 0000000..d5c5892 --- /dev/null +++ b/ConverterJSON.cpp @@ -0,0 +1,11 @@ +// +// Created by ksv on 27.03.2022. +// + +#include "ConverterJSON.h" + +std::vector ConverterJSON::GetTextDocuments() { + std::vector response = std::vector(); + + return response; +} diff --git a/ConverterJSON.h b/ConverterJSON.h new file mode 100644 index 0000000..cfb0f4e --- /dev/null +++ b/ConverterJSON.h @@ -0,0 +1,44 @@ +#include +#include +#include + +#include "nlohmann/json.hpp" + +struct config_json { + struct { + std::string name; + std::string version; + int max_responses; + } config; + std::vector files; +}; + +/** +* Класс для работы с JSON-файлами +*/ +class ConverterJSON { +public: + ConverterJSON() = default; +/** +* Метод получения содержимого файлов +* @return Возвращает список с содержимым файлов перечисленных +* в config.json +*/ + std::vector GetTextDocuments(); +/** +* Метод считывает поле max_responses для определения предельного +* количества ответов на один запрос +* @return +*/ + int GetResponsesLimit(); +/** +* Метод получения запросов из файла requests.json +* @return возвращает список запросов из файла requests.json +*/ + std::vector GetRequests(); +/** +* Положить в файл answers.json результаты поисковых запросов +*/ + void putAnswers(std::vector>> + answers); +}; \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..7f1d32f --- /dev/null +++ b/main.cpp @@ -0,0 +1,46 @@ +#include + +#include "ConverterJSON.h" + +int main() { + + auto config_file = std::ifstream("config.json"); + + if(!config_file.is_open()){ + std::cerr << "config file is missing." << std::endl; + return 1; + } + + nlohmann::json conf; + config_file >> conf; + + auto cf = config_json(); + + if(conf["config"].is_null()){ + std::cerr << "config file is empty." << std::endl; + return 1; + } + + if(!conf["config"]["name"].is_null()){ + cf.config.name = conf["config"]["name"]; + }else{ + cf.config.name = "Undefined"; + } + if(!conf["config"]["version"].is_null()) { + cf.config.version = conf["config"]["version"]; + } + cf.config.max_responses = conf["config"]["max_responses"]; + + for (auto f: conf["files"]) { + cf.files.push_back(f); + } + + std::cout << cf.config.name << ((cf.config.version == "")? "" : " version: ") << cf.config.version << std::endl; + +// for (auto f: cf.files) { +// std::cout << f << std::endl; +// } + + return 0; + +}