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 |
|
Built-in constants |
Homogeneous list |
|
|
Key-value mapping |
|
|
Nullable value |
|
|
Concurrent list |
|
|
Fixed-size tuple |
|
|
Base Class¶
The primitive types, and the utilities that act on any type. |
|
Describes the name of a type: its namespace and its identifier. |
Primitive Types¶
The void type. |
|
The bool type. |
|
The uint8 type. |
|
The uint16 type. |
|
The uint32 type. |
|
The uint64 type. |
|
The int8 type. |
|
The int16 type. |
|
The int32 type. |
|
The int64 type. |
|
The float type. |
|
The double type. |
|
The string type. |
|
The blob type. |
|
The blob_id type. |
|
The commit_id type. |
|
The uuid type. |
Container Types¶
The vector<element_type> type. |
|
The set<element_type> type. |
|
The map<key_type, element_type> type. |
|
The xarray<element_type> type. |
|
The optional<element_type> type. |
Algebraic Types¶
The tuple<T0, ...> type. |
|
The vec<numeric_type, size> type. |
|
The mat<numeric_type, columns, rows> type. |
|
The variant<T0, ...> type. |
|
The any type. |
User-Defined Types¶
A struct type. |
|
Describes the fields a struct will be created with. |
|
One field of a struct type, as TypeStructure.fields(), query() and check() answer it. |
|
An enum type. |
|
One case of an enum type, as TypeEnumeration.cases(), query() and check() answer it. |
|
Describes the cases an enum will be created with. |
Concept Types¶
A concept type. |
|
A club type. |
|
The key<element_type> type. |
|
The any_concept type. |