From b60f3ad4a372a2c9f78abdb0462e97e1a1b7771f Mon Sep 17 00:00:00 2001 From: Robert Goss Date: Fri, 29 Sep 2023 23:59:18 +0100 Subject: [PATCH] Implement the example prime library with rust --- .../Implementations/Rust/Cargo.toml | 16 + .../Interfaces/libprimes_interface_handle.rs | 93 ++++++ .../Interfaces/libprimes_interface_wrapper.rs | 298 ++++++++++++++++++ .../Rust/Interfaces/libprimes_interfaces.rs | 261 +++++++++++++++ .../Implementations/Rust/Stub/libprimes.rs | 92 ++++++ .../Rust/Stub/libprimes_base.rs | 66 ++++ .../Rust/Stub/libprimes_calculator.rs | 104 ++++++ .../libprimes_factorization_calculator.rs | 115 +++++++ .../Rust/Stub/libprimes_sieve_calculator.rs | 115 +++++++ .../Implementations/Rust/lib.rs | 44 +++ 10 files changed, 1204 insertions(+) create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Cargo.toml create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_handle.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_wrapper.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interfaces.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_base.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_calculator.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_factorization_calculator.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_sieve_calculator.rs create mode 100644 Examples/Primes/LibPrimes_component/Implementations/Rust/lib.rs diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Cargo.toml b/Examples/Primes/LibPrimes_component/Implementations/Rust/Cargo.toml new file mode 100644 index 00000000..914acd5e --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Cargo.toml @@ -0,0 +1,16 @@ +# Copyright (C) 2019 PrimeDevelopers +# +# All rights reserved. +# +# This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. +# +# Abstract: This is an autogenerated Cargo file for the development of Prime Numbers Library. +# +# Interface version: 1.2.0 + +[package] + name = "primes" + version = "0.1.0" +[lib] + path = "lib.rs" + crate-type = ["cdylib"] diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_handle.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_handle.rs new file mode 100644 index 00000000..836fe590 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_handle.rs @@ -0,0 +1,93 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +// Handle passed through interface define the casting maps needed to extract + +use libprimes_interfaces::*; + +#[allow(dead_code)] +impl HandleImpl { + pub fn as_base(&self) -> Option<&dyn Base> { + match self { + HandleImpl::TCalculator(_, ptr) => Some(ptr.as_ref()), + HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_ref()), + HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_ref()), + _ => None + } + } + pub fn as_mut_base(&mut self) -> Option<&mut dyn Base> { + match self { + HandleImpl::TCalculator(_, ptr) => Some(ptr.as_mut()), + HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_mut()), + HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_mut()), + _ => None + } + } + + pub fn as_calculator(&self) -> Option<&dyn Calculator> { + match self { + HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_ref()), + HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_ref()), + _ => None + } + } + pub fn as_mut_calculator(&mut self) -> Option<&mut dyn Calculator> { + match self { + HandleImpl::TFactorizationCalculator(_, ptr) => Some(ptr.as_mut()), + HandleImpl::TSieveCalculator(_, ptr) => Some(ptr.as_mut()), + _ => None + } + } + + pub fn as_factorization_calculator(&self) -> Option<&dyn FactorizationCalculator> { + match self { + _ => None + } + } + pub fn as_mut_factorization_calculator(&mut self) -> Option<&mut dyn FactorizationCalculator> { + match self { + _ => None + } + } + + pub fn as_sieve_calculator(&self) -> Option<&dyn SieveCalculator> { + match self { + _ => None + } + } + pub fn as_mut_sieve_calculator(&mut self) -> Option<&mut dyn SieveCalculator> { + match self { + _ => None + } + } + + pub fn inc_ref_count(&mut self) { + match self { + HandleImpl::TBase(count, _) => *count += 1, + HandleImpl::TCalculator(count, _) => *count += 1, + HandleImpl::TFactorizationCalculator(count, _) => *count += 1, + HandleImpl::TSieveCalculator(count, _) => *count += 1, + } + } + pub fn dec_ref_count(&mut self) -> bool { + match self { + HandleImpl::TBase(count, _) => {*count -= 1; *count == 0}, + HandleImpl::TCalculator(count, _) => {*count -= 1; *count == 0}, + HandleImpl::TFactorizationCalculator(count, _) => {*count -= 1; *count == 0}, + HandleImpl::TSieveCalculator(count, _) => {*count -= 1; *count == 0}, + } + } +} diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_wrapper.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_wrapper.rs new file mode 100644 index 00000000..880f6e82 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interface_wrapper.rs @@ -0,0 +1,298 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +// Calls from the C-Interface to the Rust traits via the CWrapper +// These are the symbols exposed in the shared object interface + +use libprimes_interfaces::*; +use libprimes::CWrapper; +use std::ffi::{c_char, CStr}; + +#[no_mangle] +pub fn libprimes_getversion(major : *mut u32, minor : *mut u32, micro : *mut u32) -> i32 { + // Convert parameter major to be used as an argument + if major.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _major = unsafe {&mut *major}; + + // Convert parameter minor to be used as an argument + if minor.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _minor = unsafe {&mut *minor}; + + // Convert parameter micro to be used as an argument + if micro.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _micro = unsafe {&mut *micro}; + + // Call into wrapper for global + CWrapper::get_version(_major, _minor, _micro); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_getlasterror(instance : BaseHandle, error_message_buffer_size : usize, error_message_needed_chars : *mut usize, error_message_buffer : *mut u8, has_error : *mut u8) -> i32 { + // Convert parameter instance to be used as an argument + if instance.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_instance = unsafe {&*instance}; + let _optional_instance = _handle_instance.as_base(); + if _optional_instance.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _instance = _optional_instance.unwrap(); + + // Convert parameter error_message to be used as an argument + let mut _string_error_message = String::new(); + let _error_message = &mut _string_error_message; + + // Call into wrapper for global + let _return_has_error = CWrapper::get_last_error(_instance, _error_message); + + // Pass the string error_message via output parameters + let _slice_error_message = _string_error_message.as_bytes(); + if error_message_buffer_size > _slice_error_message.len() { return LIBPRIMES_ERROR_BUFFERTOOSMALL; } + if error_message_buffer.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + if error_message_needed_chars.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let mut _buffer_slice_error_message = unsafe { std::slice::from_raw_parts_mut(error_message_buffer, _slice_error_message.len()) }; + _buffer_slice_error_message.clone_from_slice(_slice_error_message); + let mut _error_message_needed_chars = unsafe { &mut *error_message_needed_chars }; + *_error_message_needed_chars = _slice_error_message.len(); + + // Pass the return value has_error via output parameters + if has_error.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let mut _ref_has_error = unsafe{&mut *has_error}; + *_ref_has_error = _return_has_error as u8; + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +fn libprimes_acquireinstance(instance : BaseHandle) -> i32 { + if instance.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_instance = unsafe {&mut *instance}; + _handle_instance.inc_ref_count(); + LIBPRIMES_SUCCESS +} +#[no_mangle] +fn libprimes_releaseinstance(instance : BaseHandle) -> i32 { + if instance.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_instance = unsafe {&mut *instance}; + let free = _handle_instance.dec_ref_count(); + if free { + unsafe { let _ = Box::from_raw(instance); } + } + LIBPRIMES_SUCCESS +} +#[no_mangle] +pub fn libprimes_createfactorizationcalculator(instance : *mut FactorizationCalculatorHandle) -> i32 { + // Call into wrapper for global + let _return_instance = CWrapper::create_factorization_calculator(); + + // Pass the return value instance via output parameters + if instance.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_instance = Box::new(HandleImpl::TFactorizationCalculator(1, _return_instance)); + let mut _ref_instance = unsafe{&mut *instance}; + *_ref_instance = Box::into_raw(_handle_instance); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_createsievecalculator(instance : *mut SieveCalculatorHandle) -> i32 { + // Call into wrapper for global + let _return_instance = CWrapper::create_sieve_calculator(); + + // Pass the return value instance via output parameters + if instance.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_instance = Box::new(HandleImpl::TSieveCalculator(1, _return_instance)); + let mut _ref_instance = unsafe{&mut *instance}; + *_ref_instance = Box::into_raw(_handle_instance); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_setjournal(file_name : *const c_char) -> i32 { + // Convert parameter file_name to be used as an argument + if file_name.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _str_file_name = unsafe{ CStr::from_ptr(file_name) }; + let _optional_file_name = _str_file_name.to_str(); + if _optional_file_name.is_err() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _file_name = _optional_file_name.unwrap(); + + // Call into wrapper for global + CWrapper::set_journal(_file_name); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_base_classtypeid(self_ : BaseHandle, class_type_id : *mut u64) -> i32 { + // Convert parameter self_ to be used as an argument + if self_.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_self_ = unsafe {&mut *self_}; + let _optional_self_ = _handle_self_.as_mut_base(); + if _optional_self_.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _self_ = _optional_self_.unwrap(); + + // Call into trait class + let _return_class_type_id = _self_.class_type_id(); + + // Pass the return value class_type_id via output parameters + if class_type_id.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let mut _ref_class_type_id = unsafe{&mut *class_type_id}; + *_ref_class_type_id = _return_class_type_id; + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_calculator_getvalue(self_ : CalculatorHandle, value : *mut u64) -> i32 { + // Convert parameter self_ to be used as an argument + if self_.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_self_ = unsafe {&mut *self_}; + let _optional_self_ = _handle_self_.as_mut_calculator(); + if _optional_self_.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _self_ = _optional_self_.unwrap(); + + // Call into trait class + let _return_value = _self_.get_value(); + + // Pass the return value value via output parameters + if value.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let mut _ref_value = unsafe{&mut *value}; + *_ref_value = _return_value; + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_calculator_setvalue(self_ : CalculatorHandle, value : u64) -> i32 { + // Convert parameter self_ to be used as an argument + if self_.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_self_ = unsafe {&mut *self_}; + let _optional_self_ = _handle_self_.as_mut_calculator(); + if _optional_self_.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _self_ = _optional_self_.unwrap(); + + // Convert parameter value to be used as an argument + let _value = value; + + // Call into trait class + _self_.set_value(_value); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_calculator_calculate(self_ : CalculatorHandle) -> i32 { + // Convert parameter self_ to be used as an argument + if self_.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_self_ = unsafe {&mut *self_}; + let _optional_self_ = _handle_self_.as_mut_calculator(); + if _optional_self_.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _self_ = _optional_self_.unwrap(); + + // Call into trait class + _self_.calculate(); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_calculator_setprogresscallback(self_ : CalculatorHandle, progress_callback : ProgressCallback) -> i32 { + // Convert parameter self_ to be used as an argument + if self_.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_self_ = unsafe {&mut *self_}; + let _optional_self_ = _handle_self_.as_mut_calculator(); + if _optional_self_.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _self_ = _optional_self_.unwrap(); + + // Convert parameter progress_callback to be used as an argument + let _progress_callback = progress_callback; + + // Call into trait class + _self_.set_progress_callback(_progress_callback); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_factorizationcalculator_getprimefactors(self_ : FactorizationCalculatorHandle, prime_factors_buffer_size : usize, prime_factors_count : *mut usize, prime_factors_buffer : *mut PrimeFactor) -> i32 { + // Convert parameter self_ to be used as an argument + if self_.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_self_ = unsafe {&mut *self_}; + let _optional_self_ = _handle_self_.as_mut_factorization_calculator(); + if _optional_self_.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _self_ = _optional_self_.unwrap(); + + // Convert parameter prime_factors to be used as an argument + let mut _array_prime_factors : Vec = Vec::new(); + let _prime_factors = &mut _array_prime_factors; + + // Call into trait class + _self_.get_prime_factors(_prime_factors); + + // Pass the array prime_factors via output parameters + let _slice_prime_factors = _array_prime_factors.as_slice(); + if prime_factors_buffer_size > _slice_prime_factors.len() { return LIBPRIMES_ERROR_BUFFERTOOSMALL; } + if prime_factors_buffer.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + if prime_factors_count.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let mut _buffer_slice_prime_factors = unsafe { std::slice::from_raw_parts_mut(prime_factors_buffer, _slice_prime_factors.len()) }; + _buffer_slice_prime_factors.clone_from_slice(_slice_prime_factors); + let mut _prime_factors_count = unsafe { &mut *prime_factors_count }; + *_prime_factors_count = _slice_prime_factors.len(); + + // All ok - return success + LIBPRIMES_SUCCESS +} + +#[no_mangle] +pub fn libprimes_sievecalculator_getprimes(self_ : SieveCalculatorHandle, primes_buffer_size : usize, primes_count : *mut usize, primes_buffer : *mut u64) -> i32 { + // Convert parameter self_ to be used as an argument + if self_.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _handle_self_ = unsafe {&mut *self_}; + let _optional_self_ = _handle_self_.as_mut_sieve_calculator(); + if _optional_self_.is_none() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let _self_ = _optional_self_.unwrap(); + + // Convert parameter primes to be used as an argument + let mut _array_primes : Vec = Vec::new(); + let _primes = &mut _array_primes; + + // Call into trait class + _self_.get_primes(_primes); + + // Pass the array primes via output parameters + let _slice_primes = _array_primes.as_slice(); + if primes_buffer_size > _slice_primes.len() { return LIBPRIMES_ERROR_BUFFERTOOSMALL; } + if primes_buffer.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + if primes_count.is_null() { return LIBPRIMES_ERROR_INVALIDPARAM; } + let mut _buffer_slice_primes = unsafe { std::slice::from_raw_parts_mut(primes_buffer, _slice_primes.len()) }; + _buffer_slice_primes.clone_from_slice(_slice_primes); + let mut _primes_count = unsafe { &mut *primes_count }; + *_primes_count = _slice_primes.len(); + + // All ok - return success + LIBPRIMES_SUCCESS +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interfaces.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interfaces.rs new file mode 100644 index 00000000..08d8b6d3 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Interfaces/libprimes_interfaces.rs @@ -0,0 +1,261 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated rust file in order to allow easy +development of Prime Numbers Library. The implementer of Prime Numbers Library needs to +derive concrete classes from the abstract classes in this header. + +Interface version: 1.2.0 + +*/ + +#[allow(unused_imports)] +use std::ffi::c_void; + +/************************************************************************************************************************* + Version definition for LibPrimes +**************************************************************************************************************************/ + +#[allow(dead_code)] +pub const LIBPRIMES_VERSION_MAJOR : usize = 1; +#[allow(dead_code)] +pub const LIBPRIMES_VERSION_MINOR : usize = 2; +#[allow(dead_code)] +pub const LIBPRIMES_VERSION_MICRO : usize= 0; +#[allow(dead_code)] +pub const LIBPRIMES_VERSION_PRERELEASEINFO : &str = ""; +#[allow(dead_code)] +pub const LIBPRIMES_VERSION_BUILDINFO : &str = ""; + + +/************************************************************************************************************************* + Error constants for LibPrimes +**************************************************************************************************************************/ + +#[allow(dead_code)] +pub const LIBPRIMES_SUCCESS : i32 = 0; +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_NOTIMPLEMENTED : i32 = 1; /** functionality not implemented */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_INVALIDPARAM : i32 = 2; /** an invalid parameter was passed */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_INVALIDCAST : i32 = 3; /** a type cast failed */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_BUFFERTOOSMALL : i32 = 4; /** a provided buffer is too small */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_GENERICEXCEPTION : i32 = 5; /** a generic exception occurred */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_COULDNOTLOADLIBRARY : i32 = 6; /** the library could not be loaded */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT : i32 = 7; /** a required exported symbol could not be found in the library */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION : i32 = 8; /** the version of the binary interface does not match the bindings interface */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_NORESULTAVAILABLE : i32 = 9; /** no result is available */ +#[allow(dead_code)] +pub const LIBPRIMES_ERROR_CALCULATIONABORTED : i32 = 10; /** a calculation has been aborted */ + + +/************************************************************************************************************************* + Handle definiton for LibPrimes +**************************************************************************************************************************/ + +// Enum of all traits - this acts as a handle as we pass trait pointers through the interface + +#[allow(dead_code)] +pub enum HandleImpl { + TBase(u64, Box), + TCalculator(u64, Box), + TFactorizationCalculator(u64, Box), + TSieveCalculator(u64, Box) +} + +pub type Handle = *mut HandleImpl; +pub type BaseHandle =Handle; +pub type CalculatorHandle =Handle; +pub type FactorizationCalculatorHandle =Handle; +pub type SieveCalculatorHandle =Handle; +/************************************************************************************************************************* + Interface Struct definitions for LibPrimes +**************************************************************************************************************************/ + +#[repr(C)] +#[derive(Clone)] +pub struct PrimeFactor { + pub prime: u64, + pub multiplicity: u32 +} + +/************************************************************************************************************************* + Function type definitions for LibPrimes +**************************************************************************************************************************/ + +// Callback to report calculation progress and query whether it should be aborted +// +// * @param[in] progress_percentage - How far has the calculation progressed? +// * @param[out] should_abort - Should the calculation be aborted? +// +pub type ProgressCallback = unsafe extern "C" fn(progress_percentage : f32, should_abort : *mut u8); +/************************************************************************************************************************* + Traits defined for LibPrimes +**************************************************************************************************************************/ + +// Trait for interface Base +// +pub trait Base { + + // class_type_id + // + // Get Class Type Id + // * @param[return] class_type_id - Class type as a 64 bits integer + // + fn class_type_id(&mut self) -> u64; + + // get_last_error_message + // + // Returns the last error registered of this class instance + // * @param[out] error_message - Message of the last error registered + // * @param[return] has_last_error - Has an error been registered already + // + fn get_last_error_message(&mut self, error_message : &mut String) -> bool; + + // clear_error_messages + // + // Clears all registered messages of this class instance + // + fn clear_error_messages(&mut self); + + // register_error_message + // + // Registers an error message with this class instance + // * @param[in] error_message - Error message to register + // + fn register_error_message(&mut self, error_message : &str); +} + + +// Trait for interface Calculator +// +pub trait Calculator : Base { + + // get_value + // + // Returns the current value of this Calculator + // * @param[return] value - The current value of this Calculator + // + fn get_value(&mut self) -> u64; + + // set_value + // + // Sets the value to be factorized + // * @param[in] value - The value to be factorized + // + fn set_value(&mut self, value : u64); + + // calculate + // + // Performs the specific calculation of this Calculator + // + fn calculate(&mut self); + + // set_progress_callback + // + // Sets the progress callback function + // * @param[in] progress_callback - The progress callback + // + fn set_progress_callback(&mut self, progress_callback : ProgressCallback); +} + + +// Trait for interface FactorizationCalculator +// +pub trait FactorizationCalculator : Calculator { + + // get_prime_factors + // + // Returns the prime factors of this number (without multiplicity) + // * @param[out] prime_factors - The prime factors of this number + // + fn get_prime_factors(&mut self, prime_factors : &mut Vec); +} + + +// Trait for interface SieveCalculator +// +pub trait SieveCalculator : Calculator { + + // get_primes + // + // Returns all prime numbers lower or equal to the sieve's value + // * @param[out] primes - The primes lower or equal to the sieve's value + // + fn get_primes(&mut self, primes : &mut Vec); +} + + +/************************************************************************************************************************* + Trait defined for global methods of LibPrimes +**************************************************************************************************************************/ + +// Wrapper trait for global methods +// +pub trait Wrapper { + + // get_version + // + // retrieves the binary version of this library. + // * @param[out] major - returns the major version of this library + // * @param[out] minor - returns the minor version of this library + // * @param[out] micro - returns the micro version of this library + // + fn get_version(major : &mut u32, minor : &mut u32, micro : &mut u32); + + // get_last_error + // + // Returns the last error recorded on this object + // * @param[in] instance - Instance Handle + // * @param[out] error_message - Message of the last error + // * @param[return] has_error - Is there a last error to query + // + fn get_last_error(instance : & dyn Base, error_message : &mut String) -> bool; + + // acquire_instance + // + // Acquire shared ownership of an Instance + // * @param[in] instance - Instance Handle + // + fn acquire_instance(instance : & dyn Base); + + // release_instance + // + // Releases shared ownership of an Instance + // * @param[in] instance - Instance Handle + // + fn release_instance(instance : & dyn Base); + + // create_factorization_calculator + // + // Creates a new FactorizationCalculator instance + // * @param[return] instance - New FactorizationCalculator instance + // + fn create_factorization_calculator() -> Box; + + // create_sieve_calculator + // + // Creates a new SieveCalculator instance + // * @param[return] instance - New SieveCalculator instance + // + fn create_sieve_calculator() -> Box; + + // set_journal + // + // Handles Library Journaling + // * @param[in] file_name - Journal FileName + // + fn set_journal(file_name : &str); +} diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes.rs new file mode 100644 index 00000000..1fa0a5ef --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes.rs @@ -0,0 +1,92 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +use libprimes_interfaces::*; + +// Wrapper struct to implement the wrapper trait for global methods +pub struct CWrapper; + +impl Wrapper for CWrapper { + + + // get_version + // + // retrieves the binary version of this library. + // * @param[out] major - returns the major version of this library + // * @param[out] minor - returns the minor version of this library + // * @param[out] micro - returns the micro version of this library + // + fn get_version(_major : &mut u32, _minor : &mut u32, _micro : &mut u32) { + unimplemented!(); + } + + // get_last_error + // + // Returns the last error recorded on this object + // * @param[in] instance - Instance Handle + // * @param[out] error_message - Message of the last error + // * @param[return] has_error - Is there a last error to query + // + fn get_last_error(_instance : & dyn Base, _error_message : &mut String) -> bool { + unimplemented!(); + } + + // acquire_instance + // + // Acquire shared ownership of an Instance + // * @param[in] instance - Instance Handle + // + fn acquire_instance(_instance : & dyn Base) { + unimplemented!(); + } + + // release_instance + // + // Releases shared ownership of an Instance + // * @param[in] instance - Instance Handle + // + fn release_instance(_instance : & dyn Base) { + unimplemented!(); + } + + // create_factorization_calculator + // + // Creates a new FactorizationCalculator instance + // * @param[return] instance - New FactorizationCalculator instance + // + fn create_factorization_calculator() -> Box { + unimplemented!(); + } + + // create_sieve_calculator + // + // Creates a new SieveCalculator instance + // * @param[return] instance - New SieveCalculator instance + // + fn create_sieve_calculator() -> Box { + unimplemented!(); + } + + // set_journal + // + // Handles Library Journaling + // * @param[in] file_name - Journal FileName + // + fn set_journal(_file_name : &str) { + unimplemented!(); + } +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_base.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_base.rs new file mode 100644 index 00000000..4cb747bd --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_base.rs @@ -0,0 +1,66 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +use libprimes_interfaces::*; + +// Stub struct to implement the Base trait +pub struct CBase { + last_error : Option +} + +impl Base for CBase { + + // get_last_error_message + // + // Returns the last error registered of this class instance + // * @param[out] error_message - Message of the last error registered + // * @param[return] has_last_error - Has an error been registered already + // + fn get_last_error_message(&mut self, _error_message : &mut String) -> bool { + match &self.last_error { + None => false, + Some(error_val) => { + *_error_message = error_val.clone(); + true + } + } + } + // clear_error_messages + // + // Clears all registered messages of this class instance + // + fn clear_error_messages(&mut self) { + self.last_error = None; + } + // register_error_message + // + // Registers an error message with this class instance + // * @param[in] error_message - Error message to register + // + fn register_error_message(&mut self, _error_message : &str) { + self.last_error = Some(_error_message.to_string()); + } + + // class_type_id + // + // Get Class Type Id + // * @param[return] class_type_id - Class type as a 64 bits integer + // + fn class_type_id(&mut self) -> u64 { + unimplemented!(); + } +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_calculator.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_calculator.rs new file mode 100644 index 00000000..f2167a55 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_calculator.rs @@ -0,0 +1,104 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +use libprimes_interfaces::*; +use libprimes_base::CBase; + +// Stub struct to implement the Calculator trait +pub struct CCalculator { + parent : CBase +} + +// Implementation of parent traits via parent + +impl Base for CCalculator { + + // class_type_id + // + // Get Class Type Id + // * @param[return] class_type_id - Class type as a 64 bits integer + // + fn class_type_id(&mut self) -> u64 { + self.parent.class_type_id() + } + + // get_last_error_message + // + // Returns the last error registered of this class instance + // * @param[out] error_message - Message of the last error registered + // * @param[return] has_last_error - Has an error been registered already + // + fn get_last_error_message(&mut self, error_message : &mut String) -> bool { + self.parent.get_last_error_message(error_message) + } + + // clear_error_messages + // + // Clears all registered messages of this class instance + // + fn clear_error_messages(&mut self) { + self.parent.clear_error_messages() + } + + // register_error_message + // + // Registers an error message with this class instance + // * @param[in] error_message - Error message to register + // + fn register_error_message(&mut self, error_message : &str) { + self.parent.register_error_message(error_message) + } +} + +impl Calculator for CCalculator { + + + // get_value + // + // Returns the current value of this Calculator + // * @param[return] value - The current value of this Calculator + // + fn get_value(&mut self) -> u64 { + unimplemented!(); + } + + // set_value + // + // Sets the value to be factorized + // * @param[in] value - The value to be factorized + // + fn set_value(&mut self, _value : u64) { + unimplemented!(); + } + + // calculate + // + // Performs the specific calculation of this Calculator + // + fn calculate(&mut self) { + unimplemented!(); + } + + // set_progress_callback + // + // Sets the progress callback function + // * @param[in] progress_callback - The progress callback + // + fn set_progress_callback(&mut self, _progress_callback : ProgressCallback) { + unimplemented!(); + } +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_factorization_calculator.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_factorization_calculator.rs new file mode 100644 index 00000000..149c9da5 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_factorization_calculator.rs @@ -0,0 +1,115 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +use libprimes_interfaces::*; +use libprimes_calculator::CCalculator; + +// Stub struct to implement the FactorizationCalculator trait +pub struct CFactorizationCalculator { + parent : CCalculator +} + +// Implementation of parent traits via parent + +impl Calculator for CFactorizationCalculator { + + // get_value + // + // Returns the current value of this Calculator + // * @param[return] value - The current value of this Calculator + // + fn get_value(&mut self) -> u64 { + self.parent.get_value() + } + + // set_value + // + // Sets the value to be factorized + // * @param[in] value - The value to be factorized + // + fn set_value(&mut self, value : u64) { + self.parent.set_value(value) + } + + // calculate + // + // Performs the specific calculation of this Calculator + // + fn calculate(&mut self) { + self.parent.calculate() + } + + // set_progress_callback + // + // Sets the progress callback function + // * @param[in] progress_callback - The progress callback + // + fn set_progress_callback(&mut self, progress_callback : ProgressCallback) { + self.parent.set_progress_callback(progress_callback) + } +} +impl Base for CFactorizationCalculator { + + // class_type_id + // + // Get Class Type Id + // * @param[return] class_type_id - Class type as a 64 bits integer + // + fn class_type_id(&mut self) -> u64 { + self.parent.class_type_id() + } + + // get_last_error_message + // + // Returns the last error registered of this class instance + // * @param[out] error_message - Message of the last error registered + // * @param[return] has_last_error - Has an error been registered already + // + fn get_last_error_message(&mut self, error_message : &mut String) -> bool { + self.parent.get_last_error_message(error_message) + } + + // clear_error_messages + // + // Clears all registered messages of this class instance + // + fn clear_error_messages(&mut self) { + self.parent.clear_error_messages() + } + + // register_error_message + // + // Registers an error message with this class instance + // * @param[in] error_message - Error message to register + // + fn register_error_message(&mut self, error_message : &str) { + self.parent.register_error_message(error_message) + } +} + +impl FactorizationCalculator for CFactorizationCalculator { + + + // get_prime_factors + // + // Returns the prime factors of this number (without multiplicity) + // * @param[out] prime_factors - The prime factors of this number + // + fn get_prime_factors(&mut self, _prime_factors : &mut Vec) { + unimplemented!(); + } +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_sieve_calculator.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_sieve_calculator.rs new file mode 100644 index 00000000..fccd0480 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/Stub/libprimes_sieve_calculator.rs @@ -0,0 +1,115 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +use libprimes_interfaces::*; +use libprimes_calculator::CCalculator; + +// Stub struct to implement the SieveCalculator trait +pub struct CSieveCalculator { + parent : CCalculator +} + +// Implementation of parent traits via parent + +impl Calculator for CSieveCalculator { + + // get_value + // + // Returns the current value of this Calculator + // * @param[return] value - The current value of this Calculator + // + fn get_value(&mut self) -> u64 { + self.parent.get_value() + } + + // set_value + // + // Sets the value to be factorized + // * @param[in] value - The value to be factorized + // + fn set_value(&mut self, value : u64) { + self.parent.set_value(value) + } + + // calculate + // + // Performs the specific calculation of this Calculator + // + fn calculate(&mut self) { + self.parent.calculate() + } + + // set_progress_callback + // + // Sets the progress callback function + // * @param[in] progress_callback - The progress callback + // + fn set_progress_callback(&mut self, progress_callback : ProgressCallback) { + self.parent.set_progress_callback(progress_callback) + } +} +impl Base for CSieveCalculator { + + // class_type_id + // + // Get Class Type Id + // * @param[return] class_type_id - Class type as a 64 bits integer + // + fn class_type_id(&mut self) -> u64 { + self.parent.class_type_id() + } + + // get_last_error_message + // + // Returns the last error registered of this class instance + // * @param[out] error_message - Message of the last error registered + // * @param[return] has_last_error - Has an error been registered already + // + fn get_last_error_message(&mut self, error_message : &mut String) -> bool { + self.parent.get_last_error_message(error_message) + } + + // clear_error_messages + // + // Clears all registered messages of this class instance + // + fn clear_error_messages(&mut self) { + self.parent.clear_error_messages() + } + + // register_error_message + // + // Registers an error message with this class instance + // * @param[in] error_message - Error message to register + // + fn register_error_message(&mut self, error_message : &str) { + self.parent.register_error_message(error_message) + } +} + +impl SieveCalculator for CSieveCalculator { + + + // get_primes + // + // Returns all prime numbers lower or equal to the sieve's value + // * @param[out] primes - The primes lower or equal to the sieve's value + // + fn get_primes(&mut self, _primes : &mut Vec) { + unimplemented!(); + } +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Rust/lib.rs b/Examples/Primes/LibPrimes_component/Implementations/Rust/lib.rs new file mode 100644 index 00000000..629c58a9 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Rust/lib.rs @@ -0,0 +1,44 @@ +/*++ + +Copyright (C) 2019 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.8.0-develop. + +Abstract: This is an autogenerated Rust implementation file in order to allow easy +development of Prime Numbers Library. It needs to be generated only once. + +Interface version: 1.2.0 + +*/ + + +#![feature(trait_upcasting)] +#![allow(incomplete_features)] +#![feature(vec_into_raw_parts)] + +#[path = "Interfaces/libprimes_interfaces.rs"] +mod libprimes_interfaces; + +#[path = "Interfaces/libprimes_interface_wrapper.rs"] +mod libprimes_interface_wrapper; + +#[path = "Interfaces/libprimes_interface_handle.rs"] +mod libprimes_interface_handle; + +#[path = "Stub/libprimes.rs"] +mod libprimes; + +#[path = "Stub/libprimes_base.rs"] +mod libprimes_base; + +#[path = "Stub/libprimes_calculator.rs"] +mod libprimes_calculator; + +#[path = "Stub/libprimes_factorization_calculator.rs"] +mod libprimes_factorization_calculator; + +#[path = "Stub/libprimes_sieve_calculator.rs"] +mod libprimes_sieve_calculator; +