1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
//! # Debug Clist
//! This are the Debug Bindings from this Modulee for the CList.
//! You should not this for any generally action, only for experts.
//!
//! Note
//! ----
//! This Module includes the CList full from dexalt-lib-sys.
//!
//! <details>
//! <summary>Includes</summary>
//! <ol>
//! <li><pre><code>pub struct CList</code></pre></li>
//! <li><pre><code>pub fn CList_init</code></pre></li>
//! <li><pre><code>pub fn CList_free</code></pre></li>
//! <li><pre><code>pub fn CList_append</code></pre></li>
//! <li><pre><code>pub fn CList_extend</code></pre></li>
//! <li><pre><code>pub fn CList_push</code></pre></li>
//! <li><pre><code>pub fn CList_remove</code></pre></li>
//! <li><pre><code>pub fn CList_pop</code></pre></li>
//! <li><pre><code>pub fn CList_to_array</code></pre></li>
//! <li><pre><code>pub fn CList_to_array_new</code></pre></li>
//! <li><pre><code>pub fn CList_size</code></pre></li>
//! <li><pre><code>pub fn CList_len</code></pre></li>
//! <li><pre><code>pub fn CList_lock</code></pre></li>
//! <li><pre><code>pub fn CList_unlock</code></pre></li>
//! <li><pre><code>pub fn CList_is_locked</code></pre></li>
//! </ol>
//! </details>
//!
//! **Attention**
//! This Modulee is only for experts.
//! The Includes summary show you only the generally names
//!
//! ## use
//!
//! ```rust
//! use dexalt_lib::clist::raw::include::*;
//! ```
pub mod bindings;
pub mod include {
pub use crate::clist::raw::bindings::*;
}
#[allow(unused_imports)]
use std::ffi;
#[allow(unused_imports)]
use std::os::raw;
#[allow(unused_imports)]
use std::ptr;
/// The Data enum.
///
/// # Example
///
/// ```rust
/// let data = Data::int(10);
/// ```
pub enum Data {
Int(i32),
UInt(u32),
Float(f32),
Double(f64),
CString(ffi::CString),
}
/// The DebugCList struct.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// ```
pub struct DebugCList {
inner: include::RawCList,
}
impl DebugCList {
/// Create a new CList with the given size.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// ```
pub fn new(size: usize) -> Self {
let size_int = size.try_into().unwrap();
let inner_n = include::RawCList::new(size_int);
DebugCList { inner: inner_n }
}
/// Clear the CList.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.clear();
/// ```
pub fn clear(&mut self) {
self.inner.free();
}
/// Append the CList with the given data.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.append(ffi::CString::new("Hello").unwrap());
/// ```
pub fn append(&mut self, data: ffi::CString) {
let data_ptr = data.as_ptr();
self.inner.append(data_ptr as *mut raw::c_void);
}
/// Extend the CList with the given data.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.extend(&mut list);
/// ```
pub fn extend(&mut self, list: &mut include::RawCList) {
let mut clist_origin = include::include::CList {
data: list.get_data(),
size: list.size(),
len: list.len(),
locked: list.is_locked(),
next: list.get_next(),
};
self.inner.extend(&mut clist_origin);
}
/// Push the CList with the given data.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.push(Data::Int(10));
/// ```
pub fn push(&mut self, data: Data) {
match data {
Data::Int(val) => self.inner.push(&val as *const _ as *mut raw::c_void),
Data::UInt(val) => self.inner.push(&val as *const _ as *mut raw::c_void),
Data::Float(val) => self.inner.push(&val as *const _ as *mut raw::c_void),
Data::Double(val) => self.inner.push(&val as *const _ as *mut raw::c_void),
Data::CString(val) => self.inner.push(val.as_ptr() as *mut raw::c_void),
}
}
/// Remove the CList with the given data.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.remove(ffi::CString::new("Hello").unwrap());
/// ```
pub fn remove(&mut self, data: ffi::CString) {
let data_ptr = data.as_ptr();
self.inner.remove(data_ptr as *mut raw::c_void);
}
/// Pop the CList with the given index.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.pop(0);
/// ```
pub fn pop(&mut self, index: usize) {
let index_int: raw::c_int = index.try_into().unwrap();
self.inner.pop(index_int);
}
/// Convert the CList to an array.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// let mut array = Vec::new();
/// list.to_array(&mut array);
/// ```
pub fn to_array(&mut self, array: &mut Vec<ffi::CString>) {
let mut raw_array: Vec<*mut raw::c_void> = array.iter_mut()
.map(|cstr| cstr.as_ptr() as *mut raw::c_void)
.collect();
let array_ptr: *mut *mut raw::c_void = raw_array.as_mut_ptr();
self.inner.to_array(array_ptr);
// Update the original array with new values if needed
}
/// Convert the CList to an array.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// let array = list.to_array_new();
/// ```
pub fn to_array_new(&mut self) -> Vec<ffi::CString> {
let mut array: Vec<ffi::CString> = Vec::new();
self.to_array(&mut array);
array
}
/// Get the size of the CList.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// let size = list.size();
/// ```
pub fn size(&mut self) -> usize {
let size_int = self.inner.size();
size_int.try_into().unwrap()
}
/// Get the length of the CList.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// let len = list.len();
/// ```
pub fn len(&mut self) -> usize {
let len_int = self.inner.len();
len_int.try_into().unwrap()
}
/// Lock the CList.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.lock();
/// ```
pub fn lock(&mut self) {
self.inner.lock();
}
/// Unlock the CList.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// list.unlock();
/// ```
pub fn unlock(&mut self) {
self.inner.unlock();
}
/// Check if the CList is locked.
///
/// # Example
///
/// ```rust
/// let mut list = DebugCList::new(10);
/// let is_locked = list.is_locked();
/// ```
pub fn is_locked(&mut self) -> bool {
self.inner.is_locked()
}
}