Skip to content

sam::Policy

Module: Policy-related Modules

Implementation of the Policy class. More...

#include <Policy.h>

Public Functions

Name
Policy() =default
Policy(const std::string & p_def, sol::state & lua)
Creates a policy, and registers it to the available lua state.
template <typename ForwardIt >
std::optional< std::pair< ForwardIt, ForwardIt > >
operator()(ForwardIt begin, ForwardIt end)
Filters the range based on the given policy.
bool operator()(const Submission & sub) const
Returns the result of applying the policy on a submission.
bool operator()(const DependentVariable & dv) const
Returns the result of applying the policy on a dependent variable.
bool operator()(DependentVariable & dv) const

Public Attributes

Name
PolicyType type
PolicyDefinition def
sol::function func

Detailed Description

struct sam::Policy;

Implementation of the Policy class.

A policy is a logical rule that it's being applied on an experiment, submission, or a set of submissions. A policy can be used to perform two type of operation on either of the mentioned data structures, selection or decision.

  • To check whether a submission, a dependent variable satisfies a given Policy, you must use the appropriate call operator in the form of bool operator().
  • To filter a list of submissions or dependent variables of the experiment based on the given Policy, you must use the iterator-based operator.

Public Functions Documentation

function Policy

Policy() =default

function Policy

Policy(
    const std::string & p_def,
    sol::state & lua
)

Creates a policy, and registers it to the available lua state.

Parameters:

  • p_def The definition
  • lua The lua state

Attention: Since everything is happening via text processing, Policy is quite sensitive to the function definition and it rejects anythings with slightest of mistake in its definition.

This mostly performs some string search, and decided what type of function has been given as the input. Then, it uses a lua function template to construct the appropriate function definition. Finally, it registers the function to the given lua state.

function operator()

template <typename ForwardIt >
std::optional< std::pair< ForwardIt, ForwardIt > > operator()(
    ForwardIt begin,
    ForwardIt end
)

Filters the range based on the given policy.

Parameters:

  • begin The begin
  • end The end

Template Parameters:

  • ForwardIt This usually accepts Submission's ForwardIt

Return: Return a tuple containing three variables.

Attention: You can only use this on DependentVariable and Submission objects, since these are the two classes that are registered as lua usertype.

This applies the current policy on a range of values, and returns a subset of the range if it finds anything. If not, it will return an empty optional.

Shuffling the array and setting the end pointer to the first time, this basically mimic the process of selecting a random element from the list.

function operator()

inline bool operator()(
    const Submission & sub
) const

Returns the result of applying the policy on a submission.

function operator()

inline bool operator()(
    const DependentVariable & dv
) const

Returns the result of applying the policy on a dependent variable.

function operator()

inline bool operator()(
    DependentVariable & dv
) const

Public Attributes Documentation

variable type

PolicyType type;

variable def

PolicyDefinition def;

variable func

sol::function func;

Updated on 29 June 2021 at 16:13:48 CEST


Last update: 2021-09-18