/
Alexandr_Pidkasisty
/
froma2
Обзор
Документация
Войти
/
Alexandr_Pidkasisty
/
froma2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
libsource/Impex_lib.cpp
549 строк
38 KB
Alexandr Pidkasisty
Скорректировал комментарии у метода Import_Recipes
03 авг 2026, 21:45
Верифицирован
03 авг 2026, 21:45
96a4263
Код
Авторство
О чём код?
/** ���� ���� �������� ������ ���������� ������������ ����������� ��� �������������� �������������, ����������� ������� � ������������ ������������ ������������ ����������� "Free Operation Manager 2" (���������� FROMA2). **/ /****************************************************************************************************/ /****************************************************************************************************/ /*** ***/ /*** Copyright � 2025 ����������� ��������� �������� ***/ /*** ***/ /*** ������ �������� ��������� �����, ���������� ����� ������� ������������ ����������� � ***/ /*** ������������� ������������ (����� � ����������� �����������), ������������ ������������ ***/ /*** ����������� ����������� ��� �����������, ������� �������������� ����� �� �������������, ***/ /*** �����������, ���������, �������, ����������, ���������������, ����������������� �/��� ***/ /*** ������� ����� ������������ �����������, � ����� �����, ������� ��������������� ������ ***/ /*** ����������� �����������, ��� ���������� ��������� �������: ***/ /*** ***/ /*** ��������� ���� ����������� �� ��������� ����� � ������ ������� ������ ���� �������� �� ***/ /*** ��� ����� ��� �������� ����� ������� ������������ �����������. ***/ /*** ***/ /*** ������ ����������� ����������� ��������������� ���� ���ܻ, ��� �����-���� ��������, ���� ***/ /*** ���������� ��� ���������������, ������� �������� �������� �����������, ������������ �� ***/ /*** ��� ����������� ���������� � ���������� ���������, �� �� ������������� ���. �� � ����� ***/ /*** ������ ������ ��� ��������������� �� ����� ��������������� �� �����-���� �����, �� ����� ***/ /*** ��� �� ���� �����������, � ��� �����, ��� �������� ���������, ������� ��� ���� ��������, ***/ /*** ��������� ��-�� ������������� ������������ ����������� ��� ���� �������� � ����������� ***/ /*** ������������. ***/ /*** ***/ /****************************************************************************************************/ /****************************************************************************************************/ #include "impex_module.h" #include <limits> const unsigned short int mant = std::numeric_limits<double>::max_digits10; /** ���������� �������� ������������� ����� double, ������������� ��� ������ ������ � ����� � ������ clsImpex::Import ��� ������� ������ �� �������� ���� strItem (�� ��������� ����� 17), �� https://iq.opengenus.org/print-double-with-full-precision-in-cpp **/ /*************************************************************************************************************************/ /** ����� clsImpex ��� ������� ���������� �� cvs-������ **/ /** � ���������� �������� ������ ��� �������� ���� clsStorage � clsManufactory **/ /*************************************************************************************************************************/ clsImpex::clsImpex() { /** ����������� �� ��������� **/ m_rowcount = m_colcount = nmBPTypes::sZero; // �������� �������� separator = ';'; // ������������� ��������� �� ��������� } // Default Ctor clsImpex::clsImpex(ifstream& ifs, const char& ch) { /** ����������� � ����������. ���������: ifs - �������� ����� �� ������, ch - ������ ����������� ����� ������� � ����� **/ m_rowcount = m_colcount = nmBPTypes::sZero; // �������� �������� separator = ';'; // ������������� ��������� �� ��������� if(!ifs.is_open()) return; // ���� ���� �� ������, �� ����� if(!Import(ifs, ch)) // ������ ������ �� �����. ���� ��������, �� reset(); // ���������� ��������� ������� } // Ctor with parametr clsImpex::clsImpex(const size_t ncount, const nmBPTypes::strNameMeas names[],\ const nmBPTypes::strItem data[], const size_t dcount, nmBPTypes::ReportData flg) { /** ����������� � ����������� ��� ������� �� ��������. ���������: const size_t ncount - ����� �����, ������ ����� ��������� ������� names[] � �������������� �����, names[] - ������ � �������������� ����� � ��������� ���������, data[] - ���������� ������, ������ ��������� ������� �������� ncount*dcount � �������, dcount - ����� �������� �������, flg - ����, ������������ ��� ������������ ������: volume, price ��� value. **/ m_rowcount = m_colcount = nmBPTypes::sZero; // �������� �������� separator = ';'; // ������������� ��������� �� ��������� if((ncount==nmBPTypes::sZero) || (!names) || (!data) || (dcount==nmBPTypes::sZero)) return; // ���� ������� �� ����������, �� ����� if(!Import(ncount, names, data, dcount, flg)) // ������ ������ �� �������. ���� ��������, �� reset(); // ���������� ��������� ������� } // Ctor with parametr clsImpex::clsImpex(const clsImpex& other) { /** ����������� ����������� **/ m_rowcount = other.m_rowcount; m_colcount = other.m_colcount; separator = other.separator; m_data = other.m_data; } //Copy ctor clsImpex::clsImpex(clsImpex&& other) { /** ����������� ����������� **/ swap(other); } // Move Ctor void clsImpex::swap(clsImpex& other) noexcept { /** ������� ������ ����������� �������� **/ std::swap(m_rowcount, other.m_rowcount); // ���������� �������� std::swap(m_colcount, other.m_colcount); std::swap(separator, other.separator); m_data.swap(other.m_data); } // swap clsImpex& clsImpex::operator=(const clsImpex& rhs) { /** �������� ������������ ������������ **/ if (this == &rhs) return *this; // handle self assignment clsImpex temp(rhs); // ��������������� ���������� ��������� ������������ �� rhs swap(temp); // ����� �� ��������������� ���������� return *this; } // Copy assignment operator clsImpex& clsImpex::operator=(clsImpex &&rhs) { /** ���������� ��������� ������������ ������������ ������������ ������� **/ if (this == &rhs) return *this; // handle self assignment swap(rhs); // ������������ � �������� ����������� return *this; } // Move assignment operator void clsImpex::reset() { /** ���������� ��������� ������� �� �������� �� ���������. ����� vector::clear �� ����������� ��������� ����������������� ������, ����������� ���� ����� ������������ ��� ������������ ��� (http://cplusplus.com/reference/vector/vector/clear) **/ m_rowcount = m_colcount = nmBPTypes::sZero; // �������� ��������, separator = ';'; // ������������� ��������� �� ��������� vector<std::vector<std::string>>().swap(m_data); // �������� ������ � ��������� �� ��������� } // reset bool clsImpex::is_Empty() const { /** ���������� true, ���� m_data ������ **/ if(m_data.size() == 0) return true; else return false; } // is_Empty /** ������ ������� **/ bool clsImpex::Import(ifstream& ifs, const char& ch) { /** ����� ����������� ������ �� �����, ���������� � ������� ifs, � �������� ����������� ������������ ������ ch **/ if((m_rowcount>nmBPTypes::sZero) || (m_colcount>nmBPTypes::sZero) || (m_data.size()>nmBPTypes::sZero))\ return false; // �������� �� ������� ������ if(!ifs.is_open()) { // ���� ���� �� ������, �� return false; // ������� � ���������� false }; size_t tmpcount; // ��������������� ������� ��������� ��� �������� "���������������" ������� ������� for (string line; getline(ifs, line);) { // ������ � line ������ ������ ����� if(ifs.bad()) { // ���� ������ �� ����� �� �������, �� return false; // � ������� � false }; m_rowcount++; // � ����������� ������� ����� istringstream ss(std::move(line)); // � ���������� ���������� ������ � ��������� ����� ss vector<std::string> row; // ��������������� ������ ��� ������ if(!m_data.empty()) // ���� �������� ������ �� ������, �� � �������������� ������� row.reserve(m_data.front().size()); // ����������� ������ �������� � ������ ������� tmpcount = m_colcount; // ������������� ��������������� ������� ������ ����������� �������� m_colcount m_colcount = nmBPTypes::sZero; // �������� ������� �������� for(string value; getline(ss, value, separator);) { // ��������� ������ �� ��������� ������, ����������� �������� ch m_colcount++; // ����������� ������� �������� row.push_back(std::move(value)); // ��������� ������ ����� ������ �� �������������� ������ }; if(tmpcount != nmBPTypes::sZero) if(tmpcount != m_colcount) { // ��������, ��� ���������� ����� ��������� �� ���� ������� return false; // � ������� � false }; m_data.push_back(std::move(row)); // ��������� �������������� ������ � ������� ��������� ������� }; return true; } // Import from file bool clsImpex::Import(const size_t ncount, const nmBPTypes::strNameMeas names[], const nmBPTypes::strItem data[],\ const size_t dcount, nmBPTypes::ReportData flg) { /** ����� ����������� ������ �� ��������. ���������: const size_t ncount - ����� �����, ������ ����� ��������� ������� names[] � �������������� �����, names[] - ������ � �������������� ����� � ��������� ���������, data[] - ���������� ������, ������ ��������� ������� �������� ncount*dcount � �������, dcount - ����� �������� �������, flg - ����, ������������ ��� ������������ ������: volume, price ��� value. **/ if((m_rowcount>nmBPTypes::sZero) || (m_colcount>nmBPTypes::sZero) || (m_data.size()>nmBPTypes::sZero)) return false; // �������� �� ������� ������; ���� ������ ��� ����, �� ����� � false if((ncount==nmBPTypes::sZero) || (!names) || (!data) || (dcount==nmBPTypes::sZero)) return false; // ���� ������� �� ����������, �� ����� m_rowcount = ncount + 1; // ���������� ����� � ������� m_colcount = dcount + 2; // ���������� �������� � ������� { // ���� ���������� ��� ����������� ��������� ���������������� ������� vector<std::string> frow; // ��������������� ������ ��� ������ m_data.reserve(m_rowcount); // ����������� ������ ��������� ������� frow.reserve(m_colcount); // ����������� ������ ���������������� ������� frow.push_back(nmPrntSetup::c_TableName); // ���������� ��������� "������������" frow.push_back(nmPrntSetup::c_TableMeas); // ���������� ��������� "��.���������" for(size_t j{}; j<dcount; j++) frow.push_back(std::to_string(j)); // ���������� ������ ������� m_data.push_back(std::move(frow)); // ��������� �������������� ������ � ������� ��������� ������� } // ����� ����� ����������, ��������������� ������ ������������ for(size_t i{}; i<ncount; i++) { // ���� �� ������� vector<std::string> row; // ��������������� ������ ��� ������ row.reserve(m_colcount); // ����������� ������ row.push_back((names+i)->name); // ��������� ������������ ������� row.push_back((names+i)->measure); // ��������� ������� ��������� for(size_t j{}; j<dcount; j++) { // ���� �� �������� stringstream ss; // ��������������� ����� if((flg==nmBPTypes::ReportData::volume) || (flg==nmBPTypes::ReportData::price)) // ���������� � ����� ������ if(flg==nmBPTypes::ReportData::volume) ss << lr_precision(ex_precision) << (data+dcount*i+j)->volume; else ss << lr_precision(ex_precision) << (data+dcount*i+j)->price; else ss << lr_precision(ex_precision) << (data+dcount*i+j)->value; row.push_back(std::move(ss.str())); // ��������� � ������ ������� }; m_data.push_back(std::move(row)); // ��������� �������������� ������ � ������� ��������� ������� }; return true; } // Import from massive /** ������ �������������� **/ void clsImpex::Transpon() { /** ����� ���������������� ������� m_data **/ if(m_data.size() == nmBPTypes::sZero) return; // ���� ������ ����, �� �� ������������� ��� vector<std::vector<std::string>> tmp; // ��������������� ������� for(size_t j=nmBPTypes::sZero; j<m_colcount; j++) { // ���� �� �������� vector<std::string> col; // ��������������� ������ ��� ������� if(!tmp.empty()) // ���� �������� ������ �� ������, �� � �������������� ������� col.reserve(tmp.front().size()); // ����������� ������ �������� � ������ ������� for(vector<std::string> row: m_data) { // ���� �� ������� vector<std::string>::const_iterator cit = row.begin()+j; // ������������� �������� �� j-� ������� ������ col.push_back(*cit); // ��������� ������� col ��� ����� ������� tmp } tmp.push_back(std::move(col)); // � ��������� ��� � ����� ������� }; m_data.swap(tmp); // ���������� ���������� ������� m_data � ����� ������� tmp std::swap(m_rowcount, m_colcount); // ���������� �������� � ��������� } // Transpon /** ������ �������� **/ void clsImpex::csvExport(ofstream& ofs) const { /** ����� �������� ������� � csv-���� � ������������, �������� � ���������� separator **/ for (const vector<string>& row : m_data) { for(const string& value: row) { ofs << lr_precision(ex_precision) << value << separator; } ofs << endl; }; } // csvExport /** ������ Get **/ decimal* clsImpex::GetDecimal(const size_t brow, const size_t erow,\ const size_t bcol, const size_t ecol) const { /** ����� ���������� ��������� � ������� ������, ���������������� � ��� decimal. ���������: brow - ��������� ������ ������, erow - �������� ������, bcol - ��������� �������, ecol - �������� �������. ����� ���������� ���������� ������������ ������, ���������� �������� ��������� ������� �������� (erow-brow+1)*(ecol-bcol+1). ��� � ������ ������ ��������� � �������, ������������ � �������� ���������� �������� ������� clsStorage � clsManufactory. ��������!!! ��� ������������� � ����������� ������� ������� clsStorage � clsManufactory ������� (� ������� m_data) � ���������������� ������� ������ ����� �������������� ���������� (������ ������� - � ������ ��������). � ��������� ������ ����� ����������� ���������� ������ ������� ���������� ���������������. **/ if((m_rowcount==nmBPTypes::sZero) || (m_colcount==nmBPTypes::sZero) ||\ (m_data.size()==nmBPTypes::sZero)) return nullptr; // �������� �� ������� ������ if((brow>=m_rowcount) || (erow>=m_rowcount) || (brow>erow) ||\ (bcol>=m_colcount) || (ecol>=m_colcount) || (bcol>ecol)) return nullptr; // �������� ������������ ���������� size_t trows = erow-brow+nmBPTypes::sOne; // ���������� ����� � �������� ������� size_t tcols = ecol-bcol+nmBPTypes::sOne; // ���������� �������� � �������� ������� decimal* dData = new(nothrow) decimal[trows*tcols]; // �������� ������ ������� if(!dData) return nullptr; // ���� ������ �� ��������, �� ����� � ������� nullptr vector<vector<string>>::const_iterator citrow; // �������� ��� ����� vector<string>::const_iterator citcell; // �������� ��� �������� size_t i=nmBPTypes::sZero; // ������ ������ for(citrow=m_data.cbegin()+brow; citrow<=m_data.cbegin()+erow; citrow++) { // ������� �� ������� size_t j=nmBPTypes::sZero; // ������ ������� for(citcell=(*citrow).cbegin()+bcol; citcell<=(*citrow).cbegin()+ecol; citcell++) { // ������� �� �������� stringstream ss; // ��������������� ����� ����� ss << *citcell; // ������ �� ������� � ����� ����� ss >> *(dData+tcols*i+j); // ������������ �� ������ � ����� j++; // �������� ������ ������� }; i++; // �������� ������ ������ }; return dData; } // GetDecimal template <typename T, class> T* clsImpex::GetData(const size_t brow, const size_t erow, const size_t bcol, const size_t ecol) const { /** ����� ���������� ��������� � ������� ������, ���������������� � ��� decimal, bool ��� size_t. ���������: brow - ��������� ������ ������, erow - �������� ������, bcol - ��������� �������, ecol - �������� �������. ����� ���������� ���������� ������������ ������, ���������� �������� ��������� ������� �������� (erow-brow+1)*(ecol-bcol+1). **/ if((m_rowcount==nmBPTypes::sZero) || (m_colcount==nmBPTypes::sZero) ||\ (m_data.size()==nmBPTypes::sZero)) return nullptr; // �������� �� ������� ������ if((brow>=m_rowcount) || (erow>=m_rowcount) || (brow>erow) ||\ (bcol>=m_colcount) || (ecol>=m_colcount) || (bcol>ecol)) return nullptr; // �������� ������������ ���������� size_t trows = erow-brow+nmBPTypes::sOne; // ���������� ����� � �������� ������� size_t tcols = ecol-bcol+nmBPTypes::sOne; // ���������� �������� � �������� ������� T* dData = new(nothrow) T[trows*tcols]; // �������� ������ ������� if(!dData) return nullptr; // ���� ������ �� ��������, �� ����� � ������� nullptr vector<vector<string>>::const_iterator citrow; // �������� ��� ����� vector<string>::const_iterator citcell; // �������� ��� �������� size_t i=nmBPTypes::sZero; // ������ ������ for(citrow=m_data.cbegin()+brow; citrow<=m_data.cbegin()+erow; citrow++) { // ������� �� ������� size_t j=nmBPTypes::sZero; // ������ ������� for(citcell=(*citrow).cbegin()+bcol; citcell<=(*citrow).cbegin()+ecol; citcell++) { // ������� �� �������� stringstream ss; // ��������������� ����� ����� ss << *citcell; // ������ �� ������� � ����� ����� ss >> *(dData+tcols*i+j); // ������������ �� ������ � ����� j++; // �������� ������ ������� }; i++; // �������� ������ ������ }; return dData; } // clsImpex::GetData template decimal* clsImpex::GetData<decimal>(const size_t brow, const size_t erow, const size_t bcol, const size_t ecol) const; template bool* clsImpex::GetData<bool>(const size_t brow, const size_t erow, const size_t bcol, const size_t ecol) const; template size_t* clsImpex::GetData<size_t>(const size_t brow, const size_t erow, const size_t bcol, const size_t ecol) const; /** ���� ��������� ���������� �������� ��� ����� decimal, bool � size_t **/ nmBPTypes::strNameMeas* clsImpex::GetNames(const size_t brow, const size_t erow,\ const size_t idName, const size_t idMeas) const { /** ����� ���������� ��������� � ������� ������, ���������������� � ��� strNameMeas. ���������: brow - ��������� ������ ������, erow - �������� ������, idName - ����� ������� � ����������, idMeas - ����� ������� � ��������� ���������. ����� ���������� ���������� ������������ ������ �������� (erow-brow+1). ��� � ������ ������ ��������� � �������, ������������ � �������� ���������� �������� ������� clsStorage � clsManufactory. ��������!!! ��� ������������� � ����������� ������� ������� clsStorage � clsManufactory ������� (� ������� m_data) � ���������������� ������� ������ ����� �������������� ���������� (������ ������� - � ������ ��������). � ��������� ������ ����� ����������� ���������� ������ ������� ���������� ���������������. **/ if((m_rowcount==nmBPTypes::sZero) || (m_colcount==nmBPTypes::sZero) ||\ (m_data.size()==nmBPTypes::sZero)) return nullptr; // �������� �� ������� ������ if((idName>=m_colcount) || (idMeas>=m_colcount) ||\ (brow>=m_rowcount) || (erow>=m_rowcount) || (brow>erow)) return nullptr; // �������� ������������ ���������� size_t trows = erow-brow+nmBPTypes::sOne; // ���������� ����� � �������� ������� nmBPTypes::strNameMeas* dData = new(nothrow) nmBPTypes::strNameMeas[trows]; // �������� ������ ������� if(!dData) return nullptr; // ���� ������ �� ��������, �� ����� � ������� nullptr vector<vector<string>>::const_iterator citrow; // �������� ��� ����� size_t i=nmBPTypes::sZero; // ������ ������ for(citrow=m_data.cbegin()+brow; citrow<=m_data.cbegin()+erow; citrow++) { (dData+i)->name = *((*citrow).cbegin() + idName); // �������� ��� (dData+i)->measure = *((*citrow).cbegin() + idMeas); // �������� ������� ��������� i++; }; return dData; } // GetNames string* clsImpex::GetNames(const size_t brow, const size_t erow, const size_t idName) const { /** ����� ���������� ��������� � ������� ������, ���������������� � ��� string. ���������: brow - ��������� ������ ������, erow - �������� ������, idName - ����� ������� � ����������. ����� ���������� ���������� ������������ ������ �������� (erow-brow+1). ��������!!! ��� ������������� � ����������� ������� ������� clsStorage � clsManufactory ������� (� ������� m_data) � ���������������� ������� ������ ����� �������������� ���������� (������ ������� - � ������ ��������). � ��������� ������ ����� ����������� ���������� ������ ������� ���������� ���������������. **/ if((m_rowcount==nmBPTypes::sZero) || (m_colcount==nmBPTypes::sZero) ||\ (m_data.size()==nmBPTypes::sZero)) return nullptr; // �������� �� ������� ������ if((idName>=m_colcount) || \ (brow>=m_rowcount) || (erow>=m_rowcount) || (brow>erow)) return nullptr; // �������� ������������ ���������� size_t trows = erow-brow+nmBPTypes::sOne; // ���������� ����� � �������� ������� string* dData = new(nothrow) string[trows]; // �������� ������ ������� if(!dData) return nullptr; // ���� ������ �� ��������, �� ����� � ������� nullptr vector<vector<string>>::const_iterator citrow; // �������� ��� ����� size_t i=nmBPTypes::sZero; // ������ ������ for(citrow=m_data.cbegin()+brow; citrow<=m_data.cbegin()+erow; citrow++) { *(dData+i) = *((*citrow).cbegin() + idName); // �������� ��� i++; }; return dData; } // GetNames nmBPTypes::strItem* clsImpex::GetstrItem(const size_t brow, const size_t erow, const size_t bcol,\ const size_t ecol, nmBPTypes::ReportData flg) const { /** ����� ���������� ��������� � ������� ������, ���������������� � ����������� ��� strItem. ���������: brow - ��������� ������ ������, erow - �������� ������, bcol - ��������� �������, ecol - �������� �������, flg - ����, ������������ ������������ � ��������� ����: volume, price ��� value. ������������ ���� ����������� ������� �� �������, �������������� - ������. ����� ���������� ���������� ������������ ������, ���������� �������� ��������� ������� �������� (erow-brow+1)*(ecol-bcol+1). ��� � ������ ������ ��������� � �������, ������������ � �������� ���������� �������� ������� clsStorage � clsManufactory. ��������!!! ��� ������������� � ����������� ������� ������� clsStorage � clsManufactory ������� (� ������� m_data) � ���������������� ������� ������ ����� �������������� ���������� (������ ������� - � ������ ��������). � ��������� ������ ����� ����������� ���������� ������ ������� ���������� ���������������. **/ if((m_rowcount==nmBPTypes::sZero) || (m_colcount==nmBPTypes::sZero) ||\ (m_data.size()==nmBPTypes::sZero)) return nullptr; // �������� �� ������� ������ if((brow>=m_rowcount) || (erow>=m_rowcount) || (brow>erow) ||\ (bcol>=m_colcount) || (ecol>=m_colcount) || (bcol>ecol)) return nullptr; // �������� ������������ ���������� size_t trows = erow-brow+nmBPTypes::sOne; // ���������� ����� � �������� ������� size_t tcols = ecol-bcol+nmBPTypes::sOne; // ���������� �������� � �������� ������� nmBPTypes::strItem* dData = new(nothrow) nmBPTypes::strItem[trows*tcols]; // �������� ������ ������� if(!dData) return nullptr; // ���� ������ �� ��������, �� ����� � ������� nullptr vector<vector<string>>::const_iterator citrow; // �������� ��� ����� vector<string>::const_iterator citcell; // �������� ��� �������� size_t i=nmBPTypes::sZero; // ������ ������ for(citrow=m_data.cbegin()+brow; citrow<=m_data.cbegin()+erow; citrow++) { // ������� �� ������� size_t j=nmBPTypes::sZero; // ������ ������� for(citcell=(*citrow).cbegin()+bcol; citcell<=(*citrow).cbegin()+ecol; citcell++) { // ������� �� �������� stringstream ss; // ��������������� ����� ����� ss << *citcell; // ������ �� ������� � ����� ����� if(flg==nmBPTypes::volume) { // ���� ������ ���� volume ss >> (dData+tcols*i+j)->volume; // ������������ �� ������ � ����� � ���������� � ���� volume (dData+tcols*i+j)->price = nmBPTypes::dZero; // ��������� ���� ��������� ������ (dData+tcols*i+j)->value = nmBPTypes::dZero; } else // ����� if(flg==nmBPTypes::price) { // ���� ������ ���� price (dData+tcols*i+j)->volume = nmBPTypes::dZero; ss >> (dData+tcols*i+j)->price; // ������������ �� ������ � ����� � ���������� � ���� price (dData+tcols*i+j)->value = nmBPTypes::dZero; } else { (dData+tcols*i+j)->volume = nmBPTypes::dZero; (dData+tcols*i+j)->price = nmBPTypes::dZero; ss >> (dData+tcols*i+j)->value; }; j++; // �������� ������ ������� }; i++; // �������� ������ ������ }; return dData; } // GetstrItem size_t clsImpex::GetRowCount() const { return m_rowcount; } size_t clsImpex::GetColCount() const { return m_colcount; } /** ������ ����������� �������� **/ void clsImpex::View(ostream& os) const { /** ����� ����������� �������� ��������� �� ����� ���������� **/ os << "Rows " << m_rowcount << "; columns " << m_colcount << endl; for (const vector<string>& row : m_data) { for(const string& value: row) { os << setw(15) << value.substr(0,15) << " "; } os << endl; }; } // View /*************************************************************************************************************************/ /** ������������ ������� **/ /*************************************************************************************************************************/ bool ImportSingleArray(const string _filename, const char _ch, size_t hcols, size_t hrows, ReportData flg,\ strItem* &_data, strNameMeas* &_names, size_t& ColCount, size_t& RowCount) { /** ����� ������ ���������� �� ����� � ������ _filename � ������������� ����� ������ _ch � ��������� ����: RowCount - ����� �������������� ������� (�������� ��� ���������), ColCount - ����� �������� �������, _names - ������ �� ��������� �� ������ � �������������� �������������� ������� � ������ �� ���������, _data - ������ �� ��������� �� ����������� ������, flg - ����, ������������ ��� ������������� ������: "volume" - ������ � ����������� ���������, "price" - ����, "value" - ���������; hcols � hrows - ���������� �������� � ����� � �����������, ���������� �������� �������� � ������ �������� �������. **/ ifstream input(_filename); // ��������� ���� � ������� �� ������ if(!input.is_open()) return false; // �������� �������� ����� const char ch = _ch; // �������� ����������� clsImpex* Data = new clsImpex(input, ch); // ������� ����� ��� ������� � ����������� ������ �� ����� input.close(); // ��������� ���� � ��������� ������� if(Data->is_Empty()) { // ���� ������ �� ������, �� delete Data; // ������� ������ return false; // � ������� � false }; ColCount = Data->GetColCount()-hcols; // �������� ����� �������� ������� RowCount = Data->GetRowCount()-hrows; // �������� ����� �������������� ������� (�������� ��� ���������) strItem* tmpdata; // ��������� ����������-��������� �� ������ � ������� strNameMeas* tmpnames; // ��������� ����������-��������� �� ������ � ���������� size_t maxRow = RowCount-sOne+hrows; // ��������� ������ size_t maxCol = ColCount-sOne+hcols; // ��������� ������� tmpdata = Data->GetstrItem(hrows, maxRow, hcols, maxCol, flg); // �������� ��������� �� ������ � ������� tmpnames = Data->GetNames(hrows, maxRow, hcols-sTwo, hcols-sOne); // �������� ��������� �� ������ � ���������� delete Data; // ������� ������ ��� ������� std::swap(_data, tmpdata); // ������������ ������ �� ������� ��������� std::swap(_names, tmpnames); // ������������ ������ �� ������� ��������� if(tmpdata) delete[] tmpdata; // ������� ��������������� ������, ���� �� ���� if(tmpnames) delete[] tmpnames; // ������� ��������������� ������, ���� �� ���� return true; } // ImportSingleArray template<typename T, class> bool ImportSingleArray(const string _filename, const char _ch, size_t hcols, size_t hrows, \ T* &_data, strNameMeas* &_names, size_t& ColCount, size_t& RowCount) { /** ����� ������ ���������� �� ����� � ������ _filename � ������������� ����� ������ _ch � ��������� ����: RowCount - ����� �������������� ������� (�������� ��� ���������), ColCount - ����� �������� �������, _names - ������ �� ��������� �� ������ � �������������� �������������� ������� � ������ �� ���������, _data - ������ �� ��������� �� ����������� ������; hcols � hrows - ���������� �������� � ����� � �����������, ���������� �������� �������� � ������ �������� �������. **/ ifstream input(_filename); // ��������� ���� � ������� �� ������ if(!input.is_open()) return false; // �������� �������� ����� const char ch = _ch; // �������� ����������� clsImpex* Data = new clsImpex(input, ch); // ������� ����� ��� ������� � ����������� ������ �� ����� input.close(); // ��������� ���� � ��������� ������� if(Data->is_Empty()) { // ���� ������ �� ������, �� delete Data; // ������� ������ return false; // � ������� � false }; ColCount = Data->GetColCount()-hcols; // �������� ����� �������� ������� RowCount = Data->GetRowCount()-hrows; // �������� ����� �������������� ������� (�������� ��� ���������) T* tmpdata; // ��������� ����������-��������� �� ������ � ������� strNameMeas* tmpnames; // ��������� ����������-��������� �� ������ � ���������� size_t maxRow = RowCount-sOne+hrows; // ��������� ������ size_t maxCol = ColCount-sOne+hcols; // ��������� ������� tmpdata = Data->GetData<T>(hrows, maxRow, hcols, maxCol); // �������� ��������� �� ������ � ������� tmpnames = Data->GetNames(hrows, maxRow, hcols-sTwo, hcols-sOne); // �������� ��������� �� ������ � ���������� delete Data; // ������� ������ ��� ������� std::swap(_data, tmpdata); // ������������ ������ �� ������� ��������� std::swap(_names, tmpnames); // ������������ ������ �� ������� ��������� if(tmpdata) delete[] tmpdata; // ������� ��������������� ������, ���� �� ���� if(tmpnames) delete[] tmpnames; // ������� ��������������� ������, ���� �� ���� return true; } // template-ImportSingleArray /** ������������� ������� T ��� ������� ImportSingleArray **/ template bool ImportSingleArray(const string _filename, const char _ch, size_t hcols, size_t hrows, \ decimal* &_data, strNameMeas* &_names, size_t& ColCount, size_t& RowCount); template bool ImportSingleArray(const string _filename, const char _ch, size_t hcols, size_t hrows, \ bool* &_data, strNameMeas* &_names, size_t& ColCount, size_t& RowCount); template bool ImportSingleArray(const string _filename, const char _ch, size_t hcols, size_t hrows, \ size_t* &_data, strNameMeas* &_names, size_t& ColCount, size_t& RowCount); bool Import_Recipes(const string _prefixname, const char _ch, size_t hcols, size_t hrows,vector<clsRecipeItem>\ &_Recipe, size_t _Count, const string& msks, const string& V_DIR_INPUTDATA) { /** ����� ������ ���������� �� ������ � �������, ����������� ������� ����� ���������/ ��������������� ����� _prefixname. �������������� ��� �����, ��������������� ����� msks � ������� � ����� �����. ����� ��������� ��������� �������� _Recipe �������� _Count. ���������: _prefixname - ������� ���� ������ ���.����, _ch - �����������, ������������ � ������ ���� CSV, hcols - ���������� �������� � �����������, hrows - ���������� ����� � ����������� � ������, _Recipe - �������� ���������, _Count - ������ ����� ����������, msks - ����� ����������� ��������� ��� ������ ���������� ������, V_DIR_INPUTDATA - �����, ��� ����� ����������� ����� ������. **/ vector<clsRecipeItem> tmpRecipe; // ��������������� ������ tmpRecipe.reserve(_Count); // ����������� ������ ��� ��������� ������� ifstream rec; // ����� ��� ������ �� ����� clsImpex* Data = new(nothrow) clsImpex(); // ������� ��������� ������ ��� ������� regex fmask(_prefixname + msks); // ����� ������ ������ string pth = V_DIR_INPUTDATA; // ���������� � ����� ��� ������ ������ pth.resize(pth.length()-1); const fs::path indata{pth}; // ����� � ������� �������� if(!fs::exists(indata)) return false; // ��������� ������������� ����� for(auto &p : fs::directory_iterator(indata)) { // ����� � ����� if(!fs::is_regular_file(p.status())) continue; // ���������, ��� ��������� ���� ���������� (�� �����, �� ������) string name((p.path().filename()).string()); // �������� ��� ����� � ���� ������ if(regex_match(name, fmask)) { // ��������� ��� ����� �� ���������� � ������ rec.open(p.path()); // ��������� ����� � ������ if(!rec.is_open()) { // ���� ���� �� ������, �� delete Data; // ������� ��������� ������ ��� ������� return false; // � ������� � false } if(!Data->Import(rec, _ch)) { // ����������� ������ �� �����. ���� ������ �� ������, rec.close(); // �� ��������� ����; delete Data; // ������� ��������� ������ ��� ������� return false; // � ������� � false }; rec.close(); // ��������� ���� strNameMeas* _names = Data->GetNames(sZero, sZero, sZero, sOne); // ������ �������� � ��.��������� �������� size_t _duration = Data->GetColCount()-hcols; // �������� ������������ ����������������� ����� size_t _rcount = Data->GetRowCount()-hrows; // �������� ���������� ������� ����� � ��������� size_t maxRow = _rcount-sOne+hrows; // ��������� ������ size_t maxCol = _duration-sOne+hcols; // ��������� ������� strNameMeas* _rnames = Data->GetNames(hrows, maxRow, hcols-sTwo, hcols-sOne); // ������ � �������������� �������� decimal* _recipeitem = Data->GetDecimal(hrows, maxRow, hcols, maxCol); // �������� ���.����� ������� tmpRecipe.emplace_back(_names->name, _names->measure, _duration, _rcount, _rnames, _recipeitem); // ������� ������ "���������" � ������� delete[] _names; // ������� ��������������� ������ delete[] _rnames; // ������� ��������������� ������ delete[] _recipeitem; // ������� ��������������� ������ Data->reset(); // ���������� ��������� ������� �� ���������� } } // for(auto &p...) delete Data; _Recipe = move(tmpRecipe); // ���������� ��������������� ������ � �������� return true; } // Import_Recipes