Skip to main content

iso_10303/express/
datatype.rs

1use super::SimpleExpression;
2
3#[derive(Debug, Clone)]
4pub enum DataType {
5    Number,
6    Integer,
7    Real {
8        precision: Option<u8>,
9    },
10    Boolean,
11    Logical,
12    String {
13        width: Option<usize>,
14        fixed: bool,
15    },
16    Binary {
17        width: Option<usize>,
18        fixed: bool,
19    },
20    TypeRef {
21        name: String,
22    },
23    Array {
24        bound: Option<BoundSpec>,
25        optional: bool,
26        unique: bool,
27        base_type: Box<DataType>,
28    },
29    /// Ordered elements
30    List {
31        bound: Option<BoundSpec>,
32        unique: bool,
33        base_type: Box<DataType>,
34    },
35    /// Unordered elements
36    Bag {
37        bound: Option<BoundSpec>,
38        base_type: Box<DataType>,
39    },
40    /// Unordered and unqiue elements
41    Set {
42        bound: Option<BoundSpec>,
43        base_type: Box<DataType>,
44    },
45    /// Enumeration
46    Enum {
47        values: Vec<String>,
48    },
49    /// Union of named types
50    Select {
51        types: Vec<String>,
52    },
53    Generic {
54        type_label: Option<String>,
55    },
56    Aggregate {
57        type_label: Option<String>,
58        base_type: Box<DataType>,
59    },
60}
61
62#[derive(Debug, Clone)]
63pub struct BoundSpec {
64    pub start: SimpleExpression,
65    pub end: Option<SimpleExpression>,
66}
67
68impl DataType {
69    pub fn is_number(&self) -> bool {
70        match *self {
71            DataType::Number => true,
72            _ => false,
73        }
74    }
75    pub fn is_real(&self) -> bool {
76        match *self {
77            DataType::Real { .. } => true,
78            _ => false,
79        }
80    }
81    pub fn is_integer(&self) -> bool {
82        match *self {
83            DataType::Integer => true,
84            _ => false,
85        }
86    }
87    pub fn type_ref(&self) -> Option<&String> {
88        match self {
89            DataType::TypeRef { name } => Some(name),
90            _ => None,
91        }
92    }
93}