Loading...
Searching...
No Matches
eonc::shared_flag Struct Reference

Bool storage shared with Matter. More...

#include <ParametersOptions.h>

Public Member Functions

 shared_flag ()=default
 shared_flag (bool value)
 shared_flag (const shared_flag &other)
 shared_flag (shared_flag &&other) noexcept
shared_flag & operator= (const shared_flag &other)
shared_flag & operator= (shared_flag &&other) noexcept
shared_flag & operator= (bool value)
 operator bool () const
std::shared_ptr< bool > share () const

Public Attributes

std::shared_ptr< bool > bit {std::make_shared<bool>(false)}

Private Member Functions

std::shared_ptr< bool > & ensure ()

Detailed Description

Bool storage shared with Matter.

Assignment updates the same cell, so a Matter built from this Parameters sees a later write. Copying the flag makes a new cell. Destroying the Parameters leaves the cell with its last value for any Matter that still holds it. The cell is not the Parameters address, so a new Parameters allocated in the same place does not alias an older Matter.

Definition at line 31 of file ParametersOptions.h.

Constructor & Destructor Documentation

◆ shared_flag() [1/4]

eonc::shared_flag::shared_flag ( )
default

◆ shared_flag() [2/4]

eonc::shared_flag::shared_flag ( bool value)
inlineexplicit

Definition at line 35 of file ParametersOptions.h.

35: bit(std::make_shared<bool>(value)) {}
std::shared_ptr< bool > bit

◆ shared_flag() [3/4]

eonc::shared_flag::shared_flag ( const shared_flag & other)
inline

Definition at line 36 of file ParametersOptions.h.

37 : bit(std::make_shared<bool>(static_cast<bool>(other))) {}

◆ shared_flag() [4/4]

eonc::shared_flag::shared_flag ( shared_flag && other)
inlinenoexcept

Definition at line 38 of file ParametersOptions.h.

38: bit(std::move(other.bit)) {}

Member Function Documentation

◆ ensure()

std::shared_ptr< bool > & eonc::shared_flag::ensure ( )
inlineprivate

Definition at line 66 of file ParametersOptions.h.

66 {
67 if (!bit) {
68 bit = std::make_shared<bool>(false);
69 }
70 return bit;
71 }

◆ operator bool()

eonc::shared_flag::operator bool ( ) const
inline

Definition at line 61 of file ParametersOptions.h.

61{ return bit && *bit; }

◆ operator=() [1/3]

shared_flag & eonc::shared_flag::operator= ( bool value)
inline

Definition at line 56 of file ParametersOptions.h.

56 {
57 *ensure() = value;
58 return *this;
59 }
std::shared_ptr< bool > & ensure()

◆ operator=() [2/3]

shared_flag & eonc::shared_flag::operator= ( const shared_flag & other)
inline

Definition at line 40 of file ParametersOptions.h.

40 {
41 if (this != &other) {
42 *ensure() = static_cast<bool>(other);
43 }
44 return *this;
45 }

◆ operator=() [3/3]

shared_flag & eonc::shared_flag::operator= ( shared_flag && other)
inlinenoexcept

Definition at line 46 of file ParametersOptions.h.

46 {
47 if (this != &other) {
48 if (bit && other.bit) {
49 *bit = *other.bit;
50 } else {
51 bit = std::move(other.bit);
52 }
53 }
54 return *this;
55 }

◆ share()

std::shared_ptr< bool > eonc::shared_flag::share ( ) const
inlinenodiscard

Definition at line 63 of file ParametersOptions.h.

63{ return bit; }

Member Data Documentation

◆ bit

std::shared_ptr<bool> eonc::shared_flag::bit {std::make_shared<bool>(false)}

Definition at line 32 of file ParametersOptions.h.

32{std::make_shared<bool>(false)};

The documentation for this struct was generated from the following file: