/* * LMDB Abstraction Layer. * Copyright (C) 2023 Yury Gubich * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include #include #include #include #include #include template QDataStream& operator << (QDataStream &out, const std::map& container) { uint32_t size = container.size(); out << size; for (const std::pair& pair : container) { out << pair; } return out; } template QDataStream& operator >> (QDataStream &in, std::map& container) { uint32_t size; in >> size; for (uint32_t i = 0; i < size; ++i) { std::pair pair; in >> pair; container.insert(pair); } return in; } template QDataStream& operator << (QDataStream &out, const std::multimap& container) { uint32_t size = container.size(); out << size; for (const std::pair& pair : container) { out << pair; } return out; } template QDataStream& operator >> (QDataStream &in, std::multimap& container) { uint32_t size; in >> size; for (uint32_t i = 0; i < size; ++i) { std::pair pair; in >> pair; container.insert(pair); } return in; } #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) template QDataStream& operator << (QDataStream &out, const std::pair& pair) { out << pair.first; out << pair.second; return out; } template QDataStream& operator >> (QDataStream &in, std::pair& container) { in >> container.first; in >> container.second; return in; } #endif template QDataStream& operator << (QDataStream &out, const std::set& container) { uint32_t size = container.size(); out << size; for (const K& value : container) { out << value; } return out; } template QDataStream& operator >> (QDataStream &in, std::set& container) { uint32_t size; in >> size; for (uint32_t i = 0; i < size; ++i) { K value; in >> value; container.insert(value); } return in; } template QDataStream& operator << (QDataStream &out, const std::multiset& container) { uint32_t size = container.size(); out << size; for (const K& value : container) { out << value; } return out; } template QDataStream& operator >> (QDataStream &in, std::multiset& container) { uint32_t size; in >> size; for (uint32_t i = 0; i < size; ++i) { K value; in >> value; container.insert(value); } return in; } template QDataStream& operator << (QDataStream &out, const std::vector& container) { uint32_t size = container.size(); out << size; for (const K& value : container) { out << value; } return out; } template QDataStream& operator >> (QDataStream &in, std::vector& container) { uint32_t size; in >> size; container.resize(size); for (uint32_t i = 0; i < size; ++i) { in >> container[i]; } return in; } template QDataStream& operator << (QDataStream &out, const std::deque& container) { uint32_t size = container.size(); out << size; for (const K& value : container) { out << value; } return out; } template QDataStream& operator >> (QDataStream &in, std::deque& container) { uint32_t size; in >> size; container.resize(size); for (uint32_t i = 0; i < size; ++i) { in >> container[i]; } return in; } template QDataStream& operator << (QDataStream &out, const std::list& container) { uint32_t size = container.size(); out << size; for (const K& value : container) { out << value; } return out; } template QDataStream& operator >> (QDataStream &in, std::list& container) { uint32_t size; in >> size; for (uint32_t i = 0; i < size; ++i) { typename std::list::iterator itr = container.emplace(container.end()); in >> *itr; } return in; }