[odb-users] Lazy pointer question

Paul Stath PStath at jmawireless.com
Mon Mar 12 11:18:48 EDT 2018


Hi Boris,

I have a question about using lazy pointers that I'm having trouble with.
I have successfully used lazy pointers in a previous project for a different company, but no longer have access to that code, so I'm having to do it again.  (frown)

I have an object B that has a lazy_weak_pointer<C> to object C.
Object B is loaded due to an eager (std::shared_ptr<B>) pointer while object A is loaded.
Relationship of objects A and B don't factor into this question, correct?

How does one determine if object B is linked to object C without calling the lazy_weak_ptr<C>::load() method?

In reading the documentation, section 6.4 describes contains the interface for the generic class lazy_pointer.
Right above the loaded() method is a comment containing the following table:

NULL                     loaded()
true                       true                       NULL pointer to transient object
false                       true                        valid pointer to persistent object
true                        false                      unloaded pointer to persistent object
false                       false                       valid pointer to transient object

I also searched the odb-users mailing list archive and discovered the following topic:  https://www.codesynthesis.com/pipermail/odb-users/2016-June/003290.html

Combining the manual and this mailing list entry, I have the following question:

For a lazy_weak_ptr<C>:
Does this mean the first column is the same as calling lazy_weak_ptr<C>.expired()?
For a lazy_shared_ptr<C>:
What does the first column indicate?
Is that a simple bool check of the lazy_shared_ptr<C> instance?
if (c_ptr && c_ptr.loaded())  { // valid pointer to persistent object }

---
Paul Stath
Senior Systems Software Engineer
JMA Wireless
pstath at jmawireless


More information about the odb-users mailing list