3#include "containers/ClauseExchange.hpp"
5#include "utils/Parameters.hpp"
11#include <shared_mutex>
40 : m_sharingId(s_currentSharingId.fetch_add(1))
43 LOGDEBUG1(
"I am sharing entity %d", m_sharingId);
54 SharingEntity(
const std::vector<std::shared_ptr<SharingEntity>>& clients)
55 : m_sharingId(s_currentSharingId.fetch_add(1))
56 ,
m_clients(clients.begin(), clients.end())
58 LOGDEBUG1(
"I am sharing entity %d", m_sharingId);
83 virtual void importClauses(
const std::vector<ClauseExchangePtr>& v_clauses) = 0;
102 virtual void addClient(std::shared_ptr<SharingEntity> client)
105 LOGDEBUG3(
"Sharing Entity %d: new client %p (counts: %d)", m_sharingId, client.get(), client.use_count());
123 [&client](
const std::weak_ptr<SharingEntity>& wp) { return wp.lock() == client; }),
126 LOGDEBUG3(
"Sharing Entity %d: removed client %p", m_sharingId, client.get());
166 return client->importClause(clause);
180 bool exported =
false;
182 if (
auto sharedClient = client.lock()) {
200 for (
const auto& weakClient :
m_clients) {
201 if (
auto client = weakClient.lock()) {
202 for (
const ClauseExchangePtr& clause : clauses) {
214 inline static std::atomic<int> s_currentSharingId{ 0 };
Defines logging functions and macros for the SAT solver.
#define LOGDEBUG3(...)
Log a debug message with verbosity level 4 and magenta color.
Definition Logger.hpp:229
#define LOGDEBUG1(...)
Log a debug message with verbosity level 1 and blue color.
Definition Logger.hpp:213
A base class representing entities that can exchange clauses between themselves.
Definition SharingEntity.hpp:29
SharingEntity()
Construct a new SharingEntity object.
Definition SharingEntity.hpp:39
void setSharingId(int _id)
Set the sharing ID of this entity.
Definition SharingEntity.hpp:95
virtual void importClauses(const std::vector< ClauseExchangePtr > &v_clauses)=0
Import multiple clauses to this sharing entity.
void clearClients()
Remove all clients.
Definition SharingEntity.hpp:146
virtual bool importClause(const ClauseExchangePtr &clause)=0
Import a single clause to this sharing entity.
virtual ~SharingEntity()
Destroy the SharingEntity object.
Definition SharingEntity.hpp:64
size_t getClientCount() const
Get the current number of clients.
Definition SharingEntity.hpp:137
void exportClauses(const std::vector< ClauseExchangePtr > &clauses)
Export multiple clauses to all registered clients.
Definition SharingEntity.hpp:197
virtual bool exportClauseToClient(const ClauseExchangePtr &clause, std::shared_ptr< SharingEntity > client)
Export a clause to a specific client.
Definition SharingEntity.hpp:164
SharingEntity(const std::vector< std::shared_ptr< SharingEntity > > &clients)
Construct a new SharingEntity object.
Definition SharingEntity.hpp:54
virtual void removeClient(std::shared_ptr< SharingEntity > client)
Remove a specific client from this entity.
Definition SharingEntity.hpp:116
bool exportClause(const ClauseExchangePtr &clause)
Export a clause to all registered clients.
Definition SharingEntity.hpp:177
int getSharingId() const
Get the sharing ID of this entity.
Definition SharingEntity.hpp:89
virtual void addClient(std::shared_ptr< SharingEntity > client)
Add a client to this entity.
Definition SharingEntity.hpp:102
std::vector< std::weak_ptr< SharingEntity > > m_clients
List of weak pointers to client SharingEntities.
Definition SharingEntity.hpp:218
std::shared_mutex m_clientsMutex
Mutex to protect access to m_clients.
Definition SharingEntity.hpp:221