[#BloombergLP-bslmt-OnceGuard] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::OnceGuard :relfileprefix: ../../ :mrdocs: Guard class for using `Once` safely. == Synopsis Declared in `<bslmt_once.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class OnceGuard; ---- == Description 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. == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bslmt/OnceGuard/2constructor.adoc[`OnceGuard`] [.small]#[constructor]# | Create a guard optionally associated with the specified `once` object. | xref:BloombergLP/bslmt/OnceGuard/2destructor.adoc[`~OnceGuard`] [.small]#[destructor]# | Destroy this object, completing in‐progress once work if needed. | 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`] | Enter the associated `Once` object's one‐time region if allowed. | xref:BloombergLP/bslmt/OnceGuard/isInProgress.adoc[`isInProgress`] | Return `true` 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]#