9
9
10
10
use std:: { cell:: RefCell , pin:: Pin , rc:: Rc } ;
11
11
12
- use autocxx:: c_uint;
13
12
use cxx:: let_cxx_string;
14
13
15
14
use crate :: {
16
- clone, inner, into_id, model:: Model , pin_ptr , sbmlcxx , sbo_term , traits :: fromptr :: FromPtr ,
17
- upcast_annotation,
15
+ clone, inner, into_id, model:: Model , optional_property , pin_ptr , required_property , sbmlcxx ,
16
+ sbo_term , traits :: fromptr :: FromPtr , upcast_annotation,
18
17
} ;
19
18
20
19
/// A safe wrapper around the libSBML Compartment class.
@@ -61,145 +60,64 @@ impl<'a> Compartment<'a> {
61
60
}
62
61
}
63
62
64
- /// Gets the compartment's identifier.
65
- ///
66
- /// # Returns
67
- /// The compartment's ID as a String
68
- pub fn id ( & self ) -> String {
69
- self . inner . borrow ( ) . getId ( ) . to_str ( ) . unwrap ( ) . to_string ( )
70
- }
71
-
72
- /// Sets the compartment's identifier.
73
- ///
74
- /// # Arguments
75
- /// * `id` - The new identifier to set
76
- pub fn set_id ( & self , id : & str ) {
77
- let_cxx_string ! ( id = id) ;
78
- self . inner . borrow_mut ( ) . as_mut ( ) . setId ( & id) ;
79
- }
80
-
81
- /// Gets the compartment's name.
82
- ///
83
- /// # Returns
84
- /// The compartment's name as a String
85
- pub fn name ( & self ) -> String {
86
- self . inner . borrow ( ) . getName ( ) . to_str ( ) . unwrap ( ) . to_string ( )
87
- }
88
-
89
- /// Sets the compartment's name.
90
- ///
91
- /// # Arguments
92
- /// * `name` - The new name to set
93
- pub fn set_name ( & self , name : & str ) {
94
- let_cxx_string ! ( name = name) ;
95
- self . inner . borrow_mut ( ) . as_mut ( ) . setName ( & name) ;
96
- }
97
-
98
- /// Gets the spatial dimensions of the compartment.
99
- ///
100
- /// # Returns
101
- /// The number of spatial dimensions as a u32
102
- pub fn spatial_dimensions ( & self ) -> u32 {
103
- self . inner . borrow ( ) . getSpatialDimensions ( ) . 0
104
- }
105
-
106
- /// Sets the spatial dimensions of the compartment.
107
- ///
108
- /// # Arguments
109
- /// * `spatial_dimensions` - The number of spatial dimensions to set (typically 0-3)
110
- pub fn set_spatial_dimensions ( & self , spatial_dimensions : u32 ) {
111
- self . inner
112
- . borrow_mut ( )
113
- . as_mut ( )
114
- . setSpatialDimensions ( c_uint:: from ( spatial_dimensions) ) ;
115
- }
116
-
117
- /// Gets the unit of measurement for the compartment.
118
- ///
119
- /// # Returns
120
- /// The unit of measurement as a String (e.g., "litre", "metre^3")
121
- pub fn unit ( & self ) -> String {
122
- self . inner . borrow ( ) . getUnits ( ) . to_str ( ) . unwrap ( ) . to_string ( )
123
- }
124
-
125
- /// Sets the unit of measurement for the compartment.
126
- ///
127
- /// # Arguments
128
- /// * `unit` - The unit of measurement to set (e.g., "litre", "metre^3")
129
- pub fn set_unit ( & self , unit : & str ) {
130
- let_cxx_string ! ( unit = unit) ;
131
- self . inner . borrow_mut ( ) . as_mut ( ) . setUnits ( & unit) ;
132
- }
133
-
134
- /// Gets the size of the compartment.
135
- ///
136
- /// # Returns
137
- /// The size as a f64 in the units specified by the compartment's units attribute
138
- pub fn size ( & self ) -> f64 {
139
- self . inner . borrow ( ) . getSize ( )
140
- }
141
-
142
- /// Sets the size of the compartment.
143
- ///
144
- /// # Arguments
145
- /// * `size` - The size to set in the units specified by the compartment's units attribute
146
- pub fn set_size ( & self , size : f64 ) {
147
- self . inner . borrow_mut ( ) . as_mut ( ) . setSize ( size) ;
148
- }
149
-
150
- /// Gets the volume of the compartment.
151
- ///
152
- /// # Returns
153
- /// The volume as a f64 in the units specified by the compartment's units attribute
154
- pub fn volume ( & self ) -> f64 {
155
- self . inner . borrow ( ) . getVolume ( )
156
- }
157
-
158
- /// Sets the volume of the compartment.
159
- ///
160
- /// # Arguments
161
- /// * `volume` - The volume to set in the units specified by the compartment's units attribute
162
- pub fn set_volume ( & self , volume : f64 ) {
163
- self . inner . borrow_mut ( ) . as_mut ( ) . setVolume ( volume) ;
164
- }
165
-
166
- /// Gets whether the compartment is constant.
167
- ///
168
- /// # Returns
169
- /// true if the compartment's size is constant over time, false otherwise
170
- pub fn constant ( & self ) -> bool {
171
- self . inner . borrow ( ) . getConstant ( )
172
- }
173
-
174
- /// Sets whether the compartment is constant.
175
- ///
176
- /// # Arguments
177
- /// * `constant` - true if the compartment's size should be constant over time, false otherwise
178
- pub fn set_constant ( & self , constant : bool ) {
179
- self . inner . borrow_mut ( ) . as_mut ( ) . setConstant ( constant) ;
180
- }
181
-
182
- /// Gets the outside compartment reference.
183
- ///
184
- /// # Returns
185
- /// The ID of the containing (outside) compartment as a String
186
- pub fn outside ( & self ) -> String {
187
- self . inner
188
- . borrow ( )
189
- . getOutside ( )
190
- . to_str ( )
191
- . unwrap ( )
192
- . to_string ( )
193
- }
194
-
195
- /// Sets the outside compartment reference.
196
- ///
197
- /// # Arguments
198
- /// * `outside` - The ID of the containing (outside) compartment to set
199
- pub fn set_outside ( & self , outside : & str ) {
200
- let_cxx_string ! ( outside = outside) ;
201
- self . inner . borrow_mut ( ) . as_mut ( ) . setOutside ( & outside) ;
202
- }
63
+ // Getter and setter methods for the id property
64
+ required_property ! ( Compartment <' a>, id, String , getId, setId) ;
65
+
66
+ // Getter and setter methods for the name property
67
+ optional_property ! ( Compartment <' a>, name, String , getName, setName, isSetName) ;
68
+
69
+ // Getter and setter methods for the spatial dimensions property
70
+ optional_property ! (
71
+ Compartment <' a>,
72
+ spatial_dimensions,
73
+ u32 ,
74
+ getSpatialDimensions,
75
+ setSpatialDimensions,
76
+ isSetSpatialDimensions
77
+ ) ;
78
+
79
+ // Getter and setter methods for the unit property
80
+ optional_property ! (
81
+ Compartment <' a>,
82
+ unit,
83
+ String ,
84
+ getUnits,
85
+ setUnits,
86
+ isSetUnits
87
+ ) ;
88
+
89
+ // Getter and setter methods for the size property
90
+ optional_property ! ( Compartment <' a>, size, f64 , getSize, setSize, isSetSize) ;
91
+
92
+ // Getter and setter methods for the volume property
93
+ optional_property ! (
94
+ Compartment <' a>,
95
+ volume,
96
+ f64 ,
97
+ getVolume,
98
+ setVolume,
99
+ isSetVolume
100
+ ) ;
101
+
102
+ // Getter and setter methods for the constant property
103
+ optional_property ! (
104
+ Compartment <' a>,
105
+ constant,
106
+ bool ,
107
+ getConstant,
108
+ setConstant,
109
+ isSetConstant
110
+ ) ;
111
+
112
+ // Getter and setter methods for the outside property
113
+ optional_property ! (
114
+ Compartment <' a>,
115
+ outside,
116
+ String ,
117
+ getOutside,
118
+ setOutside,
119
+ isSetOutside
120
+ ) ;
203
121
204
122
// SBO Term Methods generated by the `sbo_term` macro
205
123
sbo_term ! ( sbmlcxx:: Compartment , sbmlcxx:: SBase ) ;
@@ -372,21 +290,21 @@ mod tests {
372
290
373
291
// Use all setters to set all properties
374
292
compartment. set_name ( "test" ) ;
375
- compartment. set_spatial_dimensions ( 3 ) ;
293
+ compartment. set_spatial_dimensions ( 3u32 ) ;
376
294
compartment. set_unit ( "test" ) ;
377
295
compartment. set_size ( 1.0 ) ;
378
296
compartment. set_volume ( 1.0 ) ;
379
297
compartment. set_outside ( "test" ) ;
380
298
compartment. set_constant ( true ) ;
381
299
382
300
assert_eq ! ( compartment. id( ) , "test" ) ;
383
- assert_eq ! ( compartment. name( ) , "test" ) ;
384
- assert_eq ! ( compartment. spatial_dimensions( ) , 3 ) ;
385
- assert_eq ! ( compartment. unit( ) , "test" ) ;
386
- assert_eq ! ( compartment. size( ) , 1.0 ) ;
387
- assert_eq ! ( compartment. volume( ) , 1.0 ) ;
388
- assert_eq ! ( compartment. outside( ) , "test" ) ;
389
- assert ! ( compartment. constant( ) ) ;
301
+ assert_eq ! ( compartment. name( ) , Some ( "test" . to_string ( ) ) ) ;
302
+ assert_eq ! ( compartment. spatial_dimensions( ) , Some ( 3 ) ) ;
303
+ assert_eq ! ( compartment. unit( ) , Some ( "test" . to_string ( ) ) ) ;
304
+ assert_eq ! ( compartment. size( ) , Some ( 1.0 ) ) ;
305
+ assert_eq ! ( compartment. volume( ) , Some ( 1.0 ) ) ;
306
+ assert_eq ! ( compartment. outside( ) , Some ( "test" . to_string ( ) ) ) ;
307
+ assert_eq ! ( compartment. constant( ) , Some ( true ) ) ;
390
308
}
391
309
392
310
#[ test]
@@ -404,13 +322,13 @@ mod tests {
404
322
. build ( ) ;
405
323
406
324
assert_eq ! ( compartment. id( ) , "test" ) ;
407
- assert_eq ! ( compartment. name( ) , "test" ) ;
408
- assert_eq ! ( compartment. spatial_dimensions( ) , 3 ) ;
409
- assert_eq ! ( compartment. unit( ) , "test" ) ;
410
- assert_eq ! ( compartment. size( ) , 1.0 ) ;
411
- assert_eq ! ( compartment. volume( ) , 1.0 ) ;
412
- assert_eq ! ( compartment. outside( ) , "test" ) ;
413
- assert ! ( compartment. constant( ) ) ;
325
+ assert_eq ! ( compartment. name( ) , Some ( "test" . to_string ( ) ) ) ;
326
+ assert_eq ! ( compartment. spatial_dimensions( ) , Some ( 3 ) ) ;
327
+ assert_eq ! ( compartment. unit( ) , Some ( "test" . to_string ( ) ) ) ;
328
+ assert_eq ! ( compartment. size( ) , Some ( 1.0 ) ) ;
329
+ assert_eq ! ( compartment. volume( ) , Some ( 1.0 ) ) ;
330
+ assert_eq ! ( compartment. outside( ) , Some ( "test" . to_string ( ) ) ) ;
331
+ assert_eq ! ( compartment. constant( ) , Some ( true ) ) ;
414
332
}
415
333
416
334
#[ test]
0 commit comments