ROSE 0.11.145.192
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
Sawyer::Document::Markup::Function Class Referenceabstract

Description

Base class for markup functions.

Definition at line 71 of file DocumentMarkup.h.

#include <Sawyer/DocumentMarkup.h>

Inheritance diagram for Sawyer::Document::Markup::Function:
Inheritance graph
[legend]
Collaboration diagram for Sawyer::Document::Markup::Function:
Collaboration graph
[legend]

Public Types

typedef SharedPointer< FunctionPtr
 Reference-counting pointer to markup function.
 

Public Member Functions

const std::string & name () const
 Function name.
 
bool isMacro () const
 Whether declaration is for a macro.
 
Ptr arg (const std::string &name)
 Declare a required argument.
 
Ptr arg (const std::string &name, const std::string &dflt)
 Declare an optional argument.
 
Ptr ellipsis (size_t n=(size_t)(-1))
 Declare additional arguments.
 
size_t nRequiredArgs () const
 Number of required arguments.
 
size_t nOptionalArgs () const
 Number of optional arguments.
 
size_t nAdditionalArgs () const
 Max number of additional arguments.
 
size_t maxArgs () const
 Max number of actual arguments possible.
 
void validateArgs (std::vector< std::string > &actuals, TokenStream &) const
 Check and adjust actual arguments.
 
virtual std::string eval (const Grammar &, const std::vector< std::string > &actuals)=0
 How to evaluate this function or macro.
 
- Public Member Functions inherited from Sawyer::SharedObject
 SharedObject ()
 Default constructor.
 
 SharedObject (const SharedObject &)
 Copy constructor.
 
virtual ~SharedObject ()
 Virtual destructor.
 
SharedObjectoperator= (const SharedObject &)
 Assignment.
 
- Public Member Functions inherited from Sawyer::SharedFromThis< Function >
SharedPointer< FunctionsharedFromThis ()
 Create a shared pointer from this.
 
SharedPointer< const FunctionsharedFromThis () const
 Create a shared pointer from this.
 

Protected Member Functions

 Function (const std::string &name, bool evalArgs=true)
 

Member Typedef Documentation

◆ Ptr

Reference-counting pointer to markup function.

Definition at line 74 of file DocumentMarkup.h.

Constructor & Destructor Documentation

◆ Function()

Sawyer::Document::Markup::Function::Function ( const std::string &  name,
bool  evalArgs = true 
)
inlineexplicitprotected

Definition at line 95 of file DocumentMarkup.h.

Member Function Documentation

◆ name()

const std::string & Sawyer::Document::Markup::Function::name ( ) const

Function name.

The name does not include the "@" character.

◆ isMacro()

bool Sawyer::Document::Markup::Function::isMacro ( ) const

Whether declaration is for a macro.

A macro differs from a function in only one regard: its arguments are not evaluated before invoking the macro.

◆ arg() [1/2]

Ptr Sawyer::Document::Markup::Function::arg ( const std::string &  name)

Declare a required argument.

Required arguments must come before optional arguments.

◆ arg() [2/2]

Ptr Sawyer::Document::Markup::Function::arg ( const std::string &  name,
const std::string &  dflt 
)

Declare an optional argument.

Optional arguments have a default value that will be passed as the actual argument if that actual argument isn't present at the call site. Optional arguments must come after all required arguments. For example, if a function declares one required argument and one optional argument with the default value "xxx", then if the function is called as "@foo{aaa}{bbb}" then "bbb" is passed as the actual argument, and if called as "@foo{aaa}" with no second argument then "xxx" is passed as the actual argument.

◆ ellipsis()

Ptr Sawyer::Document::Markup::Function::ellipsis ( size_t  n = (size_t)(-1))

Declare additional arguments.

A function can take up to n additional arguments. If these arguments are present at the call site then they're passed to the function, otherwise the function's actual argument list is shorter.

◆ nOptionalArgs()

size_t Sawyer::Document::Markup::Function::nOptionalArgs ( ) const

Number of optional arguments.

If an optional argument is not present at the call site, then an actual argument is created with the declared default value and passed to the function. Optional arguments are different than "additioanl" arguments.

◆ nAdditionalArgs()

size_t Sawyer::Document::Markup::Function::nAdditionalArgs ( ) const

Max number of additional arguments.

This is the maximum number of additional arguments which, if present at the call site, are passed to the function and which if not present are not passed. This is different than optional arguments.

◆ validateArgs()

void Sawyer::Document::Markup::Function::validateArgs ( std::vector< std::string > &  actuals,
TokenStream  
) const

Check and adjust actual arguments.

Checks that the actual argument list has enough values to satisfy the functions required arguments, then adds any default values necessary to pad out the optional arguments. Throws an exception if there is not the right number of arguments. The token stream is only for error location information.

◆ eval()

virtual std::string Sawyer::Document::Markup::Function::eval ( const Grammar ,
const std::vector< std::string > &  actuals 
)
pure virtual

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