[#BloombergLP-bslmt-OnceGuard] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::OnceGuard :relfileprefix: ../../ :mrdocs: Guard class for using `Once` safely. Construct an object of this class before conditionally entering one‐time processing code. Destroy the object when the one‐time code is complete. When used this way, this object will be in an "in‐progress" state during the time that the one‐time code is being executed. == Synopsis Declared in `<bslmt_once.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class OnceGuard; ---- == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslmt/OnceGuard/2constructor.adoc[`OnceGuard`] [.small]#[constructor]# | Initialize this object to guard the (optionally) specified `once` object. If `once` is not specified, then it must be set later using the `setOnce` method before other methods may be called. | xref:BloombergLP/bslmt/OnceGuard/2destructor.adoc[`~OnceGuard`] [.small]#[destructor]# | Destroy this object. If this object is not in an "in‐progress" state, do nothing. If this object is in an "in‐progress" state and is being destroyed in the course of normal processing, then call `leave` on the associated `Once` object. | xref:BloombergLP/bslmt/OnceGuard/cancel.adoc[`cancel`] | If this object is in the "in‐progress" state, call `cancel` on the associated `Once` object and exit the "in‐progress" state. Otherwise, do nothing. | xref:BloombergLP/bslmt/OnceGuard/enter.adoc[`enter`] | Call `enter` on the associated `Once` object and return the result. If `Once::enter` returns `true`, set this object into the "in‐progress" state. The behavior is undefined unless this object has been associated with a `Once` object, either in the constructor or using `setOnce`, or if this object is already in the "in‐progress" state. | xref:BloombergLP/bslmt/OnceGuard/isInProgress.adoc[`isInProgress`] | Return `true` if this object is in the "in‐progress" state. The object is in‐progress if `enter` has been called and returned `true` and neither `leave` nor `cancel` have been called. The one‐time code controlled by this object should only be executing if this object is in the "in‐progress" state. | xref:BloombergLP/bslmt/OnceGuard/leave.adoc[`leave`] | If this object is in the "in‐progress" state, call `leave` on the associated `Once` object and exit the "in‐progress" state. Otherwise, do nothing. | xref:BloombergLP/bslmt/OnceGuard/setOnce.adoc[`setOnce`] | Set this object to guard the specified `once` object. The behavior is undefined if this object is currently in the "in‐progress" state. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#