[#BloombergLP-bslmt-OnceGuard]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bslmt.adoc[bslmt]::OnceGuard
:relfileprefix: ../../
:mrdocs:

Guard class for using `Once` safely&period; Construct an object of this class before conditionally entering one&hyphen;time processing code&period; Destroy the object when the one&hyphen;time code is complete&period; When used this way, this object will be in an &quot;in&hyphen;progress&quot; state during the time that the one&hyphen;time code is being executed&period;

== Synopsis

Declared in `&lt;bslmt&lowbar;once&period;h&gt;`

[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&period; If `once` is not specified, then it must be set later using the `setOnce` method before other methods may be called&period;
| xref:BloombergLP/bslmt/OnceGuard/2destructor.adoc[`&#126;OnceGuard`] [.small]#[destructor]#
| Destroy this object&period; If this object is not in an &quot;in&hyphen;progress&quot; state, do nothing&period; If this object is in an &quot;in&hyphen;progress&quot; state and is being destroyed in the course of normal processing, then call `leave` on the associated `Once` object&period;
| xref:BloombergLP/bslmt/OnceGuard/cancel.adoc[`cancel`] 
| If this object is in the &quot;in&hyphen;progress&quot; state, call `cancel` on the associated `Once` object and exit the &quot;in&hyphen;progress&quot; state&period; Otherwise, do nothing&period;
| xref:BloombergLP/bslmt/OnceGuard/enter.adoc[`enter`] 
| Call `enter` on the associated `Once` object and return the result&period; If `Once&colon;&colon;enter` returns `true`, set this object into the &quot;in&hyphen;progress&quot; state&period; 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 &quot;in&hyphen;progress&quot; state&period;
| xref:BloombergLP/bslmt/OnceGuard/isInProgress.adoc[`isInProgress`] 
| Return `true` if this object is in the &quot;in&hyphen;progress&quot; state&period; The object is in&hyphen;progress if `enter` has been called and returned `true` and neither `leave` nor `cancel` have been called&period; The one&hyphen;time code controlled by this object should only be executing if this object is in the &quot;in&hyphen;progress&quot; state&period;
| xref:BloombergLP/bslmt/OnceGuard/leave.adoc[`leave`] 
| If this object is in the &quot;in&hyphen;progress&quot; state, call `leave` on the associated `Once` object and exit the &quot;in&hyphen;progress&quot; state&period; Otherwise, do nothing&period;
| xref:BloombergLP/bslmt/OnceGuard/setOnce.adoc[`setOnce`] 
| Set this object to guard the specified `once` object&period; The behavior is undefined if this object is currently in the &quot;in&hyphen;progress&quot; state&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
