LibraryLink Utilities  3.0.1
Modern C++ wrapper over LibraryLink and WSTP
LLU::WS Namespace Reference

Contains definitions related to WSTP functionality in LLU. More...

Detailed Description

Contains definitions related to WSTP functionality in LLU.

Namespaces

 EncodingConfig
 Contains configuration parameters that paclet developers may modify.
 

Classes

struct  Association
 Special type of a Function which corresponds to the Association expression when exchanged with the Kernel via WSStream. More...
 
struct  BeginExpr
 
struct  CharTypeStruct
 
struct  DropExpr
 
struct  EndExpr
 
struct  Function
 Structure representing any function in Wolfram Language, i.e. a head plus number of arguments. More...
 
struct  GetAs
 Utility structure used to enforce receiving given value via WSStream with encoding E. More...
 
struct  List
 Special type of a Function which corresponds to the List expression when exchanged with the Kernel via WSStream. More...
 
struct  Missing
 Special type of a Function which corresponds to the Missing expression when exchanged with the Kernel via WSStream. More...
 
struct  PutAs
 Utility structure used to enforce sending given value with encoding E via WSStream. More...
 
struct  StringTypeStruct
 
struct  Symbol
 Structure representing any symbol in Wolfram Language. More...
 

Type aliases

template<Encoding E>
using CharType = typename CharTypeStruct< E >::type
 Specializations of CharTypeStruct, encoding E has assigned type T iff WSPutEString takes const T* as second parameter. More...
 
template<Encoding E>
using StringType = typename StringTypeStruct< E >::type
 
template<typename T >
using ListData = std::unique_ptr< T[], ReleaseList< T > >
 ListData with of type T is a unique_ptr to an array of Ts with custom destructor. More...
 
template<typename T >
using ArrayData = std::unique_ptr< T[], ReleaseArray< T > >
 ArrayData with of type T is a unique_ptr to an array of Ts with custom destructor. More...
 
template<Encoding E>
using StringData = std::unique_ptr< const CharType< E >[], ReleaseString< E > >
 StringData with Encoding E is a unique_ptr to an array of E-encoded characters It allows you to take ownership of raw string data from WSTP without making extra copies. More...
 
template<typename T >
using GetStringFuncT = std::function< int(WSLINK, const T **, int *, int *)>
 GetStringFuncT is a type of WSTP function that reads string from a link, e.g. WSGetByteString. More...
 
template<typename T >
using PutStringFuncT = std::function< int(WSLINK, const T *, int)>
 PutStringFuncT is a type of WSTP function that sends string data to a link, e.g. WSPutByteString. More...
 
template<typename T >
using ReleaseStringFuncT = std::function< void(WSLINK, const T *, int)>
 ReleaseStringFuncT is a type of WSTP function to release string data allocated by WSTP, e.g. WSReleaseByteString. More...
 

Enumerations

enum  Encoding : std::uint8_t {
  Encoding::Undefined,
  Encoding::Native,
  Encoding::Byte,
  Encoding::UTF8,
  Encoding::UTF16,
  Encoding::UCS2,
  Encoding::UTF32
}
 
enum  Direction : bool {
  Get,
  Put
}
 Helper enum for tokens that can be sent via WSTP in both directions, e.g. WS::Null. More...
 

Functions

constexpr const char * getEncodingName (Encoding e)
 Get the name of encoding. More...
 
template<Encoding E, typename T >
PutAs< E, T > putAs (T &&obj)
 This is a helper function to facilitate constructing WS::PutAs wrapper. More...
 
template<Encoding E, typename T >
GetAs< E, T > getAs (T &obj)
 This is a helper function to facilitate constructing WS::GetAs wrapper. More...
 
template<WS::Encoding EIn, WS::Encoding EOut>
WSStream< EIn, EOut > & NewPacket (WSStream< EIn, EOut > &ms)
 NewPacket is a WSStream token which tells WSTP to skip to the end of the current packet. More...
 
template<WS::Encoding EIn, WS::Encoding EOut>
WSStream< EIn, EOut > & EndPacket (WSStream< EIn, EOut > &ms)
 EndPacket is a WSStream token which tells WSTP that the current expression is complete and is ready to be sent. More...
 
template<WS::Encoding EIn, WS::Encoding EOut>
WSStream< EIn, EOut > & Flush (WSStream< EIn, EOut > &ms)
 Flush is a WSStream token which tells WSTP to flush out any buffers containing data waiting to be sent on link. More...
 
template<WS::Encoding EIn, WS::Encoding EOut>
WSStream< EIn, EOut > & Rule (WSStream< EIn, EOut > &ms, Direction dir)
 Rule is a WSStream token corresponding to a Rule expression in the WolframLanguage. More...
 
template<WS::Encoding EIn, WS::Encoding EOut>
WSStream< EIn, EOut > & Null (WSStream< EIn, EOut > &ms, Direction dir)
 Null is a WSStream token corresponding to a Null expression in the WolframLanguage. More...
 

