/
Alexandr_Pidkasisty
/
froma2
Обзор
Документация
Войти
/
Alexandr_Pidkasisty
/
froma2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
libsource/serialization_module.hpp
135 строк
10 KB
Alexandr Pidkasisty
Файлы с исходными текстами библиотеки восстановлены в папке libsource
12 авг 2025, 13:08
Верифицирован
12 авг 2025, 13:08
0af724b
Код
Авторство
О чём код?
/** ���� ���� �������� ������ ���������� ������������ ����������� ��� �������������� �������������, ����������� ������� � ������������ ������������ ������������ ����������� "Free Operation Manager 2" (���������� FROMA2). **/ /****************************************************************************************************/ /****************************************************************************************************/ /*** ***/ /*** Copyright � 2025 ����������� ��������� �������� ***/ /*** ***/ /*** ������ �������� ��������� �����, ���������� ����� ������� ������������ ����������� � ***/ /*** ������������� ������������ (����� � ����������� �����������), ������������ ������������ ***/ /*** ����������� ����������� ��� �����������, ������� �������������� ����� �� �������������, ***/ /*** �����������, ���������, �������, ����������, ���������������, ����������������� �/��� ***/ /*** ������� ����� ������������ �����������, � ����� �����, ������� ��������������� ������ ***/ /*** ����������� �����������, ��� ���������� ��������� �������: ***/ /*** ***/ /*** ��������� ���� ����������� �� ��������� ����� � ������ ������� ������ ���� �������� �� ***/ /*** ��� ����� ��� �������� ����� ������� ������������ �����������. ***/ /*** ***/ /*** ������ ����������� ����������� ��������������� ���� ���ܻ, ��� �����-���� ��������, ���� ***/ /*** ���������� ��� ���������������, ������� �������� �������� �����������, ������������ �� ***/ /*** ��� ����������� ���������� � ���������� ���������, �� �� ������������� ���. �� � ����� ***/ /*** ������ ������ ��� ��������������� �� ����� ��������������� �� �����-���� �����, �� ����� ***/ /*** ��� �� ���� �����������, � ��� �����, ��� �������� ���������, ������� ��� ���� ��������, ***/ /*** ��������� ��-�� ������������� ������������ ����������� ��� ���� �������� � ����������� ***/ /*** ������������. ***/ /*** ***/ /****************************************************************************************************/ /****************************************************************************************************/ #ifndef FROMA2_SERIALIZATION_MODULE_H_INCLUDED #define FROMA2_SERIALIZATION_MODULE_H_INCLUDED #include <iostream> // ������������ ���� � ��������, ��������� � ����������� ��� ����������� �����-������ #include <string> // ������������ ���� ��� ������ �� �������� #include <fstream> // ������������ ���� ��� ������ � ������� using namespace std; /*************************************************************************************************************************/ /** **/ /** ������� � ����������� ������������� ������� ��� ����������� � ���� � ������ �� ����� **/ /** **/ /*************************************************************************************************************************/ /** version from 2024.10.13 **/ template<typename T> constexpr bool is_srlzd_v = std::is_trivially_copyable<T>::value; // ������� �������� �������� � ��������� trait � ������ "is_srlz_v" // ������ is_srlz_v ���������� �� ����� ����������: ���� � �������� ���� // T ������������� ���������� ���������� ���, �� ��������� ������� true, // ����� false (https://cplusplus.com/reference/type_traits/is_trivially_copyable/) namespace nmSrlz { const size_t sZero = 0; const string EmpStr =""; } // namespace nmSrlz template<typename T=string> bool SEF(ofstream &_outF, string& str) { // ����������� ������� ��� ������������ ������ � ���� // ��������� ������: &_outF - ������ �� �������� ���������� _outF ���� ofstream; &str - ������ �� ���������� str ���� string size_t len = str.length(); // ���������� ����� ���������� ���� string _outF.write((char*)&len, sizeof(size_t)); // �������� �������� len � ���� char � ���������� ��� � ���������� _outF if(len>nmSrlz::sZero) // ���� ������ ��������� �����, �� _outF.write(str.data(), len); // ���������� ���� ������ �������� ������ len � ���������� _outF if(_outF.bad()) return false; // �������� ��������� ����� ������ badbit (https://cplusplus.com/reference/ios/ios/rdstate/) return true; // https://learntutorials.net/ru/cplusplus/topic/496/��������-����-����� }; // SEF-����������� ������� template<typename T, class=std::enable_if_t<is_srlzd_v<T>>> // ���������� ������� T ����, ���������� � ������������ bool SEF(ofstream &_outF, T x[], size_t Cnt) { // ��������� ������� ��� ������������ ������� ������������� ���� T // � ����. ��������� ������: &_outF - ������ �� �������� ���������� _outF ���� ofstream; x - ��������� �� ������ ������� // �������; Cnt - ��������, ������ ���������� ��������� ������� bool flag; // ���� ������������� �������. ���� ��������� �� ������ �� ����� nullptr if(x && Cnt>nmSrlz::sZero) flag = true; else flag = false; // � ����� ������� ������ ����, ���� true. ����� false _outF.write((char*)&flag, sizeof(bool)); // ���������� ���� � ����� if(flag) // ���� ���� true, �� ���������� ������ � ����� for(size_t j=nmSrlz::sZero; j<Cnt; j++) { // �������� ������ ������� ������� � ����� � ���� char � ����������, _outF.write((char*)(x+j), sizeof(*(x+j))); // ��������� ��������� ���������� (������ �������� ��������� �������). }; // � �������� ������� ����� ����������� ������ ������� �� ������ x+j. if(_outF.bad()) return false; // �������� ��������� ����� ������ badbit (https://cplusplus.com/reference/ios/ios/rdstate/) return true; }; // SEF-������ template<typename T, class=std::enable_if_t<is_srlzd_v<T>>> // ���������� ������� T ����, ���������� � ������������ bool SEF(ofstream &_outF, T& x) { // ��������� ������� ��� ������������ �������� ������������� ���� T // � ����. ��������� ������: &_outF - ������ �� �������� ���������� _outF ���� ofstream; &x - ������ �� ���������� ���� T _outF.write((char*)&x, sizeof(x)); // ���������� ��������, ������������� �� ������ &x � �������� x if(_outF.bad()) return false; // �������� ��������� ����� ������ badbit (https://cplusplus.com/reference/ios/ios/rdstate/) return true; }; // SEF-������ template<typename T=string> bool DSF(ifstream &_inF, string& str) { // ����������� ������� ��� �������������� ������ �� �����, ���������� // ���� � ������� ������� bool SEF(ofstream &_outF, string& str). ��������� ������: &_inF - ������ �� �������� ���������� _inF // ���� ifstream; &str - ������ �� ���������� str ���� string size_t len; // ��������� ����������: ����� ������������ ������ � �������� _inF.read((char*)&len, sizeof(size_t)); // ������ �� �������� ���������� ����� ������� ������ char c=nmSrlz::sZero; // ����������� ��������������� ���������� ���� ������ �������� "�����" str=nmSrlz::EmpStr; // ����������� �������� "�����" ������� ������ for(size_t j=nmSrlz::sZero; j<len; j++) { // � ����� ������ �� �������� ���������� ������ ������ ������� ������ _inF.read((char*)&c, sizeof(char)); // � ���������� ��� �� ��������������� ���������� str += c; // ��������� � ������� ������ ������� ������ ��������� ������ // �� ��������������� ����������, }; if(_inF.bad()) return false; // �������� ��������� ����� ������ badbit (https://cplusplus.com/reference/ios/ios/rdstate/) return true; }; // DSF-����������� ������� template<typename T, class=std::enable_if_t<is_srlzd_v<T>>> // ���������� ������� T ����, ���������� � ������������ bool DSF(ifstream &_inF, T x[], size_t Cnt) { // ��������� ������� ��� �������������� ������� ������������� ���� T // �� �����, ���������� ���� � ������� ������� bool SEF(ofstream &_outF, T& x, size_t Cnt). ��������� ������: &_inF - ������ �� // �������� ���������� _inF ���� ifstream; x - ������ �� ������ ������� �������; Cnt - ��������, ������ ���������� // ��������� ������� bool flag; // ���� ������������� ������� _inF.read((char*)&flag, sizeof(bool)); // ������ ���� �� ����� if(flag) // ���� ����������� ���� true, �� for(size_t i=nmSrlz::sZero; i<Cnt; i++) { // ������ �� ����� ������ ������� ������� � �����, ��������� ��������� _inF.read((char*)(x+i), sizeof(*(x+i))); // ���������� (������ �������� ��������� �������). � �������� ������� } // ����� ����������� ������ ������� �� ������ x+i. else x = nullptr; // ���� ���� false, �� ������������� ��������� ������� �� nullptr if(_inF.bad()) return false; // �������� ��������� ����� ������ badbit (https://cplusplus.com/reference/ios/ios/rdstate/) return true; }; // DSF - ��������� ������� template<typename T, class=std::enable_if_t<is_srlzd_v<T>>> // ���������� ������� T ����, ���������� � ������������ bool DSF(ifstream &_inF, T& x) { // ��������� ������� ��� �������������� �������� ������������� ���� T // �� �����. ��������� ������: &_inF - ������ �� �������� ���������� _inF ���� ifstream; &x - ������ �� ���������� ���� T _inF.read((char*)&x, sizeof(x)); // ������ �� ����� ���� ���������� ����������� �������� x � ���������� � x if(_inF.bad()) return false; // �������� ��������� ����� ������ badbit (https://cplusplus.com/reference/ios/ios/rdstate/) return true; // ��� � ���������� x }; // DSF - ��������� ������� #endif // FROMA2_SERIALIZATION_MODULE_H_INCLUDED