CVB++ 15.0
Loading...
Searching...
No Matches

Variant like python object. More...

#include <cvb/py_script/object.hpp>

Public Member Functions

ObjectPtr Attribute (const Cvb::String &attributeName)
 Gets an attribute of the object as object.
 
ObjectPtr Run (const Object &args)
 Runs the object as callable.
 
ObjectPtr Run ()
 Runs the object as callable.
 
size_t ElementCount () const
 Number of elements in this object.
 
void Set (size_t index, const Object &obj)
 Set an element in this object.
 
ObjectPtr Get (size_t index) const
 Get an element from this object.
 
template<class T>
As () const
 Get an type from this object.
 
void * Handle () const noexcept
 Classic API buffer handle.
 

Static Public Member Functions

template<class T>
static std::shared_ptr< ObjectCreate (const T &value)
 Creates a object form any supported type.
 
static ObjectPtr MakeVoidTuple (size_t size)
 Creates tuple with a specified size.
 
template<typename... T>
static ObjectPtr MakeTuple (T &&...args)
 Creates tuple with the given types.
 
static std::shared_ptr< ObjectMakeVoidList (size_t size)
 Creates list with a specified size.
 

Detailed Description

Variant like python object.

Like variants this type can hold any python object. Note that in python also function, methods, types and even "None" is an object. There are convenience to create Objects from CVB types and extract CVB types from Object. All primitive types can also be converted to and from an Object.

Furthermore list and tuples can be created to hold other objects. Be aware that all arguments to e.g. functions or methods must delivered in a tuple.

Member Function Documentation

◆ As()

template<class T>
T As ( ) const
inline

Get an type from this object.

Returns
The requested type if contained within the object.
Exceptions
Anyexception derived from std::exception including CvbException.

See module description on details how types are received.

◆ Attribute()

ObjectPtr Attribute ( const Cvb::String & attributeName)
inline

Gets an attribute of the object as object.

Parameters
[in]attributeNameName of the attribute.
Returns
A pointer to an object.
Exceptions
Anyexception derived from std::exception including CvbException.

Attributes are meant in the python sense, e.g. type objects, methods, callables, globals etc.

◆ Create()

template<class T>
static std::shared_ptr< Object > Create ( const T & value)
inlinestatic

Creates a object form any supported type.

Parameters
[in]valueThe type to put into the object.
Returns
A pointer to an object.
Exceptions
Anyexception derived from std::exception including CvbException.

See module description on details how types are created.

◆ ElementCount()

size_t ElementCount ( ) const
inline

Number of elements in this object.

Returns
The number of elements.
Exceptions
Anyexception derived from std::exception including CvbException.

Only valid for list or tuple, fails otherwise.

◆ Get()

ObjectPtr Get ( size_t index) const
inline

Get an element from this object.

Parameters
[in]indexPosition to access.
Returns
A pointer to an object.
Exceptions
Anyexception derived from std::exception including CvbException.

Only valid for list or tuple, fails otherwise.

◆ Handle()

void * Handle ( ) const
inlinenoexcept

Classic API buffer handle.

Returns
Classic API handle.

It is normally not necessary to work with this handle.

◆ MakeTuple()

template<typename... T>
static ObjectPtr MakeTuple ( T &&... args)
inlinestatic

Creates tuple with the given types.

Parameters
[in]argsVariadic list of types.
Returns
A pointer to an object.
Exceptions
Anyexception derived from std::exception including CvbException.

The tuple will be with the types provided. All types must be supported. See Set, Get and ElementCount for handling the items in the tuple.

◆ MakeVoidList()

ObjectPtr MakeVoidList ( size_t size)
inlinestatic

Creates list with a specified size.

Parameters
[in]sizeThe size of the list.
Returns
A pointer to an object.
Exceptions
Anyexception derived from std::exception including CvbException.

The list will be filled with "None". See Set, Get and ElementCount for handling the items in the list.

◆ MakeVoidTuple()

ObjectPtr MakeVoidTuple ( size_t size)
inlinestatic

Creates tuple with a specified size.

Parameters
[in]sizeThe size of the tuple.
Returns
A pointer to an object.
Exceptions
Anyexception derived from std::exception including CvbException.

The tuple will be filled with "None". See Set, Get and ElementCount for handling the items in the tuple.

◆ Run() [1/2]

ObjectPtr Run ( )
inline

Runs the object as callable.

Returns
The result of the call as pointer to object (may be "None").
Exceptions
Anyexception derived from std::exception including CvbException.

◆ Run() [2/2]

ObjectPtr Run ( const Object & args)
inline

Runs the object as callable.

Parameters
[in]argsArguments for the call, must be a tuple.
Returns
The result of the call as pointer to object (may be "None").
Exceptions
Anyexception derived from std::exception including CvbException.

◆ Set()

void Set ( size_t index,
const Object & obj )
inline

Set an element in this object.

Parameters
[in]indexPosition to access.
[in]objObject to set at the given index.
Exceptions
Anyexception derived from std::exception including CvbException.

Only valid for list or tuple, fails otherwise.