Variables

template<Encoding E, typename T >
constexpr bool CharacterTypesCompatible = (sizeof(T) == sizeof(CharType<E>))
 Check whether character type T is compatible with encoding E (i.e. More...
 
template<typename T >
constexpr bool supportedInWSArithmeticQ = false
 Utility trait that determines whether type T is a suitable data type for functions like WSPut*Array, WSGet*List, WSPutScalar, etc. More...
 
template<typename T >
constexpr bool ScalarSupportedTypeQ = supportedInWSArithmeticQ<remove_cv_ref<T>>
 Convenient alias for supportedInWSArithmeticQ<T> that strips T from cv-qualifiers and reference. More...
 
template<typename T >
constexpr bool supportedInWSStringQ = false
 Utility trait that determines whether type T is a suitable character type for WSPut*String and WSGet*String. More...
 
template<typename T >
constexpr bool StringTypeQ = supportedInWSStringQ<remove_cv_ref<T>>
 Convenient alias for supportedInWSStringQ<T> that strips T from cv-qualifiers and reference. More...
 

Type aliases documentation

◆ ArrayData

template<typename T >
using LLU::WS::ArrayData = typedef std::unique_ptr<T[], ReleaseArray<T> >

ArrayData with of type T is a unique_ptr to an array of Ts with custom destructor.

It allows you to take ownership of raw array data from WSTP without making extra copies. The destructor object also carries information about the array's dimensions and heads.

◆ CharType

template<Encoding E>
LLU::WS::CharType

Specializations of CharTypeStruct, encoding E has assigned type T iff WSPutEString takes const T* as second parameter.

Template Parameters
E- encoding

Utility alias for type member of CharTypeStruct

◆ GetStringFuncT

template<typename T >
using LLU::WS::GetStringFuncT = typedef std::function<int(WSLINK, const T**, int*, int*)>

GetStringFuncT is a type of WSTP function that reads string from a link, e.g. WSGetByteString.

◆ ListData

template<typename T >
using LLU::WS::ListData = typedef std::unique_ptr<T[], ReleaseList<T> >

ListData with of type T is a unique_ptr to an array of Ts with custom destructor.

It allows you to take ownership of raw list data from WSTP without making extra copies. The destructor object also carries information about the list's length.

◆ PutStringFuncT

template<typename T >
using LLU::WS::PutStringFuncT = typedef std::function<int(WSLINK, const T*, int)>

PutStringFuncT is a type of WSTP function that sends string data to a link, e.g. WSPutByteString.

◆ ReleaseStringFuncT

template<typename T >
using LLU::WS::ReleaseStringFuncT = typedef std::function<void(WSLINK, const T*, int)>

ReleaseStringFuncT is a type of WSTP function to release string data allocated by WSTP, e.g. WSReleaseByteString.

◆ StringData

template<Encoding E>
using LLU::WS::StringData = typedef std::unique_ptr<const CharType<E>[], ReleaseString<E> >

StringData with Encoding E is a unique_ptr to an array of E-encoded characters It allows you to take ownership of raw string data from WSTP without making extra copies.

◆ StringType

template<Encoding E>
LLU::WS::StringType
Template Parameters
E- encoding

Utility alias for type member of StringTypeStruct

Enumeration Type Documentation

◆ Direction

enum LLU::WS::Direction : bool
strong

Helper enum for tokens that can be sent via WSTP in both directions, e.g. WS::Null.

◆ Encoding

enum LLU::WS::Encoding : std::uint8_t
strong

List of all string encodings supported by WSTP

Enumerator
Undefined 

Undefined, can be used to denote that certain function is not supposed to deal with strings.

Native 

Use WSGetString for reading and WSPutString for writing strings.

Byte 

Use WSGetByteString for reading and WSPutByteString for writing strings.

UTF8 

Use WSGetUTF8String for reading and WSPutUTF8String for writing strings.

UTF16 

Use WSGetUTF16String for reading and WSPutUTF16String for writing strings.

UCS2 

Use WSGetUCS2String for reading and WSPutUCS2String for writing strings.

UTF32 

Use WSGetUTF32String for reading and WSPutUTF32String for writing strings.

Function Documentation

◆ EndPacket()

template<WS::Encoding EIn, WS::Encoding EOut>
WSStream<EIn, EOut>& LLU::WS::EndPacket ( WSStream< EIn, EOut > &  ms)

EndPacket is a WSStream token which tells WSTP that the current expression is complete and is ready to be sent.

See also
https://reference.wolfram.com/language/ref/c/WSEndPacket.html
Template Parameters
EIn- WSStream input encoding (will be inferred from the argument)
EOut- WSStream output encoding (will be inferred from the argument)
Parameters
ms- stream object
Returns
the stream object

◆ Flush()

template<WS::Encoding EIn, WS::Encoding EOut>
WSStream<EIn, EOut>& LLU::WS::Flush ( WSStream< EIn, EOut > &  ms)

Flush is a WSStream token which tells WSTP to flush out any buffers containing data waiting to be sent on link.

See also
https://reference.wolfram.com/language/ref/c/WSFlush.html
Template Parameters
EIn- WSStream input encoding (will be inferred from the argument)
EOut- WSStream output encoding (will be inferred from the argument)
Parameters
ms- stream object
Returns
the stream object

◆ getAs()

template<Encoding E, typename T >
GetAs<E, T> LLU::WS::getAs ( T &  obj)

This is a helper function to facilitate constructing WS::GetAs wrapper.

Parameters
obj- a reference to value of type T
Returns
a GetAs wrapper

◆ getEncodingName()

constexpr const char* LLU::WS::getEncodingName ( Encoding  e)
constexpr

Get the name of encoding.

Parameters
e- value of WS::Encoding enum
Returns
C-string containing the name of encoding e

◆ NewPacket()

template<WS::Encoding EIn, WS::Encoding EOut>
WSStream<EIn, EOut>& LLU::WS::NewPacket ( WSStream< EIn, EOut > &  ms)

NewPacket is a WSStream token which tells WSTP to skip to the end of the current packet.

See also
https://reference.wolfram.com/language/ref/c/WSNewPacket.html
Template Parameters
EIn- WSStream input encoding (will be inferred from the argument)
EOut- WSStream output encoding (will be inferred from the argument)
Parameters
ms- stream object
Returns
the stream object

◆ Null()

template<WS::Encoding EIn, WS::Encoding EOut>
WSStream<EIn, EOut>& LLU::WS::Null ( WSStream< EIn, EOut > &  ms,
Direction  dir 
)

Null is a WSStream token corresponding to a Null expression in the WolframLanguage.

Template Parameters
EIn- WSStream input encoding (will be inferred from the argument)
EOut- WSStream output encoding (will be inferred from the argument)
Parameters
ms- stream object
dir- stream direction, you don't need to specify this argument when using Null in a WSStream::operator<< or operator>>
Returns
the stream object

◆ putAs()

template<Encoding E, typename T >
PutAs<E, T> LLU::WS::putAs ( T &&  obj)

This is a helper function to facilitate constructing WS::PutAs wrapper.

Parameters
obj- forwarding reference to object of type T
Returns
a PutAs wrapper

◆ Rule()

template<WS::Encoding EIn, WS::Encoding EOut>
WSStream<EIn, EOut>& LLU::WS::Rule ( WSStream< EIn, EOut > &  ms,
Direction  dir 
)

Rule is a WSStream token corresponding to a Rule expression in the WolframLanguage.

Template Parameters
EIn- WSStream input encoding (will be inferred from the argument)
EOut- WSStream output encoding (will be inferred from the argument)
Parameters
ms- stream object
dir- stream direction, you don't need to specify this argument when using Rule in a WSStream::operator<< or operator>>
Returns
the stream object

Variable Documentation

◆ CharacterTypesCompatible

template<Encoding E, typename T >
constexpr bool LLU::WS::CharacterTypesCompatible = (sizeof(T) == sizeof(CharType<E>))
inlineconstexpr

Check whether character type T is compatible with encoding E (i.e.

if it can be more or less safely used with WSPut/Get<E>String)

Each WSTP function WSPut/Get*String works with only one specific character type (see CharType<E>). In C++, on the other hand, there is no notion of encoding so std::string (with character type being char) can be used to store strings of any encoding.

We say that character type T is compatible with encoding E as long as the size of T is the same as size of CharType<E>.

◆ ScalarSupportedTypeQ

template<typename T >
constexpr bool LLU::WS::ScalarSupportedTypeQ = supportedInWSArithmeticQ<remove_cv_ref<T>>
inlineconstexpr

Convenient alias for supportedInWSArithmeticQ<T> that strips T from cv-qualifiers and reference.

◆ StringTypeQ

template<typename T >
constexpr bool LLU::WS::StringTypeQ = supportedInWSStringQ<remove_cv_ref<T>>
inlineconstexpr

Convenient alias for supportedInWSStringQ<T> that strips T from cv-qualifiers and reference.

◆ supportedInWSArithmeticQ

template<typename T >
constexpr bool LLU::WS::supportedInWSArithmeticQ = false
inlineconstexpr

Utility trait that determines whether type T is a suitable data type for functions like WSPut*Array, WSGet*List, WSPutScalar, etc.

Template Parameters
T- any type

◆ supportedInWSStringQ

template<typename T >
constexpr bool LLU::WS::supportedInWSStringQ = false
inlineconstexpr

Utility trait that determines whether type T is a suitable character type for WSPut*String and WSGet*String.

Template Parameters
T- any type