creativity  v1.3.0
Agent-based model of creativity and piracy
Public Member Functions | Static Public Member Functions | Friends | List of all members
creativity::Policy Class Referencefinal

Class for interpreting and/or constructing encoded policy values. More...

#include <creativity/Policy.hpp>

Public Member Functions

constexpr Policy ()
 Default construction results in an all-disabled policy.
 
constexpr Policy (uint32_t policy_code)
 Constructs a Policy wrapper from an encoded policy value. More...
 
constexpr Policy (bool public_sharing, bool public_voting, bool catch_pirates)
 Constructs a Policy wrapper from booleans for each policy type. More...
 
 Policy (const std::string &p)
 Constructs a Policy wrapper from a comma-separated list of policies. More...
 
constexpr bool publicSharing () const
 Returns true if this policy has basic public sharing enabled.
 
constexpr bool publicVoting () const
 Returns true if this policy has public sharing with voting enabled.
 
constexpr bool catchPirates () const
 Returns true if this policy has catching pirates enabled.
 
constexpr bool unknown () const
 Returns true if the policy has some unknown policy enabled (that is, some policy code that isn't constructible from the known policies).
 
constexpr bool all () const
 Returns true if all (known) policies are enabled. More...
 
constexpr operator bool () const
 Implicit conversion to bool: returns true if any known policy is enabled and there are no unknown policy bits set in the policy code.
 
constexpr operator uint32_t () const
 Implicit conversion to uint32_t policy code. More...
 
constexpr bool operator== (const Policy &other) const
 Returns true if the two policy objects represent the same policy choice. More...
 
constexpr bool operator!= (const Policy &other) const
 Negation of ==. More...
 
Policyoperator+= (const Policy &add)
 Modifies this Policy value by enabling any policies enabled in the given Policy. More...
 
Policyoperator-= (const Policy &remove)
 Modifies this Policy value by disabling any policies that are enabled in the given Policy. More...
 
constexpr Policy operator+ (const Policy &plus) const
 Returns a new Policy object with all policies enabled that are enabled in either argument.
 

Static Public Member Functions

static constexpr Policy PublicSharing ()
 Returns a constexpr Policy value for public sharing.
 
static constexpr Policy PublicVoting ()
 Returns a constexpr Policy value for public voting.
 
static constexpr Policy CatchPirates ()
 Returns a constexpr Policy value for catch pirates.
 
static constexpr Policy All ()
 Returns a constexpr Policy value with all (known) policies enabled.
 

Friends

class eris::serialize::serializer< Policy >
 
class eris::serialize::serializer< const Policy >
 

Detailed Description

Class for interpreting and/or constructing encoded policy values.

The encoded value is stored in the Creativity settings.policy parameter. That value should be generated and interpreted only through the abstractions provided by this class.

Constructor & Destructor Documentation

§ Policy() [1/3]

constexpr creativity::Policy::Policy ( uint32_t  policy_code)
inline

Constructs a Policy wrapper from an encoded policy value.

This constructor intentionally allows implicit conversion from a uint32_t previously obtained from a Policy object.

§ Policy() [2/3]

constexpr creativity::Policy::Policy ( bool  public_sharing,
bool  public_voting,
bool  catch_pirates 
)
inline

Constructs a Policy wrapper from booleans for each policy type.

Parameters
public_sharingif true, constructs a policy with public sharing enabled
public_votingif true, constructs a policy with public sharing with voting enabled
catch_piratesif true, constructs a policy with catching pirates enabled

§ Policy() [3/3]

creativity::Policy::Policy ( const std::string &  p)
explicit

Constructs a Policy wrapper from a comma-separated list of policies.

The following values are permitted:

  • "public-sharing" (or "public")
  • "public-voting" (or "voting" or "vote")
  • "catch-pirates" (or "catch")
  • "none" (or "") – this value is silently ignored

Any other value will result in a runtime_error exception being thrown.

Member Function Documentation

§ all()

constexpr bool creativity::Policy::all ( ) const
inline

Returns true if all (known) policies are enabled.

§ operator uint32_t()

constexpr creativity::Policy::operator uint32_t ( ) const
inline

Implicit conversion to uint32_t policy code.

§ operator!=()

constexpr bool creativity::Policy::operator!= ( const Policy other) const
inline

Negation of ==.

§ operator+=()

Policy& creativity::Policy::operator+= ( const Policy add)

Modifies this Policy value by enabling any policies enabled in the given Policy.

Currently enabled policies remain enabled, even if not enabled in the target.

Unknown policies in the target are ignored.

§ operator-=()

Policy& creativity::Policy::operator-= ( const Policy remove)

Modifies this Policy value by disabling any policies that are enabled in the given Policy.

Unknown policies are ignored.

§ operator==()

constexpr bool creativity::Policy::operator== ( const Policy other) const
inline

Returns true if the two policy objects represent the same policy choice.


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