14#ifndef OR_TOOLS_SAT_MODEL_H_
15#define OR_TOOLS_SAT_MODEL_H_
27#include "absl/container/flat_hash_map.h"
28#include "absl/log/check.h"
29#include "absl/meta/type_traits.h"
49 for (
int i = cleanup_list_.size() - 1;
i >= 0; --
i) {
50 cleanup_list_[
i].reset();
95 T
Get(std::function<T(
const Model&)> f)
const {
113 template <
typename T>
116 auto find = singletons_.find(type_id);
117 if (find != singletons_.end()) {
118 return static_cast<T*
>(find->second);
123 T* new_t = MyNew<T>(0);
124 singletons_[type_id] = new_t;
134 template <
typename T>
137 return it != singletons_.end() ?
static_cast<const T*
>(it->second)
144 template <
typename T>
147 return it != singletons_.end() ?
static_cast<T*
>(it->second) :
nullptr;
155 template <
typename T>
157 cleanup_list_.emplace_back(
new Delete<T>(t));
166 template <
typename T>
168 T* new_t = MyNew<T>(0);
178 template <
typename T>
181 CHECK(!singletons_.contains(type_id));
182 singletons_[type_id] = non_owned_class;
185 const std::string&
Name()
const {
return name_; }
193 template <
typename T>
194 decltype(T(
static_cast<Model*
>(
nullptr)))* MyNew(
int) {
197 template <
typename T>
202 const std::string name_;
205 absl::flat_hash_map< size_t,
void*> singletons_;
207 struct DeleteInterface {
208 virtual ~DeleteInterface() =
default;
210 template <
typename T>
211 class Delete :
public DeleteInterface {
213 explicit Delete(T* t) : to_delete_(t) {}
214 ~Delete()
override =
default;
217 std::unique_ptr<T> to_delete_;
225 std::vector<std::unique_ptr<DeleteInterface>> cleanup_list_;
T Add(std::function< T(Model *)> f)
T Get(std::function< T(const Model &)> f) const
Similar to Add() but this is const.
const std::string & Name() const
Model(const Model &)=delete
This type is neither copyable nor movable.
void Register(T *non_owned_class)
Model & operator=(const Model &)=delete
const std::string name
A name for logging purposes.
absl::Status Delete(absl::string_view path, Options options)
In SWIG mode, we don't want anything besides these top-level includes.