/
Alexandr_Pidkasisty
/
froma2
Обзор
Документация
Войти
/
Alexandr_Pidkasisty
/
froma2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
libsource/agregate_lib.cpp
648 строк
46 KB
Alexandr Pidkasisty
Создал перегруженный метод void Set_autopurchase(const size_t index, const size_t _pcalc[]). Убрал const у возвращаемых значений в операторах структуры Getter_exporting_count. Скорректировал комментарии
21 июл 2026, 16:09
Верифицирован
21 июл 2026, 16:09
a7dc2ea
Код
Авторство
О чём код?
/** ���� ���� �������� ������ ���������� ������������ ����������� ��� �������������� �������������, ����������� ������� � ������������ ������������ ������������ ����������� "Free Operation Manager 2" (���������� FROMA2). **/ /****************************************************************************************************/ /****************************************************************************************************/ /*** ***/ /*** Copyright � 2025 ����������� ��������� �������� ***/ /*** ***/ /*** ������ �������� ��������� �����, ���������� ����� ������� ������������ ����������� � ***/ /*** ������������� ������������ (����� � ����������� �����������), ������������ ������������ ***/ /*** ����������� ����������� ��� �����������, ������� �������������� ����� �� �������������, ***/ /*** �����������, ���������, �������, ����������, ���������������, ����������������� �/��� ***/ /*** ������� ����� ������������ �����������, � ����� �����, ������� ��������������� ������ ***/ /*** ����������� �����������, ��� ���������� ��������� �������: ***/ /*** ***/ /*** ��������� ���� ����������� �� ��������� ����� � ������ ������� ������ ���� �������� �� ***/ /*** ��� ����� ��� �������� ����� ������� ������������ �����������. ***/ /*** ***/ /*** ������ ����������� ����������� ��������������� ���� ���ܻ, ��� �����-���� ��������, ���� ***/ /*** ���������� ��� ���������������, ������� �������� �������� �����������, ������������ �� ***/ /*** ��� ����������� ���������� � ���������� ���������, �� �� ������������� ���. �� � ����� ***/ /*** ������ ������ ��� ��������������� �� ����� ��������������� �� �����-���� �����, �� ����� ***/ /*** ��� �� ���� �����������, � ��� �����, ��� �������� ���������, ������� ��� ���� ��������, ***/ /*** ��������� ��-�� ������������� ������������ ����������� ��� ���� �������� � ����������� ***/ /*** ������������. ***/ /*** ***/ /****************************************************************************************************/ /****************************************************************************************************/ #include "agregate_module.h" //#define DEBUG_StF_RfF // ������ ������ ���������� ����������. ����������������� ��� ������� /***************************************************************************************************************/ /** **/ /** clsAgregate **/ /** **/ /***************************************************************************************************************/ clsAgregate::clsAgregate() { /** ����������� �� ���������. ����� ��������� �������� ����������� ������� ������, ����������� ��������� � ������ protected. � ����������� ������� ������������ ���������� ��������� � ������ public. **/ PrCount = sh_size = sZero; // �������������� ���������� ������� Purchase = nullptr; // ������������� ������ ��������� �� ������� Shipment = nullptr; // ������������� ������ ��������� �� �������� } //ctor void clsAgregate::swap(clsAgregate& other) noexcept { /** ������� ������ ���������� ����� ���������. ������� ��������� noexcept - �� ���������� ���������� **/ clsBaseProject::swap(other); // �������� ������� ������������� ������ std::swap(PrCount, other.PrCount); // ���������� �������� std::swap(sh_size, other.sh_size); // ���������� �������� CostChain.swap(other.CostChain); // ���������� ������� std::swap(Purchase, other.Purchase); // ���������� ��������� std::swap(Shipment, other.Shipment); // ���������� ��������� } // clsCostCenterStorage_1::swap clsAgregate::clsAgregate(const clsAgregate& other) : clsBaseProject(other) { /** ����������� ����������� **/ PrCount = other.PrCount; // �������� ������������ ������� sh_size = other.sh_size; // �������� ����� ����� ������� Shipment CostChain = other.CostChain; // �������� ���������� if(other.Purchase) { // ���� ������ other.Purchase ����������, size_t tmpcount = // �� ��������� ������ ������� std::visit(Getter_exporting_count(purchase), *(CostChain.begin()))*PrCount; Purchase = new(nothrow) strItem[tmpcount]; // �������� ������, if(Purchase) // ���� ������ ��������, var_cpy(Purchase, other.Purchase, tmpcount); // �� �������� �������; } else Purchase = nullptr; // ���� other.Purchase ���, �� ����������� nullptr if(other.Shipment) { // ���� ������ other.Shipment ����������, �� size_t tmpcount = sh_size*PrCount; // ��������� ������ ������� Shipment = new(nothrow) strItem[tmpcount]; // �������� ������, if(Shipment) // ���� ������ ��������, var_cpy(Shipment, other.Shipment, tmpcount); // �� �������� �������; } else Shipment = nullptr; // ���� other.Shipment ���, �� ����������� nullptr } // Copy Ctor clsAgregate::clsAgregate(clsAgregate&& other) : clsBaseProject() { /** ����������� ����������� **/ PrCount = sh_size = sZero; // �������������� ���������� ������� Purchase = nullptr; // ������������� ������ ��������� �� ������� Shipment = nullptr; // ������������� ������ ��������� �� �������� swap(other); } // Move Ctor clsAgregate::~clsAgregate() { /** ���������� **/ if(Purchase) delete[] Purchase; if(Shipment) delete[] Shipment; } //Dtor clsAgregate& clsAgregate::operator=(const clsAgregate& rhs) { /** ���������� ��������� ������������ ������������. ����������� � ������ �����������-�-������ (copy-and-swap idiom) **/ if (this == &rhs) return *this; // ���� ������� ���������, �� ������ �� ������ clsAgregate tmp(rhs); // �������� ����� ������� rhs � ���������� tmp this->swap(tmp); // ������������ ����������� � tmp return *this; } // Copy operator= clsAgregate& clsAgregate::operator=(clsAgregate&& rhs) { /** ���������� ��������� ������������ ������������. ����������� � ������ �����������-�-������ (move-and-swap idiom) **/ if(this == &rhs) return *this; // ���� ������� ���������, �� ������ �� ������ clsAgregate tmp(move(rhs)); // ���������� ������ rhs � ���������� tmp this->swap(tmp); // ������������ ����������� � tmp return *this; } // Move operator= /** Get - ������ **/ size_t clsAgregate::ProjectCount() { /** ����� ���������� ���������� �������� ������� **/ return PrCount; } size_t clsAgregate::Counts(const ChoiseData _arr, const size_t _count) { /** ����� ���������� ����� �������� ���������� �������������. ���������: _arr � ��������� ������ ������: "purchase" - ��������, "balance" - �������/������������� ������������, "shipment" � ��������; _count - ������ ���������� �������������: 0 - ������ �������������, ����������� ������� (������� ���������� CostChain � �������� ����); �������������, ����������� ������� ��������� ����� ����� ����� ������� ����� (������� ���������� CostChain � ������������ ��������). **/ if(CostChain.size() == sZero) return sZero; // ���� ��������� ����, �� ���������� ���� else return std::visit(Getter_exporting_count(_arr), *(CostChain.begin()+_count)); } // clsAgregate::Counts strNameMeas* clsAgregate::GetNameMeas(const ChoiseData _arr, const size_t _count) const { /** ����� ���������� ��������� �� ����� ������ ���� strNameMeas � ��������� �������� � ��������� ���������. ����� ��������� ������� ����� Counts(_arr, _count). ���������: _arr - ��������� ������ ������: "purchase" - ��������, "balance" - �������/������������� ������������, "shipment" - ��������; _count - ������ ���������� �������������: 0 - ������ �������������, ����������� ������� (������� ���������� CostChain � �������� ����); �������������, ����������� ������� ��������� ����� ����� ����� ������� ����� (������� ���������� CostChain � ������������ ��������).**/ if(CostChain.size() == sZero) return nullptr; // ���� ��������� ����, �� ���������� nullptr else return std::visit(Getter_NameMeas{}, CostChain[_count]); } // clsAgregate::GetNameMeas bool clsAgregate::Export_Data(const string filename, const size_t _dep, const ChoiseData _arr, \ const ReportData& flg) const { /** ����� ���������� ������ ��������, �������� ��� �������� ���������� ������������� � csv-���� � ������ filename. ���������: _dep - ������ ������������� � ������� ������������� CostChain; _arr - ����� ������: "purchase" - ��������, "balance" - �������/������������� ������������, "shipment" - ��������; flg - ��� ��������� � ���� ����������: volume - � �����������, value - � �����������, price - � ������� ���������. � �������� ����������� ����� ������ ������������ ������ _ch �� ��������� (';'). **/ if(CostChain.size() == sZero) return false; // ��������� ���������� const size_t NameCount = std::visit(Getter_exporting_count(_arr), CostChain[_dep]); // ������ ��������������� ������� strNameMeas* pNames = std::visit(Getter_exporting_names(_arr), CostChain[_dep]); // ������ � ������� if(!pNames) return false; // ���� ������ � ������� ����, �� ����� � false strItem* pData; // ��������������� ��������� if((std::holds_alternative<clsManufactory>(CostChain[_dep])) && (_arr == purchase) && (flg !=volume)) { // ���� ����� ����� ����������� ������ � �������� �� ������� ���� clsManufactory, �� ���� �������, ��� ����� // clsManufactory::GetRMPurchPlan ���������� ������ � �������� ������ price � value. ������� ���� ����� ������ // �� �������, ��������������� ��������. ��� ������ ������� ������� ��� ������ ����� ����� �� ������� Purchase, // ��� ������ �������� - � ������� ������� ��������� Setter_ship �� ����������� �������. ptrdiff_t index = static_cast<ptrdiff_t>(_dep); // ��������������� ������ index--; // ��������� ������ if(index < static_cast<ptrdiff_t>(sZero)) { // ���� ������ ���� ������ ����, �� ����� ������ �� Purchase size_t tmpCount = NameCount*PrCount; // ��������� ���������� pData = new(nothrow) strItem[tmpCount]; // �������� ������ ������� if(!pData) { // ���� ������ �� ��������, �� delete[] pNames; // ������� ����� ��������� ������ � ������� return false; // � ������� � false } var_cpy(pData, Purchase, tmpCount); // ���� ������ ��������, �� �������� ������ �� ������� Purchase } else { // ���� �� ������ �������������, �� pData = std::visit(Getter_ship{}, CostChain[index]); // ����� ������ �� ��������� �� ����������� �������� ������� } } else pData = std::visit(Getter_exporting_data{_arr}, CostChain[_dep]); /** ������� ������ ��������/������� � ������ � ���� ������ **/ clsImpex* Data = new clsImpex(NameCount, pNames, pData, PrCount, flg); delete[] pNames; // ������� ��������� ������ � ������� delete[] pData; // ������� ��������� ������ � ������� if(Data->is_Empty()) { // ���� ��������� � ������� �� ������, �� return false; // ������� � false }; ofstream output(filename, std::ofstream::trunc); // �������� ���� �� ������ if(output.is_open()) { // ���� ���� ������, �� Data->csvExport(output); // ���������� ������ � ���� output.close(); // ��������� ���� } else { delete Data; return false; } delete Data; // ������� ������ ��������/������� return true; } // clsAgregate::Export_Data void clsAgregate::reportstream(ostream& os) const { /** ����� ������� ����� � ����� os. ������������ ������������� ������� clsBaseProject::Report **/ clsBaseProject::reportstream(os); // ����� ������� ���������� os << "���������� �������� �������:\t\t\t\t\t\t" << PrCount << "\n"; os << "���������� �������������:\t\t\t\t\t\t " << CostChain.size() << "\n"; } // clsAgregate::reportstream bool clsAgregate::Detail_report(const size_t _dep, const string _depName[], const ChoiseData _arr, const ReportData& flg) const { /** ������� ������� ��������� �����. ���������: _dep - ������ ������������� � ������� ������������� CostChain; _depName - ��������� �� ������ � ���������� ������������� (����� ��������� �� nullptr; � ���� ������ ������ �������� ������������� � ����� ����� �������� �� ������); _arr - ����� ������: "purchase" - ��������, "balance" - �������/ ������������� ������������, "shipment" - ��������; flg - ��� ��������� � ���� ����������: volume - � �����������, value - � �����������, price - � ������� ���������. ����� ��������� � ���� � ������, ������������ � ���������� clsBaseProject::RName. **/ if(CostChain.size() == sZero) return false; // ��������� ���������� const size_t NameCount = std::visit(Getter_exporting_count(_arr), CostChain[_dep]); // ������ ��������������� ������� strNameMeas* pNames = std::visit(Getter_exporting_names(_arr), CostChain[_dep]); // ������ � ������� if(!pNames) return false; // ���� ������ � ������� ����, �� ����� � false strItem* pData; // ��������������� ��������� if((std::holds_alternative<clsManufactory>(CostChain[_dep])) && (_arr == purchase) && (flg !=volume)) { // ���� ����� ����� ����������� ������ � �������� �� ������� ���� clsManufactory, �� ���� �������, ��� ����� // clsManufactory::GetRMPurchPlan ���������� ������ � �������� ������ price � value. ������� ���� ����� ������ // �� �������, ��������������� ��������. ��� ������ ������� ������� ��� ������ ����� ����� �� ������� Purchase, // ��� ������ �������� - � ������� ������� ��������� Setter_ship �� ����������� �������. ptrdiff_t index = static_cast<ptrdiff_t>(_dep); // ��������������� ������ index--; // ��������� ������ if(index < static_cast<ptrdiff_t>(sZero)) { // ���� ������ ���� ������ ����, �� ����� ������ �� Purchase size_t tmpCount = NameCount*PrCount; // ��������� ���������� pData = new(nothrow) strItem[tmpCount]; // �������� ������ ������� if(!pData) { // ���� ������ �� ��������, �� delete[] pNames; // ������� ����� ��������� ������ � ������� return false; // � ������� � false } var_cpy(pData, Purchase, tmpCount); // ���� ������ ��������, �� �������� ������ �� ������� Purchase } else { // ���� �� ������ �������������, �� pData = std::visit(Getter_ship{}, CostChain[index]); // ����� ������ �� ��������� �� ����������� �������� ������� } } else pData = std::visit(Getter_exporting_data{_arr}, CostChain[_dep]); /** ��������� ����� **/ string divsn = ""; // ��������������� ����������: �������� ������������� string swork; // ��������������� ����������: �������� ���������� ������� if(_depName) // ���� ������ � �������������� ������������� ����������, divsn = *(_depName+_dep); // �� ����������� divsn ��� �������������, else divsn = std::to_string(_dep); // ����� ����������� ����� ������������� divsn += ": "; // ��������� ��������� � ������ if((_arr == purchase) || (_arr == balance)) if(_arr == purchase) swork = nmAgregate::aPurchase; else swork = nmAgregate::aBalance; else swork = nmAgregate::aShipment; std::ofstream ofs; // ��������������� ���������� ��� ������ ������ � ���� ofs.open(RName, std::ofstream::app); // ��������� ����� � ������ � ��������� ��� �� ������ // � ������ ���������� � ������������� nmRePrint::PrintHeader2(ofs, nmRePrint::smblcunt+nmRePrint::uThree, divsn+swork); // ������� ��������� ������ nmRePrint::clsRePrint<strItem, strNameMeas>* MyRep = \ new nmRePrint::clsRePrint<strItem, strNameMeas>(nmAgregate::w1, nmAgregate::w2, nmAgregate::w3);// ��������� MyRep->SetHeadings(nmAgregate::rTableName, nmAgregate::rTableMeas, \ nmAgregate::rByVolume, nmAgregate::rByPrice, nmAgregate::rByValue); // ������ ��������� ������� auto Set_currency = [](auto& obj) { return obj.GetHomeCurrency(); }; // ������ ��� ��������� ������� ������ MyRep->SetCurrency(static_cast<nmBPTypes::Currency>(std::visit(Set_currency, CostChain[_dep])));// ��������� ������ MyRep->SetPrecision(nmAgregate::precis); // ��������� ���������� ������ ����� ������� MyRep->SetStream(ofs); // ������������� ����� ������ � �������� ����� bool result; // ��������������� ��������� if(MyRep->SetReport(NameCount, pNames, pData, PrCount, flg)) { // ������ ������ � ����� MyRep->Print(flg); // ������� �����, ���� ����������, result = true; // �� ��������� true, } else result = false; // ������ ��������� false ofs.close(); // ��������� ���� if(pNames) delete[] pNames; // ������� ��������������� ������ if(pData) delete[] pData; // ������� ��������������� ������ if(MyRep) delete MyRep; // ������� ����� return result; } // clsAgregate::GetReport /** Set - ������ **/ void clsAgregate::Set_progress_shell(clsProgress_shell<type_progress>* _val) { /** ������� ����������� ��������� pshell ������� ������� �� ���������� CostChain ����� ������� val - �������� ��� ���������� ���������. **/ auto Set_shell = [&_val](auto& obj) { obj.Set_progress_shell(_val); }; /** ������ ��� ��������� ��������� �� �������� ���������� ��������� **/ for(T_agregate &obj: CostChain) { std::visit(Set_shell, obj); } } // clsAgregate::Set_progress_shell void clsAgregate::Set_share(const size_t index, const decimal _share[]) { /** ������� ������������� ��������� ������� �� ������. ���������: index - ������ �������� ���������� CostChain, � ������� ��������� ������ ���� clsStorage, _share - ��������� �� ������ � ����������� ������� �������� ��� ������� ��������������� ������. ����� ���������� � ����� �� ������� ��������. **/ auto Setter_share = [&_share](auto& obj) { // �������-���������� using T = std::decay_t<decltype(obj)>; // �������������� � �������� ���� � ����������� ������ � if constexpr (std::is_same_v<T, clsStorage>) // ���� ������� ��� clsStorage, for(size_t i{}; i<obj.Size(); i++) // �� ��� ������� ��������������� i-�� ������ obj.SetShare(i, *(_share+i)); // ������������� ��������������� �������� ������ else if constexpr (std::is_same_v<T, clsManufactory>) {}; // ���� ������� ��� clsManufactory, }; // �� ������ �� ������ if(CostChain.size() == sZero) return; // ���� ��������� ����, �� ������� else std::visit(Setter_share, CostChain[index]); // �������� ���������� ��� �������� } // clsAgregate::Set_share void clsAgregate::Set_permission(const size_t index, const bool _perm[]) { /** ������� ������������� ����������/������ �� �������� � ������� �� ������ � ����� � ��� �� �������. ���������: index - ������ �������� ���������� CostChain, _perm - ��������� �� ������ � ������� ����������. **/ auto Setter_permission = [&_perm](auto& obj) { // �������-���������� using T = std::decay_t<decltype(obj)>; // �������������� � �������� ���� � ����������� ������ � if constexpr (std::is_same_v<T, clsStorage>) // ���� ������� ��� clsStorage, for(size_t i{}; i<obj.Size(); i++) // �� ��� ������� ��������������� i-�� ������ obj.SetPermission(i, *(_perm+i)); // ������������� ��������������� ���� ���������� else if constexpr (std::is_same_v<T, clsManufactory>) {}; // ���� ������� ��� clsManufactory, }; // �� ������ �� ������ if(CostChain.size() == sZero) return; // ���� ��������� ����, �� ������� else std::visit(Setter_permission, CostChain[index]); // �������� ���������� ��� �������� } // clsAgregate::Set_permission void clsAgregate::Set_autopurchase(const size_t index, const PurchaseCalc _pcalc[]) { /** ������� ������������� ���� �����������/ ������� ������� ������� �� ������. ���������: index - ������ �������� ���������� CostChain, _pcalc - ��������� �� ������ � ������� �����������. **/ auto Setter_autopurchase = [&_pcalc](auto& obj) { // �������-���������� using T = std::decay_t<decltype(obj)>; // �������������� � �������� ���� � ����������� ������ � if constexpr (std::is_same_v<T, clsStorage>) // ���� ������� ��� clsStorage, for(size_t i{}; i<obj.Size(); i++) // �� ��� ������� ��������������� i-�� ������ ������������� obj.SetAutoPurchase(i, *(_pcalc+i)); // ��������������� ���� ����������� else if constexpr (std::is_same_v<T, clsManufactory>) {}; // ���� ������� ��� clsManufactory, }; // �� ������ �� ������ if(CostChain.size() == sZero) return; // ���� ��������� ����, �� ������� else std::visit(Setter_autopurchase, CostChain[index]); // �������� ���������� ��� �������� } // clsAgregate::Set_autopurchase void clsAgregate::Set_autopurchase(const size_t index, const size_t _pcalc[]) { /** ������� ������������� ���� �����������/ ������� ������� ������� �� ������. ���������: index - ������ �������� ���������� CostChain, _pcalc - ��������� �� ������ � ������� �����������. **/ auto Setter_autopurchase = [&_pcalc](auto& obj) { // �������-���������� using T = std::decay_t<decltype(obj)>; // �������������� � �������� ���� � ����������� ������ � if constexpr (std::is_same_v<T, clsStorage>) // ���� ������� ��� clsStorage, for(size_t i{}; i<obj.Size(); i++) // �� ��� ������� ��������������� i-�� ������ ������������� obj.SetAutoPurchase(i, static_cast<PurchaseCalc>(*(_pcalc+i))); // ��������������� ���� ����������� else if constexpr (std::is_same_v<T, clsManufactory>) {}; // ���� ������� ��� clsManufactory, }; // �� ������ �� ������ if(CostChain.size() == sZero) return; // ���� ��������� ����, �� ������� else std::visit(Setter_autopurchase, CostChain[index]); // �������� ���������� ��� �������� } // clsAgregate::Set_autopurchase bool clsAgregate::Set_ship_volume(const strItem _Shipment[]) { /** ����� ����� ������� �������� � ������������� � ����� ������� ��������. ���������: _Shipment - ��������� �� �������� ������ � ����������. ����� ���������� true ��� ������� ����������� �������� ������� �� ���������� ������ Shipment.**/ if((!_Shipment) || (CostChain.size() == sZero)) return false; // ��������� ���������� sh_size = std::visit(Getter_exporting_count(shipment), *(CostChain.cend()-1)); // �������� ����� ����� ������� size_t tcount = sh_size * PrCount; // ��������� ������ ���������� �������� strItem* temp = new(nothrow) strItem[tcount]; // �������� ������ ���������� ������� if(!temp) return false; // ���� ������ �� ��������, �� ����� var_cpy(temp, _Shipment, tcount); // ����������� �������� std::swap(temp, Shipment); // ���������� ��������� if(temp) delete[] temp; // ���� temp �� ����, �� ������� ��� return true; } // clsAgregate::Set_ship_volume bool clsAgregate::Set_pur_price(const strItem _Purchase[]) { /** ����� ����� ��� �������� � ������������� � ������� ��������. ���������: _Purchase - ��������� �� �������� ������ � ����������. ����� ���������� true ��� ������� ����������� �������� ������� �� ���������� ������ Purchase. **/ if((!_Purchase) || (CostChain.size() == sZero)) return false; // ��������� ���������� sh_size = std::visit(Getter_exporting_count(purchase), *(CostChain.cbegin())); // �������� ����� ����� ������� size_t tcount = sh_size * PrCount; // ��������� ������ ���������� �������� if(Purchase) { // ���� ������ Purchase �������� for(size_t i{}; i<tcount; i++) { (Purchase +i)->price = (_Purchase +i)->price; // �������� ���� (Purchase +i)->value = (Purchase +i)->volume * (Purchase +i)->price; // ������������ ��������� } var_cpy(Shipment, Purchase, tcount); // �������� ������� } else { // ���� ������ Purchase ������ Purchase = new(nothrow) strItem[tcount]; // �������� ������ ������� if(!Purchase) return false; // ���� ������ �� ��������, �� ����� c false for(size_t i{}; i<tcount; i++) { (Purchase +i)->price = (_Purchase +i)->price; // �������� ���� (Purchase +i)->value = (Purchase +i)->volume = dZero; // ��������� ������ } } return true; } // clsAgregate::Set_pur_price bool clsAgregate::Set_pur_volume(const strItem _Pur_vol[]) { /** ����� ����� ������� �������� � ������������� ���� clsStorage � ����� ������ ��������. ������������ � ������, ����� ���� �� ��� ������ SKU ���������� ���� ������� ����� ������� �������� (���� "nocalc" - ��� ��������������� �������). ��������!!! ����� ���������� �� ������ ������� RCalculate, �������� ����� � ������� ������ Set_ship_volume. ���������: _Pur_vol - ��������� �� �������� ������ � ����������. **/ if(!_Pur_vol) return false; // ��������� ���������� for(vector<T_agregate>::iterator it = CostChain.begin(); it != CostChain.end(); it++) if(std::holds_alternative<clsStorage>(*it)) { // ���� it ��������� �� clsStorage, �� sh_size = std::visit(Getter_exporting_count(purchase), *it); // �������� ����� ����� ������� size_t tcount = sh_size * PrCount; // ��������� ������ ���������� �������� strItem* tmp = new(nothrow) strItem[tcount]; // �������� ������ ���������� ������� if(!tmp) return false; // ���� ������ �� ��������, �� ����� c false var_cpy(tmp, _Pur_vol, tcount); // �������� ������� if(!std::visit(Setter_purch(tmp), *it)) { // ���������� ��������� ������ if(tmp) delete[] tmp; // ���� ��������, �� ������� ��������� ������ return false; // � ������� � false } return true; // � ������ ������ ������� � true } return false; // ���� �� ����� �� ������ clsStorage, �� ������� � false } // clsAgregate::Set_pur_volume void clsAgregate::Reset() { /** ����� ���������� ��� ���������� � �������� ������ � ��������� �� ��������� **/ clsAgregate temp; // ������� "������ ������" swap(temp); // ������������ ���������� � ������ �������� } // clsAgregate::Reset /** View- ������ **/ void clsAgregate::ViewSettings() const { /** ������� ������� �� ����� ���������� � ���������� ��� �������. **/ auto caller_view = [](auto& obj) { // �������-���������� using T = std::decay_t<decltype(obj)>; // �������������� � �������� ���� � ����������� ������ � if constexpr (std::is_same_v<T, clsStorage>) // ���� ������� ��� clsStorage, obj.ViewSettings(); // �������� ��������������� ������� else if constexpr (std::is_same_v<T, clsManufactory>) // ���� ������� ��� clsManufactory, obj.ViewProjectParametrs(); // �������� ��������������� ������� }; for(vector<T_agregate>::const_reverse_iterator crit=CostChain.crbegin(); crit!=CostChain.crend(); crit++ ) { // ��� ���� ��������� ���������� � �������� ������� std::visit(caller_view, *crit); // �������� �������-���������� } } // clsAgregate::ViewSettings /** ��������� ������ **/ bool clsAgregate::RCalculate(const string msg[]) { /** ����� ������������ ����� �������� � ����������� ���������, ����������� � ������������� � ������� ��������. ���� ������� ����������� ������ (����� ������ true), � ������� Purchase ����� ����������� ��������� ������. ���������: msg - ��������� �� ������ � �������������� ����������� ���������. **/ if(CostChain.size() == sZero) return false; // ��������� ���������� TLack Lack; // ��������������� ���������� size_t i = CostChain.size()-sOne; // ���������� ������ ���������� �������� ���������� size_t MCount; // ���������� ������� �� �����, � �������� � ������ auto Setter_maxcount = [&MCount](auto& obj) { //������� ������������� ����� �������� ������������� ����� �������� ��� ���������� ��������� obj.Set_progress_maxcount(MCount); }; for(vector<T_agregate>::reverse_iterator rit=CostChain.rbegin(); rit!=CostChain.rend(); rit++) { // ������������� ������������ ���������� ���������, ������������� ������������ �������� �������� // ���������� ���������, ������ ������ �� �������� �� ������� Shipment � ������� ����������, // ������������ ���� �������, ������� ��������� ������ � ������ Shipment. � ��� ��� ���� ��������� // ���������� � ����������� ����������� std::visit(Setter_progress_message{*(msg+i)}, *rit); // ������������� ��������� ���������� ��������� MCount = std::visit(Getter_exporting_count(shipment), *rit); // ���������� ����� ����������� SKU � ������������� std::visit(Setter_maxcount, *rit); // ������������� ������� ���������� ��������� i--; // ��������� ������� ������� msg if(!std::visit(Setter_ship(Shipment), *rit)) return false; // ���� ������� �������� �� Shipment Lack = std::visit(Calculater_back{}, *rit); // ������ ����������� � �������� cout << '\n'; if(fabs(Lack.lack) > epsln) { // �������� �������� �������� cout << "������� �������� � ������� " << Lack.Name << " � ������ "; cout << Lack.lack << '\n'; return false; }; Shipment = std::visit(Getter_purch(), *rit); // ��������� ������� � ������������ � ������ Shipment }; sh_size = std::visit(Getter_exporting_count(purchase), *(CostChain.cbegin())); // �������� ����� ����� ������� Shipment size_t tcount = sh_size * PrCount; // ������ ���������� �������� if(Purchase) { // ���� ������ Purchase ����������, �� for(size_t i{}; i<tcount; i++) { (Purchase + i)->volume = (Shipment +i)->volume; // �������� ������ �������� (Purchase + i)->value = (Purchase + i)->volume * (Purchase + i)->price; // ������������ ������ ��������� } var_cpy(Shipment, Purchase, tcount); // �������� ������� } else { Purchase = new(nothrow) strItem[tcount]; // �������� ������ ������� if(!Purchase) return false; // ���� ������ �� ��������, �� ����� � false var_cpy(Purchase, Shipment, tcount); // �������� ������� } return true; } // clsAgregate::RCalculate bool clsAgregate::FCalculate(const string msg[]) { /** ����� ������������ �������� � ������ ��������� ��������, ����������� �� ������������� � ������������ ��������. ���� ������� ����������� ������ (����� ������ true), � ������� Shipment ����� ����������� ��������� ������. ���������: msg - ��������� �� ������ � �������������� ����������� ���������. **/ if(CostChain.size() == sZero) return false; // ��������� ���������� TLack Lack; // ��������������� ���������� size_t i{}; // ��������������� ������� size_t MCount; // ���������� ������� �� �����, � �������� � ������ auto Setter_maxcount = [&MCount](auto& obj) { //������� ������������� ����� �������� ������������� ����� �������� ��� ���������� ��������� obj.Set_progress_maxcount(MCount); }; for(vector<T_agregate>::iterator it = CostChain.begin(); it != CostChain.end(); it++) { // ������������� ������������ ���������� ���������, ������������� ������������ �������� �������� // ���������� ���������, ������ ������ � �������� �� ������� Shipment � ������� ����������, // ������������ ���� �������, ������� ��������� ������ � ������ Shipment. � ��� ��� ���� ��������� // ���������� � ������ ����������� std::visit(Setter_progress_message{*(msg+i)}, *it); // ������������� ��������� ���������� ��������� MCount = std::visit(Getter_exporting_count(shipment), *it); // ���������� ����� ����������� SKU � ������������� std::visit(Setter_maxcount, *it); // ������������� ������� ���������� ��������� i++; // ����������� ������� if(!std::visit(Setter_purch(Shipment), *it)) return false; // ���� ��� �� Shipment Lack = std::visit(Calculater_fwrd{}, *it); // ������ ����������� � �������� cout << '\n'; if(fabs(Lack.lack) > epsln) { // �������� �������� �������� cout << "������� �������� � ������� " << Lack.Name << " � ������ "; cout << Lack.lack << '\n'; return false; }; Shipment = std::visit(Getter_ship(), *it); // ��������� ������� �� ����������� � ������ Shipment }; sh_size = std::visit(Getter_exporting_count(shipment), *(CostChain.cend()-1)); // �������� ����� ����� ������� Shipment return true; } // clsAgregate::FCalculate bool clsAgregate::StF(ofstream &_outF) { /** ����� ������������� ������ � �������� ���������� �������� ���������� ������ (������ � ����, ����� ������������). ���������: &_outF - ������ �� ��������� ������ ofstream ��� ������ ������ **/ #ifdef DEBUG_StF_RfF // ������ ������ ���������� ����������. ��������, ���� ��������� DEBUG_StF_RfF long bpos = _outF.tellp(); // ���������� ������� � ������ ����� cout << "clsAgregate::StF begin bpos= " << bpos << endl; #endif bool flagPurchase; // ���� ������������� ������� Purchase bool flagShipment; // ���� ������������� ������� Shipment size_t c_chain_size = CostChain.size(); // ������ ���������� bool c_chain_flag[c_chain_size]; // ������ � ������� ��� ����������� ���� �������� ���������� if(!clsBaseProject::StF(_outF)) return false; // ��������� � ���� ������ ������������� ������ if(!SEF(_outF, PrCount)) return false; // ��������� � ���� ���������� �������� ������� if(!SEF(_outF, c_chain_size)) return false; // ��������� � ���� ������ ���������� if(!SEF(_outF, sh_size)) return false; // ��������� � ���� ������������ ����� ����� ������� Shipment; auto flagCostChainItem = [] (auto& obj) -> bool { /** ������ ��� ����������� ���� �������� ���������� **/ using T = std::decay_t<decltype(obj)>; // �������������� � �������� ���� � ����������� ������ � if constexpr(std::is_same_v<T, clsStorage>) return true; // ��� clsStorage ���������� true, else if constexpr (std::is_same_v<T, clsManufactory>) return false; // ��� clsManufactory ���������� false }; // auto flagCostChainItem auto StF_writer = [&_outF](auto& obj) -> bool { /** ������ ��� ������ ������ ������������ StF **/ return obj.StF(_outF); }; // StF_writer /** ��������� � ���� ��������� CostChain **/ if(c_chain_size != sZero) { // ���� ������ ���������� ���������, �� size_t j{}; // ���������� ��������������� ������� � for(T_agregate& val : CostChain) { // ��������� ������ ������ c_chain_flag *(c_chain_flag+j) = std::visit(flagCostChainItem, val); j++; // ����������� ������� }; if(!SEF(_outF, c_chain_flag, c_chain_size)) return false; // ��������� ������ ������ for(vector<T_agregate>::iterator it = CostChain.begin(); it != CostChain.end(); it++) if(!std::visit(StF_writer, *it)) return false; // ��������� ������ �� ���������� }; // ��������� � ���� ��������� CostChain size_t tm_size; // ����� ����� ������� Purchase ��� Shipment /** ��������� ������ Purchase **/ if(Purchase) { // ���� ������ ����������, �� flagPurchase = true; // ������������� ���� true � ���������� ����� tm_size = std::visit(Getter_exporting_count(purchase), *(CostChain.cbegin())); // ����� ������� } else { flagPurchase = false; // ������������� ���� false tm_size = sZero; // ����������� ������� ����� ����� } if(!SEF(_outF, flagPurchase)) return false; // ��������� ���� � ���� if(!SEF(_outF, tm_size)) return false; // ��������� ����� ����� ������� Purchase � ���� if(flagPurchase && tm_size>sZero) { // ���� ���� true � ����� ����� ����� ����, �� size_t tmpCount = tm_size * PrCount; // ��������� ������ ������� for(size_t i{}; i<tmpCount; i++) // � ������ ��� ������� if(!(Purchase+i)->StF(_outF)) return false; // ��������� � ���� } /** ��������� ������ Shipment **/ if(Shipment) { // ���� ������ ����������, �� flagShipment = true; // ������������� ���� true � ���������� ����� tm_size = sh_size; // ����� ������� Shipment } else { flagShipment = false; // ������������� ���� false tm_size = sZero; // ����������� ������� ����� ����� } if(!SEF(_outF, flagShipment)) return false; // ��������� ���� � ���� if(!SEF(_outF, tm_size)) return false; // ��������� ����� ����� ������� Shipment � ���� if(flagShipment && tm_size>sZero) { // ���� ���� true � ����� ����� ����� ����, �� size_t tmpCount = tm_size * PrCount; // ��������� ������ ������� for(size_t i{}; i<tmpCount; i++) // � ������ ��� ������� if(!(Shipment+i)->StF(_outF)) return false; // ��������� � ���� } #ifdef DEBUG_StF_RfF long epos = _outF.tellp(); // ���������� ������� � ����� ����� cout << "clsAgregate::StF end epos= " << epos << endl; #endif // DEBUG_StF_RfF return true; } // clsAgregate::StF bool clsAgregate::RfF(ifstream &_inF) { /** ����� ������������� ������ �� �������� ���������� ���������� ������ (������ �� �����, ����� ��������������). ���������: &_inF - ������ �� ��������� ������ ifstream ��� ������ ������. **/ size_t c_chain_size{}; // ������ ���������� #ifdef DEBUG_StF_RfF // ������ ������ ���������� ����������. ��������, ���� ��������� DEBUG_StF_RfF long bpos = _inF.tellg(); // ���������� ������� � ������ ����� cout << "clsAgregate::RfF begin bpos= " << bpos << endl; #endif if(!clsBaseProject::RfF(_inF)) return false; // ������ �� ����� ������ ������������� ������ if(!DSF(_inF, PrCount)) return false; // ������ �� ����� ���������� �������� ������� if(!DSF(_inF, c_chain_size)) return false; // ������ �� ����� ������ ���������� if(!DSF(_inF, sh_size)) return false; // ������ �� ����� ������������ ����� ����� ������� Shipment; auto RfF_reader = [&_inF](auto& obj) -> bool { /** ������ ��� ������ ������ �������������� RfF **/ return obj.RfF(_inF); }; // RfF_reader /** ������ �� ����� ��������� CostChain **/ bool c_chain_flag[c_chain_size]; // ������ � ������� ��� ����������� ���� �������� ���������� if(c_chain_size != sZero) { // ���� ��������������� ������ ���������� �� ����� ����, �� vector<T_agregate>().swap(CostChain); // �������� ������ � ��������� �� ��������� if(!DSF(_inF, c_chain_flag, c_chain_size)) return false; // ������ �� ����� ������ ������ CostChain.reserve(c_chain_size); // ����������� ������ ���������� for(size_t i{}; i<c_chain_size; i++) { // ��������������� ���������: if(*(c_chain_flag+i)) CostChain.emplace_back(clsStorage()); // ���� ���� true, �� ������� clsStorage; else CostChain.emplace_back(clsManufactory()); // ����� ������� clsManufactory; ������ �� if(!std::visit(RfF_reader, *(CostChain.end()-1))) return false; // ����� ������ � ��������� ������� ���������� } } // ������ �� ����� ��������� CostChain size_t tm_size; // ����� ����� ������� Purchase ��� Shipment /** ������ �� ����� ������ Purchase **/ bool flagPurchase; // ���� ������������� ������� Purchase if(!DSF(_inF, flagPurchase)) return false; // ������ �� ����� ���� ������������� ������� if(!DSF(_inF, tm_size)) return false; // ������ ����� ����� �������. ���� ���� true � ����� if(flagPurchase && tm_size>sZero) { // ����� ����� ����, ����� ��������������� ������: size_t tmpCount = tm_size * PrCount; // ��������� ������ �������; strItem* tmp = new(nothrow) strItem[tmpCount]; // �������� ������ ���������������� �������; if(!tmp) return false; // ���� ������ �� ��������, �� ����� � false; for(size_t i{}; i<tmpCount; i++) // ���� ������ ��������, �� if(!(tmp+i)->RfF(_inF)) return false; // ������ ��� ������� ������ �� �����; std::swap(tmp, Purchase); // ������������ ����������� if(tmp) delete[] tmp; // ������� ��������������� ������. } else { // ����� if(Purchase) delete[] Purchase; // ���� ������ ����������, ������� ������ Purchase = nullptr; // � ������������� ��������� ������� � nullptr } /** ������ �� ����� ������ Shipment **/ bool flagShipment; // ���� ������������� ������� Shipment if(!DSF(_inF, flagShipment)) return false; // ������ �� ����� ���� ������������� ������� if(!DSF(_inF, tm_size)) return false; // ������ ����� ����� �������. ���� ���� true � ����� if(flagShipment && tm_size>sZero) { // ����� ����� ����, ����� ��������������� ������: size_t tmpCount = tm_size * PrCount; // ��������� ������ �������; strItem* tmp = new(nothrow) strItem[tmpCount]; // �������� ������ ���������������� �������; if(!tmp) return false; // ���� ������ �� ��������, �� ����� � false; for(size_t i{}; i<tmpCount; i++) // ���� ������ ��������, �� if(!(tmp+i)->RfF(_inF)) return false; // ������ ��� ������� ������ �� �����; std::swap(tmp, Shipment); // ������������ ����������� if(tmp) delete[] tmp; // ������� ��������������� ������. } else { // ����� if(Shipment) delete[] Shipment; // ���� ������ ����������, ������� ������ Shipment = nullptr; // � ������������� ��������� ������� � nullptr } #ifdef DEBUG_StF_RfF long epos = _inF.tellg(); // ���������� ������� � ����� ����� cout << "clsAgregate::RfF end epos= " << epos << endl; #endif // DEBUG_StF_RfF return true; } // clsAgregate::RfF # undef DEBUG_StF_RfF // �������� ������ ���������� �� ����������� DEBUG_StF_RfF