17#include <boost/interprocess/exceptions.hpp>
19#include <boost/mpl/size.hpp>
36namespace interprocess = boost::interprocess;
52 virtual std::shared_ptr<const Object>
object()
const = 0;
62 template<
class ObjType>
67 typedef std::shared_ptr<Object>
ptr;
71 template<
class Interface>
74 return dynamic_cast<const Interface *
>(
this);
77 std::shared_ptr<const Object>
object()
const override
79 return static_cast<const Object *
>(
this)->shared_from_this();
102 UNSTRUCTUREDGRID = 24,
104 RECTILINEARGRID = 26,
108 VERTEXOWNERLIST = 95,
117 static const char *toString(Type v);
124 bool isComplete()
const;
126 virtual std::set<Object::const_ptr> referencedObjects()
const;
135 static Object *createEmpty(
const std::string &name = std::string());
137 virtual void refresh()
const;
138 virtual bool check()
const;
139 virtual void updateInternals();
141 virtual bool isEmpty()
const;
142 virtual bool isEmpty();
144 static std::shared_ptr<Object>
as(std::shared_ptr<Object>
ptr) {
return ptr; }
145 static std::shared_ptr<const Object>
as(std::shared_ptr<const Object>
ptr) {
return ptr; }
149 Type getType()
const;
150 std::string getName()
const;
152 int getBlock()
const;
153 int getNumBlocks()
const;
156 int getNumTimesteps()
const;
157 int getIteration()
const;
158 int getExecutionCounter()
const;
159 int getCreator()
const;
162 void setBlock(
const int block);
163 void setNumBlocks(
const int num);
164 void setRealTime(
double time);
165 void setTimestep(
const int timestep);
166 void setNumTimesteps(
const int num);
167 void setIteration(
const int num);
168 void setExecutionCounter(
const int count);
169 void setCreator(
const int id);
170 void setTransform(
const Matrix4 &transform);
172 const Meta &meta()
const;
173 void setMeta(
const Meta &meta);
175 void addAttribute(
const std::string &key,
const std::string &value =
"");
176 void setAttributeList(
const std::string &key,
const std::vector<std::string> &values);
178 bool hasAttribute(
const std::string &key)
const;
179 std::string getAttribute(
const std::string &key)
const;
180 std::vector<std::string> getAttributes(
const std::string &key)
const;
181 std::vector<std::string> getAttributeList()
const;
185 bool hasAttachment(
const std::string &key)
const;
188 bool removeAttachment(
const std::string &key)
const;
192 int refcount()
const;
194 template<
class Archive>
195 static Object *loadObject(Archive &ar);
197 template<
class Archive>
198 void saveObject(Archive &ar)
const;
202#ifdef USE_INTROSPECTION_ARCHIVE
203 virtual void save(FindObjectReferenceOArchive &ar)
const = 0;
217 static void publish(
const Data *d);
218 static Object *create(Data *);
222 template<
class Archive>
252 void addAttribute(
const std::string &key,
const std::string &value =
"");
253 V_COREEXPORT void setAttributeList(
const std::string &key,
const std::vector<std::string> &values);
254 void copyAttributes(
const ObjectData *src,
bool replace);
255 bool hasAttribute(
const std::string &key)
const;
256 std::string getAttribute(
const std::string &key)
const;
257 V_COREEXPORT std::vector<std::string> getAttributes(
const std::string &key)
const;
258 V_COREEXPORT std::vector<std::string> getAttributeList()
const;
261 mutable std::recursive_mutex attachment_mutex;
266 typedef boost::interprocess::scoped_lock<boost::interprocess::interprocess_recursive_mutex>
268 typedef interprocess::offset_ptr<const ObjectData>
Attachment;
279 void copyAttachments(
const ObjectData *src,
bool replace);
280 bool hasAttachment(
const std::string &key)
const;
282 bool removeAttachment(
const std::string &key);
290 V_COREEXPORT void *
operator new(std::size_t size,
void *ptr);
292 V_COREEXPORT void operator delete(
void *ptr,
void *voidptr2);
299 V_COREEXPORT void referenceResolved(
const std::function<
void()> &completeCallback);
302 template<
class Archive>
304 template<
class Archive>
305 void load(Archive &ar);
312#ifdef USE_BOOST_ARCHIVE
313extern template Object V_COREEXPORT *V_COREEXPORT::loadObject<boost_iarchive>(boost_iarchive &ar);
314extern template void V_COREEXPORT Object::saveObject<boost_oarchive>(boost_oarchive &ar)
const;
315extern template void V_COREEXPORT Object::serialize<boost_iarchive>(boost_iarchive &ar);
316extern template void V_COREEXPORT Object::serialize<boost_oarchive>(boost_oarchive &ar);
317extern template void V_COREEXPORT Object::Data::load<boost_iarchive>(boost_iarchive &ar);
318extern template void V_COREEXPORT Object::Data::save<boost_oarchive>(boost_oarchive &ar)
const;
334 typedef Object *(*CreateEmptyFunc)(
const std::string &name);
336 typedef void (*DestroyFunc)(
const std::string &name);
347 assert(typeMap().find(
id) == typeMap().end());
356 static const struct FunctionTable &getType(
int id);
358 static CreateFunc getCreator(
int id);
359 static DestroyFunc getDestroyer(
int id);
362 typedef std::map<int, FunctionTable> TypeMap;
364 static TypeMap &typeMap();
368#define V_CHECK(true_expr) \
369 if (!(true_expr)) { \
370 std::cerr << __FILE__ << ":" << __LINE__ << ": " \
371 << "CONSISTENCY CHECK FAILURE on " << this->getName() << " " << this->meta() << ": " << #true_expr \
373 std::stringstream str; \
374 str << __FILE__ << ":" << __LINE__ << ": consistency check failure: " << #true_expr; \
375 throw(vistle::except::consistency_error(str.str())); \
381#define V_OBJECT(ObjType) \
383 typedef std::shared_ptr<ObjType> ptr; \
384 typedef std::shared_ptr<const ObjType> const_ptr; \
385 typedef ObjType Class; \
386 static Object::Type type(); \
387 static const char *typeName() { return #ObjType; } \
388 static std::shared_ptr<const ObjType> as(std::shared_ptr<const Object> ptr) \
390 return std::dynamic_pointer_cast<const ObjType>(ptr); \
392 static std::shared_ptr<ObjType> as(std::shared_ptr<Object> ptr) \
394 return std::dynamic_pointer_cast<ObjType>(ptr); \
396 static Object *createFromData(Object::Data *data) { return new ObjType(static_cast<ObjType::Data *>(data)); } \
397 std::shared_ptr<const Object> object() const override \
399 return static_cast<const Object *>(this)->shared_from_this(); \
401 Object::ptr cloneInternal() const override \
403 const std::string n(Shm::the().createObjectId()); \
404 Data *data = shm<Data>::construct(n)(*d(), n); \
406 return Object::ptr(createFromData(data)); \
408 ptr clone() const { return ObjType::as(cloneInternal()); } \
409 ptr cloneType() const { return ObjType::as(cloneTypeInternal()); } \
410 Object::ptr cloneTypeInternal() const override { return Object::ptr(new ObjType(Object::Initialized)); } \
411 static Object *createEmpty(const std::string &name) \
414 return new ObjType(Object::Initialized); \
415 auto d = Data::createNamed(ObjType::type(), name); \
416 return new ObjType(d); \
418 template<class OtherType> \
419 static ptr clone(typename OtherType::ptr other) \
421 const std::string n(Shm::the().createObjectId()); \
422 typename ObjType::Data *data = shm<typename ObjType::Data>::construct(n)(*other->d(), n); \
423 assert(data->type == ObjType::type()); \
424 ObjType *ret = dynamic_cast<ObjType *>(createFromData(data)); \
429 template<class OtherType> \
430 static ptr clone(typename OtherType::const_ptr other) \
432 return ObjType::clone<OtherType>(std::const_pointer_cast<OtherType>(other)); \
434 static void destroy(const std::string &name) { shm<ObjType::Data>::destroy(name); } \
435 void refresh() const override \
440 void refreshImpl() const; \
441 explicit ObjType(Object::InitializedFlags): Base(ObjType::Data::create()) { refreshImpl(); } \
442 virtual bool isEmpty() override; \
443 virtual bool isEmpty() const override; \
444 bool check() const override \
449 if (!Base::check()) \
451 return checkImpl(); \
454 const Data *d() const { return static_cast<Data *>(Object::m_data); } \
455 Data *d() { return static_cast<Data *>(Object::m_data); } \
457 ARCHIVE_REGISTRATION_INLINE \
459 bool checkImpl() const; \
460 explicit ObjType(Data *data); \
464 ARCHIVE_ACCESS_SPLIT \
465 template<class Archive> \
466 void load(Archive &ar); \
467 template<class Archive> \
468 void save(Archive &ar) const; \
469 friend std::shared_ptr<const Object> Shm::getObjectFromHandle(const shm_handle_t &) const; \
470 friend shm_handle_t Shm::getHandleFromObject(std::shared_ptr<const Object>) const; \
471 friend Object *Object::create(Object::Data *); \
472 friend class ObjectTypeRegistry
474#define V_DATA_BEGIN(ObjType) \
476 struct V_COREEXPORT Data: public Base::Data { \
477 static Data *createNamed(Object::Type id, const std::string &name); \
478 Data(Object::Type id, const std::string &name, const Meta &meta); \
479 Data(const Data &other, const std::string &name)
481#define V_DATA_END(ObjType) \
483 friend class ObjType; \
485 template<class Archive> \
486 void serialize(Archive &ar); \
490#ifdef USE_BOOST_ARCHIVE
492#define V_OBJECT_DECL(ObjType) \
493 extern template void V_COREEXPORT ObjType::load<yas_iarchive>(yas_iarchive & ar); \
494 extern template void V_COREEXPORT ObjType::load<boost_iarchive>(boost_iarchive & ar); \
495 extern template void V_COREEXPORT ObjType::save<yas_oarchive>(yas_oarchive & ar) const; \
496 extern template void V_COREEXPORT ObjType::save<boost_oarchive>(boost_oarchive & ar) const; \
497 extern template void V_COREEXPORT ObjType::Data::serialize<yas_iarchive>(yas_iarchive & ar); \
498 extern template void V_COREEXPORT ObjType::Data::serialize<boost_iarchive>(boost_iarchive & ar); \
499 extern template void V_COREEXPORT ObjType::Data::serialize<yas_oarchive>(yas_oarchive & ar); \
500 extern template void V_COREEXPORT ObjType::Data::serialize<boost_oarchive>(boost_oarchive & ar);
502#define V_OBJECT_INST(ObjType) \
503 template void V_COREEXPORT ObjType::load<yas_iarchive>(yas_iarchive & ar); \
504 template void V_COREEXPORT ObjType::load<boost_iarchive>(boost_iarchive & ar); \
505 template void V_COREEXPORT ObjType::save<yas_oarchive>(yas_oarchive & ar) const; \
506 template void V_COREEXPORT ObjType::save<boost_oarchive>(boost_oarchive & ar) const; \
507 template void V_COREEXPORT ObjType::Data::serialize<yas_iarchive>(yas_iarchive & ar); \
508 template void V_COREEXPORT ObjType::Data::serialize<boost_iarchive>(boost_iarchive & ar); \
509 template void V_COREEXPORT ObjType::Data::serialize<yas_oarchive>(yas_oarchive & ar); \
510 template void V_COREEXPORT ObjType::Data::serialize<boost_oarchive>(boost_oarchive & ar);
512#define V_OBJECT_DECL(ObjType) \
513 extern template void V_COREEXPORT ObjType::load<boost_iarchive>(boost_iarchive & ar); \
514 extern template void V_COREEXPORT ObjType::save<boost_oarchive>(boost_oarchive & ar) const; \
515 extern template void V_COREEXPORT ObjType::Data::serialize<boost_iarchive>(boost_iarchive & ar); \
516 extern template void V_COREEXPORT ObjType::Data::serialize<boost_oarchive>(boost_oarchive & ar);
518#define V_OBJECT_INST(ObjType) \
519 template void V_COREEXPORT ObjType::load<boost_iarchive>(boost_iarchive & ar); \
520 template void V_COREEXPORT ObjType::save<boost_oarchive>(boost_oarchive & ar) const; \
521 template void V_COREEXPORT ObjType::Data::serialize<boost_iarchive>(boost_iarchive & ar); \
522 template void V_COREEXPORT ObjType::Data::serialize<boost_oarchive>(boost_oarchive & ar);
525#define V_OBJECT_DECL(ObjType) \
526 extern template void V_COREEXPORT ObjType::load<yas_iarchive>(yas_iarchive & ar); \
527 extern template void V_COREEXPORT ObjType::save<yas_oarchive>(yas_oarchive & ar) const; \
528 extern template void V_COREEXPORT ObjType::Data::serialize<yas_iarchive>(yas_iarchive & ar); \
529 extern template void V_COREEXPORT ObjType::Data::serialize<yas_oarchive>(yas_oarchive & ar);
531#define V_OBJECT_INST(ObjType) \
532 template void V_COREEXPORT ObjType::load<yas_iarchive>(yas_iarchive & ar); \
533 template void V_COREEXPORT ObjType::save<yas_oarchive>(yas_oarchive & ar) const; \
534 template void V_COREEXPORT ObjType::Data::serialize<yas_iarchive>(yas_iarchive & ar); \
535 template void V_COREEXPORT ObjType::Data::serialize<yas_oarchive>(yas_oarchive & ar);
539#define V_OBJECT_TYPE(ObjType, id) \
540 Object::Type ObjType::type() { return id; }
542#define V_OBJECT_CREATE_NAMED(ObjType) \
543 ObjType::Data::Data(Object::Type id, const std::string &name, const Meta &meta) \
544 : ObjType::Base::Data(id, name, meta) \
548 ObjType::Data *ObjType::Data::createNamed(Object::Type id, const std::string &name) \
550 Data *t = shm<Data>::construct(name)(id, name, Meta()); \
555#define V_OBJECT_CTOR(ObjType) \
556 V_OBJECT_CREATE_NAMED(ObjType) \
557 ObjType::ObjType(ObjType::Data *data): ObjType::Base(data) { refreshImpl(); } \
558 ObjType::ObjType(): ObjType::Base() { refreshImpl(); }
560#define V_OBJECT_IMPL_LOAD(ObjType) \
561 template<class Archive> \
562 void ObjType::load(Archive &ar) \
565 ar &V_NAME(ar, "name", name); \
566 int type = Object::UNKNOWN; \
567 ar &V_NAME(ar, "type", type); \
568 if (!ar.currentObject()) \
569 ar.setCurrentObject(Object::m_data); \
570 d()->template serialize<Archive>(ar); \
571 assert(type == Object::getType()); \
574#define V_OBJECT_IMPL_SAVE(ObjType) \
575 template<class Archive> \
576 void ObjType::save(Archive &ar) const \
578 int type = Object::getType(); \
579 std::string name = d()->name; \
580 ar &V_NAME(ar, "name", name); \
581 ar &V_NAME(ar, "type", type); \
582 const_cast<Data *>(d())->template serialize<Archive>(ar); \
585#define V_OBJECT_IMPL(ObjType) \
586 V_OBJECT_IMPL_LOAD(ObjType) \
587 V_OBJECT_IMPL_SAVE(ObjType)
593template<
typename O,
typename... Args>
596 return typename O::ptr(
new O{std::forward<Args>(args)...});
#define ARCHIVE_ASSUME_ABSTRACT(obj)
Definition: archives_config.h:466
#define ARCHIVE_ACCESS
Definition: archives_config.h:465
#define ARCHIVE_REGISTRATION(override)
Definition: archives_config.h:543
#define ARCHIVE_ACCESS_SPLIT
Definition: archives_config.h:502
virtual std::shared_ptr< const Object > object() const =0
virtual ~ObjectInterfaceBase()
Definition: object.h:55
CreateFunc create
Definition: object.h:340
CreateEmptyFunc createEmpty
Definition: object.h:339
DestroyFunc destroy
Definition: object.h:341
static void registerType(int id)
Definition: object.h:345
InitializedFlags
Definition: object.h:82
static const char * typeName()
Definition: object.h:128
static std::shared_ptr< const Object > as(std::shared_ptr< const Object > ptr)
Definition: object.h:145
static std::shared_ptr< Object > as(std::shared_ptr< Object > ptr)
Definition: object.h:144
std::shared_ptr< const Object > const_ptr
Definition: object.h:68
Data * d() const
Definition: object.h:211
const Interface * getInterface() const
Definition: object.h:72
Data * m_data
Definition: object.h:208
ObjectData Data
Definition: object.h:69
std::shared_ptr< const Object > object() const override
Definition: object.h:77
Type
Definition: object.h:84
@ UNKNOWN
Definition: object.h:89
virtual Object::ptr cloneInternal() const =0
std::shared_ptr< Object > ptr
Definition: object.h:67
virtual Object::ptr cloneTypeInternal() const =0
void markAsRemoved(const std::string &name)
Definition: shm.cpp:481
Definition: shm_obj_ref.h:15
Definition: archives.h:342
Definition: archives.h:197
#define V_COREEXPORT
Definition: export.h:9
#define V_ENUM_OUTPUT_OP(name, scope)
Definition: enum.h:72
void serialize(Archive &ar, vistle::Vector1 &v, const unsigned int version)
Definition: vector.h:105
Definition: allobjects.cpp:30
std::function< void(Object::const_ptr)> ObjectCompletionHandler
Definition: archives.h:88
void registerTypes()
Definition: allobjects.cpp:44
bool operator!=(const ParameterVector< S > &v1, const ParameterVector< S > &v2)
Definition: paramvector_impl.h:237
O::ptr make_ptr(Args &&...args)
Definition: object.h:594
managed_shm::handle_t shm_handle_t
Definition: object.h:40
V_MODULEEXPORT double getRealTime(Object::const_ptr obj)
Definition: module.cpp:162
bool operator==(const ParameterVector< S > &v1, const ParameterVector< S > &v2)
Definition: paramvector_impl.h:225
V_MODULEEXPORT int getTimestep(Object::const_ptr obj)
Definition: module.cpp:145
Eigen::Matrix< Scalar, 4, 4 > Matrix4
Definition: vector.h:44
std::function< void(const std::string &name)> ArrayCompletionHandler
Definition: archives.h:87
std::map< std::string, std::vector< std::string > > StdAttributeMap
Definition: object.h:251
std::atomic< int > unresolvedReferences
no. of not-yet-available arrays and referenced objects
Definition: object.h:236
interprocess::map< Key, AttributeList, std::less< Key >, AttributeMapAllocator > AttributeMap
Definition: object.h:248
shm< char >::string Attribute
Definition: object.h:240
std::pair< const Key, AttributeList > AttributeMapValueType
Definition: object.h:243
interprocess::map< Key, Attachment, std::less< Key >, AttachmentMapAllocator > AttachmentMap
Definition: object.h:275
ObjectData(const ObjectData &)=delete
ObjectData & operator=(const ObjectData &)=delete
ARCHIVE_ACCESS_SPLIT void save(Archive &ar) const
boost::interprocess::interprocess_recursive_mutex attachment_mutex
Definition: object.h:265
Object::Type type
Definition: object.h:234
interprocess::offset_ptr< const ObjectData > Attachment
Definition: object.h:268
Meta meta
Definition: object.h:238
shm< AttachmentMapValueType >::allocator AttachmentMapAllocator
Definition: object.h:271
shm< AttributeMapValueType >::allocator AttributeMapAllocator
Definition: object.h:244
AttributeMap attributes
Definition: object.h:250
shm< char >::string Key
Definition: object.h:241
AttachmentMap attachments
Definition: object.h:277
boost::interprocess::scoped_lock< boost::interprocess::interprocess_recursive_mutex > attachment_mutex_lock_type
Definition: object.h:267
std::pair< const Key, Attachment > AttachmentMapValueType
Definition: object.h:270
shm< Attribute >::vector AttributeList
Definition: object.h:242
boost::interprocess::basic_string< T, std::char_traits< T >, allocator > string
Definition: shm.h:112
boost::interprocess::allocator< T, managed_shm::segment_manager > allocator
Definition: shm.h:111
boost::interprocess::vector< T, allocator > vector
Definition: shm.h:113