infinipaint/include/Helpers/NetworkingObjects/NetObjTemporaryPtr.decl.hpp

62 lines
3.3 KiB
C++
Raw Normal View History

/*
* InfiniPaint
* Copyright (C) 2025-2026 Yousef Khadadeh
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "NetObjID.hpp"
#include <type_traits>
#include <cereal/archives/portable_binary.hpp>
#include "NetObjOwnerPtr.decl.hpp"
#include "../Networking/NetServer.hpp"
namespace NetworkingObjects {
class NetObjManager;
template <typename T> class NetObjTemporaryPtr {
public:
NetObjTemporaryPtr();
NetObjTemporaryPtr(const NetObjTemporaryPtr& other);
NetObjTemporaryPtr(const NetObjOwnerPtr<T>& owner);
NetObjTemporaryPtr& operator=(const NetObjTemporaryPtr& other);
template <typename S> NetObjTemporaryPtr<S> cast() const;
NetObjManager* get_obj_man() const;
NetObjID get_net_id() const;
T* get() const;
std::add_lvalue_reference_t<T> operator*() const requires(!std::is_void_v<T>);
T* operator->() const;
operator bool() const;
bool operator!=(const NetObjTemporaryPtr<T>& rhs) const;
bool operator==(const NetObjTemporaryPtr<T>& rhs) const;
bool operator!=(const NetObjOwnerPtr<T>& rhs) const;
bool operator==(const NetObjOwnerPtr<T>& rhs) const;
void send_client_update(const std::string& channel, std::function<void(const NetObjTemporaryPtr<T>&, cereal::PortableBinaryOutputArchive&)> sendUpdateFunc) const;
void send_server_update_to_client(const std::shared_ptr<NetServer::ClientData>& clientToSendTo, const std::string& channel, std::function<void(const NetObjTemporaryPtr<T>&, cereal::PortableBinaryOutputArchive&)> sendUpdateFunc) const;
void send_server_update_to_all_clients_except(const std::shared_ptr<NetServer::ClientData>& clientToNotSendTo, const std::string& channel, std::function<void(const NetObjTemporaryPtr<T>&, cereal::PortableBinaryOutputArchive&)> sendUpdateFunc) const;
void send_server_update_to_all_clients(const std::string& channel, std::function<void(const NetObjTemporaryPtr<T>&, cereal::PortableBinaryOutputArchive&)> sendUpdateFunc) const;
void send_update_to_all(const std::string& channel, std::function<void(const NetObjTemporaryPtr<T>&, cereal::PortableBinaryOutputArchive&)> sendUpdateFunc) const;
void write_create_message(cereal::PortableBinaryOutputArchive& a) const;
private:
friend class NetObjManager;
template <typename S> friend class NetObjWeakPtr;
2025-12-11 22:41:53 +03:00
template <typename S> friend class NetObjTemporaryPtr;
NetObjTemporaryPtr(NetObjManager* initObjMan, NetObjID initID, T* initRawPtr);
NetObjManager* objMan;
NetObjID id;
T* rawPtr;
};
}