File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -429,7 +429,7 @@ pub use individual_table::{IndividualTable, IndividualTableRow};
429
429
pub use migration_table:: { MigrationTable , MigrationTableRow } ;
430
430
pub use mutation_table:: { MutationTable , MutationTableRow } ;
431
431
pub use node_table:: { NodeTable , NodeTableRow } ;
432
- pub use population_table:: { PopulationTable , PopulationTableRow } ;
432
+ pub use population_table:: { OwnedPopulationTable , PopulationTable , PopulationTableRow } ;
433
433
pub use site_table:: { SiteTable , SiteTableRow } ;
434
434
pub use table_collection:: TableCollection ;
435
435
pub use traits:: IndividualLocation ;
Original file line number Diff line number Diff line change @@ -116,10 +116,34 @@ impl<'a> PopulationTable<'a> {
116
116
}
117
117
}
118
118
119
+ /// A standalone population table that owns its data.
120
+ ///
121
+ /// # Examples
122
+ ///
123
+ /// ```
124
+ /// use tskit::OwnedPopulationTable;
125
+ ///
126
+ /// let mut populations = OwnedPopulationTable::default();
127
+ /// ```
119
128
pub struct OwnedPopulationTable {
120
129
table : mbox:: MBox < ll_bindings:: tsk_population_table_t > ,
121
130
}
122
131
132
+ impl OwnedPopulationTable {
133
+ fn new ( ) -> Self {
134
+ let temp = unsafe {
135
+ libc:: malloc ( std:: mem:: size_of :: < ll_bindings:: tsk_population_table_t > ( ) )
136
+ as * mut ll_bindings:: tsk_population_table_t
137
+ } ;
138
+ let nonnull = match std:: ptr:: NonNull :: < ll_bindings:: tsk_population_table_t > :: new ( temp) {
139
+ Some ( x) => x,
140
+ None => panic ! ( "out of memory" ) ,
141
+ } ;
142
+ let table = unsafe { mbox:: MBox :: from_non_null_raw ( nonnull) } ;
143
+ Self { table }
144
+ }
145
+ }
146
+
123
147
impl std:: ops:: Deref for OwnedPopulationTable {
124
148
type Target = PopulationTable < ' static > ;
125
149
@@ -128,3 +152,9 @@ impl std::ops::Deref for OwnedPopulationTable {
128
152
unsafe { std:: mem:: transmute ( & self . table ) }
129
153
}
130
154
}
155
+
156
+ impl Default for OwnedPopulationTable {
157
+ fn default ( ) -> Self {
158
+ Self :: new ( )
159
+ }
160
+ }
You can’t perform that action at this time.
0 commit comments