Type System

The type system defines all available types in Viper C++. Type is the base class with static accessors for primitive types.

When to use: Use types to define schemas, validate data, and create parameterized containers like vectors and maps.

Quick Start

>>> from dsviper import Type, TypeVector, TypeMap, TypeOptional

Primitive types are constants on Type:

>>> Type.INT64
int64
>>> Type.STRING
string

Parameterized types are their own classes, and nest:

>>> TypeVector(Type.STRING)
vector<string>
>>> TypeMap(Type.STRING, Type.INT64)
map<string, int64>
>>> TypeMap(Type.STRING, TypeVector(Type.FLOAT))
map<string, vector<float>>
>>> TypeOptional(Type.STRING)
optional<string>

Choosing the Right Type

Use Case

Type Class

Example

Primitive value

Type.STRING, Type.INT64

Built-in constants

Homogeneous list

TypeVector

TypeVector(Type.INT64)

Key-value mapping

TypeMap

TypeMap(Type.STRING, Type.INT64)

Nullable value

TypeOptional

TypeOptional(Type.STRING)

Concurrent list

TypeXArray

TypeXArray(Type.STRING)

Fixed-size tuple

TypeTuple

TypeTuple([Type.INT64, Type.STRING])

Base Class

dsviper.Type

The primitive types, and the utilities that act on any type.

dsviper.TypeName

Describes the name of a type: its namespace and its identifier.

Primitive Types

dsviper.TypeVoid

The void type.

dsviper.TypeBool

The bool type.

dsviper.TypeUInt8

The uint8 type.

dsviper.TypeUInt16

The uint16 type.

dsviper.TypeUInt32

The uint32 type.

dsviper.TypeUInt64

The uint64 type.

dsviper.TypeInt8

The int8 type.

dsviper.TypeInt16

The int16 type.

dsviper.TypeInt32

The int32 type.

dsviper.TypeInt64

The int64 type.

dsviper.TypeFloat

The float type.

dsviper.TypeDouble

The double type.

dsviper.TypeString

The string type.

dsviper.TypeBlob

The blob type.

dsviper.TypeBlobId

The blob_id type.

dsviper.TypeCommitId

The commit_id type.

dsviper.TypeUUId

The uuid type.

Container Types

dsviper.TypeVector

The vector<element_type> type.

dsviper.TypeSet

The set<element_type> type.

dsviper.TypeMap

The map<key_type, element_type> type.

dsviper.TypeXArray

The xarray<element_type> type.

dsviper.TypeOptional

The optional<element_type> type.

Algebraic Types

dsviper.TypeTuple

The tuple<T0, ...> type.

dsviper.TypeVec

The vec<numeric_type, size> type.

dsviper.TypeMat

The mat<numeric_type, columns, rows> type.

dsviper.TypeVariant

The variant<T0, ...> type.

dsviper.TypeAny

The any type.

User-Defined Types

dsviper.TypeStructure

A struct type.

dsviper.TypeStructureDescriptor

Describes the fields a struct will be created with.

dsviper.TypeStructureField

One field of a struct type, as TypeStructure.fields(), query() and check() answer it.

dsviper.TypeEnumeration

An enum type.

dsviper.TypeEnumerationCase

One case of an enum type, as TypeEnumeration.cases(), query() and check() answer it.

dsviper.TypeEnumerationDescriptor

Describes the cases an enum will be created with.

Concept Types

dsviper.TypeConcept

A concept type.

dsviper.TypeClub

A club type.

dsviper.TypeKey

The key<element_type> type.

dsviper.TypeAnyConcept

The any_concept type.