diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..5673f522 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,22 @@ +# Configuration file for Travis CI (https://travis-ci.org) +# +# It used as a status check for all PRs and +# to generate the build-status-icon in the main README.md-file. + +language: go + +go: + - 1.11.x + +matrix: + include: + - os: linux + compiler: gcc + - os: osx + osx_image: xcode7.2 + +before_script: + - cd Build + +script: + - sh build.sh diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..b9d886d9 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at automatic-component-toolkit.contributor.agreements@autodesk.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c68894bf..bb2384eb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,6 +16,8 @@ You can also contribute by reporting bugs in the [Issue tracker](../../issues), 2. When contributing to this repository, please first discuss the change you wish to make via issue with the [maintainers](#maintainers) of this repository. This way, we can ensure that there is no overlap between contributions or internal development work. +3. Adhere to the [code of conduct](CODE_OF_CONDUCT.md). + ## Submitting a pull request When ready to contribute, fork this repository and submit a pull request that references the issue it resolves. Be sure to include a clear and detailed description of the changes you've made so that we can verify them and eventually merge. diff --git a/Documentation/IDL.md b/Documentation/IDL.md index 4a9ea9d9..f772b850 100644 --- a/Documentation/IDL.md +++ b/Documentation/IDL.md @@ -4,7 +4,7 @@ -| **Version** | 0.1.0 | +| **Version** | 1.3.2 | | --- | --- | ## Disclaimer @@ -76,6 +76,7 @@ Element **\** of type **CT\_Component** | namespace | **ST\_NameSpace** | required | | Specifies the namespace for the components's functionality. | | copyright | **xs:string** | required | | The legal copyright holder. | | basename | **ST\_BaseName** | required | | The basename will be used as prefix for generated filenames and all sorts of identifiers in the generated source code. | +| version | **ST\_Version** | required | | The three digit vesion of this component. | | year | **ST\_Year** | optional | the current year | The year associcated with the copyright. | | @anyAttribute | | | | | @@ -97,13 +98,13 @@ Element **\** of type **CT\_License** ![element license](images/element_license.png) -The \ element contains a list of at least one child [license line](#3-license-line) element. +The \ element contains a list of at least one child [line](#3-line) element. The license lines will be included as comments at the start of all generated source code files. -## 3. License Line -Element **\** of type **CT\_LicenseLine** +## 3. Line +Element **\** of type **CT\_LicenseLine** -![element licenseline](images/element_licenseline.png) +![element line](images/element_line.png) ##### Attributes | Name | Type | Use | Default | Annotation | @@ -163,7 +164,10 @@ Element **\** of type **CT\_Global** The \ element contains a list of [method](#9-function-type) elements that define the exported global functions of the component. The names of the \ elements MUST be unique within the \ element. -TODO: explanation of siganture of release and version method. +The `releasemethod`-attribute must be the name of a \ within the \ element of a method that has exactly one parameter with `type="handle"`, `class="BaseClass"` and `pass="in"`. +The `versionmethod`-attribute must be the name of a \ within the \ element of a method that has exactly three parameters with `type="uint32"` and `pass="out"`. + +If the `journalmethod` attribute is given, it must be the name of a \ within the \ element of a method that has exactly one parameter with `type="string"` and `pass="in"`. ## 8. Class Element **\** of type **CT\_Class** @@ -314,6 +318,11 @@ TODO: add all simple types here. ST_Type `string` denotes a null-terminated string. If a component requires arbitrary strings that can contain null-characters, on should use the type `basicarray` of class `uint8`. ### 17.2 ScalarType +ST_ScalarType `bool` denotes a boolean value (`true` or `false`). +Although this can be encoded in a single bit, the thin C89-layer APIs generated by ACT will use a unsigned 8 bit value (a `uint8` in ACT terms) to encode a boolean value. +A numerical value of `0` encodes `false`, all oher values encode `true`. +Implementations and bindings should use the definition of a boolean value native to the respective language of the implementation or binding. + ### 17.3 ComposedType ### 17.4 Name ### 17.5 Description @@ -332,8 +341,7 @@ ST_Type `string` denotes a null-terminated string. If a component requires arbit # Appendix A. XSD Schema of ACT-IDL -See [ACT.xsd](../Source/ACT.xsd). -TODO: include the .xsds content here. +See [ACT.xsd](../Source/ACT.xsd) # Appendix B. Example of ACT-IDL -dolor sit amen +See [libPrimes.xml](../Examples/Primes/libPrimes.xml) diff --git a/Documentation/images/element_bindings.png b/Documentation/images/element_bindings.png index b621caef..0e64efa2 100644 Binary files a/Documentation/images/element_bindings.png and b/Documentation/images/element_bindings.png differ diff --git a/Documentation/images/element_class.png b/Documentation/images/element_class.png index 61b39608..f61ac7c9 100644 Binary files a/Documentation/images/element_class.png and b/Documentation/images/element_class.png differ diff --git a/Documentation/images/element_component.png b/Documentation/images/element_component.png index 64227d14..eac80bcc 100644 Binary files a/Documentation/images/element_component.png and b/Documentation/images/element_component.png differ diff --git a/Documentation/images/element_enum.png b/Documentation/images/element_enum.png index 05a44978..741094a5 100644 Binary files a/Documentation/images/element_enum.png and b/Documentation/images/element_enum.png differ diff --git a/Documentation/images/element_error.png b/Documentation/images/element_error.png index 04570916..179ab7a5 100644 Binary files a/Documentation/images/element_error.png and b/Documentation/images/element_error.png differ diff --git a/Documentation/images/element_errors.png b/Documentation/images/element_errors.png index 726081c4..02e4d78a 100644 Binary files a/Documentation/images/element_errors.png and b/Documentation/images/element_errors.png differ diff --git a/Documentation/images/element_global.png b/Documentation/images/element_global.png index 1e7dd12d..4931fd68 100644 Binary files a/Documentation/images/element_global.png and b/Documentation/images/element_global.png differ diff --git a/Documentation/images/element_implementations.png b/Documentation/images/element_implementations.png index de6cad6a..2b96d820 100644 Binary files a/Documentation/images/element_implementations.png and b/Documentation/images/element_implementations.png differ diff --git a/Documentation/images/element_license.png b/Documentation/images/element_license.png index 5e322a8f..db090b98 100644 Binary files a/Documentation/images/element_license.png and b/Documentation/images/element_license.png differ diff --git a/Documentation/images/element_licenseline.png b/Documentation/images/element_licenseline.png deleted file mode 100644 index e35677a2..00000000 Binary files a/Documentation/images/element_licenseline.png and /dev/null differ diff --git a/Documentation/images/element_line.png b/Documentation/images/element_line.png new file mode 100644 index 00000000..216605b4 Binary files /dev/null and b/Documentation/images/element_line.png differ diff --git a/Documentation/images/element_member.png b/Documentation/images/element_member.png index 88128698..989ecc41 100644 Binary files a/Documentation/images/element_member.png and b/Documentation/images/element_member.png differ diff --git a/Documentation/images/element_option.png b/Documentation/images/element_option.png index a4e45a71..f3e313f0 100644 Binary files a/Documentation/images/element_option.png and b/Documentation/images/element_option.png differ diff --git a/Documentation/images/element_param.png b/Documentation/images/element_param.png index 12fe8681..0f6c8271 100644 Binary files a/Documentation/images/element_param.png and b/Documentation/images/element_param.png differ diff --git a/Documentation/images/element_struct.png b/Documentation/images/element_struct.png index 2dcdf7b3..f627cf54 100644 Binary files a/Documentation/images/element_struct.png and b/Documentation/images/element_struct.png differ diff --git a/Documentation/images/type_export.png b/Documentation/images/type_export.png index 8df1d3bc..cda8e073 100644 Binary files a/Documentation/images/type_export.png and b/Documentation/images/type_export.png differ diff --git a/Documentation/images/type_functiontype.png b/Documentation/images/type_functiontype.png index 3acd3be1..02db1e97 100644 Binary files a/Documentation/images/type_functiontype.png and b/Documentation/images/type_functiontype.png differ diff --git a/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_dynamic.cpp b/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_dynamic.cpp deleted file mode 100644 index dbef9399..00000000 --- a/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_dynamic.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/*++ - -Copyright (C) 2018 Automatic Component Toolkit Developers - -All rights reserved. - -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. - -Abstract: This is an autogenerated plain C Header file in order to allow an easy - use of Prime Numbers Interface - -Interface version: 1.3.0 - -*/ - -#include "libprimes_types.h" -#include "libprimes_dynamic.h" -#ifdef WIN32 -#include -#else // WIN32 -#include -#endif // WIN32 - -LibPrimesResult InitLibPrimesWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable) -{ - if (pWrapperTable == nullptr) - return LIBPRIMES_ERROR_INVALIDPARAM; - - pWrapperTable->m_LibraryHandle = nullptr; - pWrapperTable->m_Calculator_GetValue = nullptr; - pWrapperTable->m_Calculator_SetValue = nullptr; - pWrapperTable->m_Calculator_SetProgressCallback = nullptr; - pWrapperTable->m_Calculator_Calculate = nullptr; - pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = nullptr; - pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors = nullptr; - pWrapperTable->m_SieveCalculator_GetPrimes = nullptr; - pWrapperTable->m_CreateFactorizationCalculator = nullptr; - pWrapperTable->m_CreateSieveCalculator = nullptr; - pWrapperTable->m_ReleaseInstance = nullptr; - pWrapperTable->m_GetLibraryVersion = nullptr; - pWrapperTable->m_SetJournal = nullptr; - - return LIBPRIMES_SUCCESS; -} - -LibPrimesResult ReleaseLibPrimesWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable) -{ - if (pWrapperTable == nullptr) - return LIBPRIMES_ERROR_INVALIDPARAM; - - if (pWrapperTable->m_LibraryHandle != nullptr) { - #ifdef WIN32 - HMODULE hModule = (HMODULE) pWrapperTable->m_LibraryHandle; - FreeLibrary (hModule); - #else // WIN32 - dlclose (pWrapperTable->m_LibraryHandle); - #endif // WIN32 - return InitLibPrimesWrapperTable (pWrapperTable); - } - - return LIBPRIMES_SUCCESS; -} - -LibPrimesResult LoadLibPrimesWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName) -{ - if (pWrapperTable == nullptr) - return LIBPRIMES_ERROR_INVALIDPARAM; - if (pLibraryFileName == nullptr) - return LIBPRIMES_ERROR_INVALIDPARAM; - - #ifdef WIN32 - HMODULE hLibrary = LoadLibraryA (pLibraryFileName); - if (hLibrary == 0) - return LIBPRIMES_ERROR_COULDNOTLOADLIBRARY; - #else // WIN32 - void* hLibrary = dlopen (pLibraryFileName, RTLD_LAZY); - if (hLibrary == 0) - return LIBPRIMES_ERROR_COULDNOTLOADLIBRARY; - dlerror(); - #endif // WIN32 - - #ifdef WIN32 - pWrapperTable->m_Calculator_GetValue = (PLibPrimesCalculator_GetValuePtr) GetProcAddress (hLibrary, "libprimes_calculator_getvalue"); - #else // WIN32 - pWrapperTable->m_Calculator_GetValue = (PLibPrimesCalculator_GetValuePtr) dlsym (hLibrary, "libprimes_calculator_getvalue"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_Calculator_GetValue == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_Calculator_SetValue = (PLibPrimesCalculator_SetValuePtr) GetProcAddress (hLibrary, "libprimes_calculator_setvalue"); - #else // WIN32 - pWrapperTable->m_Calculator_SetValue = (PLibPrimesCalculator_SetValuePtr) dlsym (hLibrary, "libprimes_calculator_setvalue"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_Calculator_SetValue == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_Calculator_SetProgressCallback = (PLibPrimesCalculator_SetProgressCallbackPtr) GetProcAddress (hLibrary, "libprimes_calculator_setprogresscallback"); - #else // WIN32 - pWrapperTable->m_Calculator_SetProgressCallback = (PLibPrimesCalculator_SetProgressCallbackPtr) dlsym (hLibrary, "libprimes_calculator_setprogresscallback"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_Calculator_SetProgressCallback == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_Calculator_Calculate = (PLibPrimesCalculator_CalculatePtr) GetProcAddress (hLibrary, "libprimes_calculator_calculate"); - #else // WIN32 - pWrapperTable->m_Calculator_Calculate = (PLibPrimesCalculator_CalculatePtr) dlsym (hLibrary, "libprimes_calculator_calculate"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_Calculator_Calculate == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = (PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) GetProcAddress (hLibrary, "libprimes_factorizationcalculator_getprimefactors"); - #else // WIN32 - pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = (PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) dlsym (hLibrary, "libprimes_factorizationcalculator_getprimefactors"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_FactorizationCalculator_GetPrimeFactors == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors = (PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr) GetProcAddress (hLibrary, "libprimes_factorizationcalculator_checkprimefactors"); - #else // WIN32 - pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors = (PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr) dlsym (hLibrary, "libprimes_factorizationcalculator_checkprimefactors"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_SieveCalculator_GetPrimes = (PLibPrimesSieveCalculator_GetPrimesPtr) GetProcAddress (hLibrary, "libprimes_sievecalculator_getprimes"); - #else // WIN32 - pWrapperTable->m_SieveCalculator_GetPrimes = (PLibPrimesSieveCalculator_GetPrimesPtr) dlsym (hLibrary, "libprimes_sievecalculator_getprimes"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_SieveCalculator_GetPrimes == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_CreateFactorizationCalculator = (PLibPrimesCreateFactorizationCalculatorPtr) GetProcAddress (hLibrary, "libprimes_createfactorizationcalculator"); - #else // WIN32 - pWrapperTable->m_CreateFactorizationCalculator = (PLibPrimesCreateFactorizationCalculatorPtr) dlsym (hLibrary, "libprimes_createfactorizationcalculator"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_CreateFactorizationCalculator == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_CreateSieveCalculator = (PLibPrimesCreateSieveCalculatorPtr) GetProcAddress (hLibrary, "libprimes_createsievecalculator"); - #else // WIN32 - pWrapperTable->m_CreateSieveCalculator = (PLibPrimesCreateSieveCalculatorPtr) dlsym (hLibrary, "libprimes_createsievecalculator"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_CreateSieveCalculator == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_ReleaseInstance = (PLibPrimesReleaseInstancePtr) GetProcAddress (hLibrary, "libprimes_releaseinstance"); - #else // WIN32 - pWrapperTable->m_ReleaseInstance = (PLibPrimesReleaseInstancePtr) dlsym (hLibrary, "libprimes_releaseinstance"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_ReleaseInstance == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_GetLibraryVersion = (PLibPrimesGetLibraryVersionPtr) GetProcAddress (hLibrary, "libprimes_getlibraryversion"); - #else // WIN32 - pWrapperTable->m_GetLibraryVersion = (PLibPrimesGetLibraryVersionPtr) dlsym (hLibrary, "libprimes_getlibraryversion"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_GetLibraryVersion == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef WIN32 - pWrapperTable->m_SetJournal = (PLibPrimesSetJournalPtr) GetProcAddress (hLibrary, "libprimes_setjournal"); - #else // WIN32 - pWrapperTable->m_SetJournal = (PLibPrimesSetJournalPtr) dlsym (hLibrary, "libprimes_setjournal"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_SetJournal == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - - pWrapperTable->m_LibraryHandle = hLibrary; - return LIBPRIMES_SUCCESS; -} - diff --git a/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_dynamic.h b/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_dynamic.h deleted file mode 100644 index 9f4e96cb..00000000 --- a/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_dynamic.h +++ /dev/null @@ -1,176 +0,0 @@ -/*++ - -Copyright (C) 2018 Automatic Component Toolkit Developers - -All rights reserved. - -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. - -Abstract: This is an autogenerated plain C Header file in order to allow an easy - use of Prime Numbers Interface - -Interface version: 1.3.0 - -*/ - -#ifndef __LIBPRIMES_DYNAMICHEADER -#define __LIBPRIMES_DYNAMICHEADER - -#include "libprimes_types.h" - - -/************************************************************************************************************************* - Class definition for Calculator -**************************************************************************************************************************/ - -/** -* Returns the current value of this Calculator -* -* @param[in] pCalculator - Calculator instance. -* @param[out] pValue - The current value of this Calculator -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesCalculator_GetValuePtr) (LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue); - -/** -* Sets the value to be factorized -* -* @param[in] pCalculator - Calculator instance. -* @param[in] nValue - The value to be factorized -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesCalculator_SetValuePtr) (LibPrimes_Calculator pCalculator, LibPrimes_uint64 nValue); - -/** -* Sets the progress callback function -* -* @param[in] pCalculator - Calculator instance. -* @param[in] pProgressCallback - The progress callback -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesCalculator_SetProgressCallbackPtr) (LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback); - -/** -* Performs the specific calculation of this Calculator -* -* @param[in] pCalculator - Calculator instance. -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesCalculator_CalculatePtr) (LibPrimes_Calculator pCalculator); - -/************************************************************************************************************************* - Class definition for FactorizationCalculator -**************************************************************************************************************************/ - -/** -* Returns the prime factors of this number (with multiplicity) -* -* @param[in] pFactorizationCalculator - FactorizationCalculator instance. -* @param[in] nPrimeFactorsBufferSize - Number of elements in buffer -* @param[out] pPrimeFactorsNeededCount - will be filled with the count of the written elements, or needed buffer size. -* @param[out] pPrimeFactorsBuffer - PrimeFactor buffer of The prime factors of this number -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) (LibPrimes_FactorizationCalculator pFactorizationCalculator, const LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); - -/** -* Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value -* -* @param[in] pFactorizationCalculator - FactorizationCalculator instance. -* @param[in] nPrimeFactorsBufferSize - Number of elements in buffer -* @param[in] pPrimeFactorsBuffer - PrimeFactor buffer of -* @param[out] pAreEqual - Do the prime factors decompose this calculator's value -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr) (LibPrimes_FactorizationCalculator pFactorizationCalculator, LibPrimes_uint64 nPrimeFactorsBufferSize, const sLibPrimesPrimeFactor * pPrimeFactorsBuffer, bool * pAreEqual); - -/************************************************************************************************************************* - Class definition for SieveCalculator -**************************************************************************************************************************/ - -/** -* Returns all prime numbers lower or equal to the sieve's value -* -* @param[in] pSieveCalculator - SieveCalculator instance. -* @param[in] nPrimesBufferSize - Number of elements in buffer -* @param[out] pPrimesNeededCount - will be filled with the count of the written elements, or needed buffer size. -* @param[out] pPrimesBuffer - uint64 buffer of The primes lower or equal to the sieve's value -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesSieveCalculator_GetPrimesPtr) (LibPrimes_SieveCalculator pSieveCalculator, const LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer); - -/************************************************************************************************************************* - Global functions -**************************************************************************************************************************/ - -/** -* Creates a new FactorizationCalculator instance -* -* @param[out] pInstance - New FactorizationCalculator instance -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesCreateFactorizationCalculatorPtr) (LibPrimes_FactorizationCalculator * pInstance); - -/** -* Creates a new SieveCalculator instance -* -* @param[out] pInstance - New SieveCalculator instance -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesCreateSieveCalculatorPtr) (LibPrimes_SieveCalculator * pInstance); - -/** -* Releases the memory of an Instance -* -* @param[in] pInstance - Instance Handle -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesReleaseInstancePtr) (LibPrimes_BaseClass pInstance); - -/** -* retrieves the current version of the library. -* -* @param[out] pMajor - returns the major version of the library -* @param[out] pMinor - returns the minor version of the library -* @param[out] pMicro - returns the micro version of the library -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesGetLibraryVersionPtr) (LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro); - -/** -* Handles Library Journaling -* -* @param[in] pFileName - Journal FileName -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesSetJournalPtr) (const char * pFileName); - -/************************************************************************************************************************* - Function Table Structure -**************************************************************************************************************************/ - -typedef struct { - void * m_LibraryHandle; - PLibPrimesCalculator_GetValuePtr m_Calculator_GetValue; - PLibPrimesCalculator_SetValuePtr m_Calculator_SetValue; - PLibPrimesCalculator_SetProgressCallbackPtr m_Calculator_SetProgressCallback; - PLibPrimesCalculator_CalculatePtr m_Calculator_Calculate; - PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr m_FactorizationCalculator_GetPrimeFactors; - PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr m_FactorizationCalculator_CheckPrimeFactors; - PLibPrimesSieveCalculator_GetPrimesPtr m_SieveCalculator_GetPrimes; - PLibPrimesCreateFactorizationCalculatorPtr m_CreateFactorizationCalculator; - PLibPrimesCreateSieveCalculatorPtr m_CreateSieveCalculator; - PLibPrimesReleaseInstancePtr m_ReleaseInstance; - PLibPrimesGetLibraryVersionPtr m_GetLibraryVersion; - PLibPrimesSetJournalPtr m_SetJournal; -} sLibPrimesDynamicWrapperTable; - -/************************************************************************************************************************* - Load DLL dynamically -**************************************************************************************************************************/ -LibPrimesResult InitLibPrimesWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable); -LibPrimesResult ReleaseLibPrimesWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable); -LibPrimesResult LoadLibPrimesWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName); - -#endif // __LIBPRIMES_DYNAMICHEADER - diff --git a/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_types.h b/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_types.h deleted file mode 100644 index 92b19290..00000000 --- a/Examples/Primes/LibPrimes_component/Bindings/CDynamic/libprimes_types.h +++ /dev/null @@ -1,116 +0,0 @@ -/*++ - -Copyright (C) 2018 Automatic Component Toolkit Developers - -All rights reserved. - -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. - -Abstract: This is an autogenerated plain C Header file with basic types in -order to allow an easy use of Prime Numbers Interface - -Interface version: 1.3.0 - -*/ - -#ifndef __LIBPRIMES_TYPES_HEADER -#define __LIBPRIMES_TYPES_HEADER - -/************************************************************************************************************************* - Scalar types definition -**************************************************************************************************************************/ - -#ifdef LIBPRIMES_USELEGACYINTEGERTYPES - -typedef unsigned char LibPrimes_uint8; -typedef unsigned short LibPrimes_uint16 ; -typedef unsigned int LibPrimes_uint32; -typedef unsigned long long LibPrimes_uint64; -typedef char LibPrimes_int8; -typedef short LibPrimes_int16; -typedef int LibPrimes_int32; -typedef long long LibPrimes_int64; - -#else // LIBPRIMES_USELEGACYINTEGERTYPES - -#include - -typedef uint8_t LibPrimes_uint8; -typedef uint16_t LibPrimes_uint16; -typedef uint32_t LibPrimes_uint32; -typedef uint64_t LibPrimes_uint64; -typedef int8_t LibPrimes_int8; -typedef int16_t LibPrimes_int16; -typedef int32_t LibPrimes_int32; -typedef int64_t LibPrimes_int64 ; - -#endif // LIBPRIMES_USELEGACYINTEGERTYPES - -typedef float LibPrimes_single; -typedef double LibPrimes_double; - -/************************************************************************************************************************* - General type definitions -**************************************************************************************************************************/ - -typedef LibPrimes_int32 LibPrimesResult; -typedef void * LibPrimesHandle; - -/************************************************************************************************************************* - Version for LibPrimes -**************************************************************************************************************************/ - -#define LIBPRIMES_VERSION_MAJOR 1 -#define LIBPRIMES_VERSION_MINOR 3 -#define LIBPRIMES_VERSION_MICRO 0 - -/************************************************************************************************************************* - Error constants for LibPrimes -**************************************************************************************************************************/ - -#define LIBPRIMES_SUCCESS 0 -#define LIBPRIMES_ERROR_NOTIMPLEMENTED 1 -#define LIBPRIMES_ERROR_INVALIDPARAM 2 -#define LIBPRIMES_ERROR_INVALIDCAST 3 -#define LIBPRIMES_ERROR_BUFFERTOOSMALL 4 -#define LIBPRIMES_ERROR_GENERICEXCEPTION 5 -#define LIBPRIMES_ERROR_COULDNOTLOADLIBRARY 6 -#define LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT 7 -#define LIBPRIMES_ERROR_NORESULTAVAILABLE 8 -#define LIBPRIMES_ERROR_CALCULATIONABORTED 9 - -/************************************************************************************************************************* - Declaration of handle classes -**************************************************************************************************************************/ - -typedef LibPrimesHandle LibPrimes_BaseClass; -typedef LibPrimesHandle LibPrimes_Calculator; -typedef LibPrimesHandle LibPrimes_FactorizationCalculator; -typedef LibPrimesHandle LibPrimes_SieveCalculator; - -/************************************************************************************************************************* - Declaration of structs -**************************************************************************************************************************/ - -#pragma pack (1) - -typedef struct { - LibPrimes_uint64 m_Prime; - LibPrimes_uint32 m_Multiplicity; -} sLibPrimesPrimeFactor; - -#pragma pack () - -/************************************************************************************************************************* - Declaration of function pointers -**************************************************************************************************************************/ - -/** -* LibPrimesProgressCallback - Callback to report calculation progress and query whether it should be aborted -* -* @param[in] fProgressPercentage - How far has the calculation progressed? -* @param[out] pShouldAbort - Should the calculation be aborted? -*/ -typedef void(*LibPrimesProgressCallback)(LibPrimes_single, bool*); - -#endif // __LIBPRIMES_TYPES_HEADER diff --git a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.cpp b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.cpp index eccdeba8..92cda33c 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.cpp +++ b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.cpp @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated C++ Wrapper Implementation file in order to allow -an easy use of Prime Numbers Interface +an easy use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -94,20 +94,20 @@ void CLibPrimesCalculator::SetValue (const LibPrimes_uint64 nValue) } /** -* CLibPrimesCalculator::SetProgressCallback - Sets the progress callback function -* @param[in] pProgressCallback - The progress callback +* CLibPrimesCalculator::Calculate - Performs the specific calculation of this Calculator */ -void CLibPrimesCalculator::SetProgressCallback (const LibPrimesProgressCallback pProgressCallback) +void CLibPrimesCalculator::Calculate () { - CheckError ( libprimes_calculator_setprogresscallback (m_pHandle, pProgressCallback) ); + CheckError ( libprimes_calculator_calculate (m_pHandle) ); } /** -* CLibPrimesCalculator::Calculate - Performs the specific calculation of this Calculator +* CLibPrimesCalculator::SetProgressCallback - Sets the progress callback function +* @param[in] pProgressCallback - The progress callback */ -void CLibPrimesCalculator::Calculate () +void CLibPrimesCalculator::SetProgressCallback (const LibPrimesProgressCallback pProgressCallback) { - CheckError ( libprimes_calculator_calculate (m_pHandle) ); + CheckError ( libprimes_calculator_setprogresscallback (m_pHandle, pProgressCallback) ); } /************************************************************************************************************************* @@ -121,7 +121,7 @@ CLibPrimesFactorizationCalculator::CLibPrimesFactorizationCalculator (LibPrimesH { } /** -* CLibPrimesFactorizationCalculator::GetPrimeFactors - Returns the prime factors of this number (with multiplicity) +* CLibPrimesFactorizationCalculator::GetPrimeFactors - Returns the prime factors of this number (without multiplicity) * @param[out] PrimeFactorsBuffer - The prime factors of this number */ void CLibPrimesFactorizationCalculator::GetPrimeFactors (std::vector & PrimeFactorsBuffer) @@ -132,18 +132,6 @@ void CLibPrimesFactorizationCalculator::GetPrimeFactors (std::vector & PrimeFactorsBuffer) -{ - bool resultAreEqual = 0; - CheckError ( libprimes_factorizationcalculator_checkprimefactors (m_pHandle, (LibPrimes_uint64)PrimeFactorsBuffer.size(), PrimeFactorsBuffer.data(), &resultAreEqual) ); - return resultAreEqual; -} /************************************************************************************************************************* Class CLibPrimesSieveCalculator @@ -168,28 +156,6 @@ void CLibPrimesSieveCalculator::GetPrimes (std::vector & Prime CheckError ( libprimes_sievecalculator_getprimes (m_pHandle, elementsNeededPrimes, &elementsWrittenPrimes, PrimesBuffer.data()) ); } -/** -* CLibPrimesWrapper::CreateFactorizationCalculator - Creates a new FactorizationCalculator instance -* @return New FactorizationCalculator instance -*/ -PLibPrimesFactorizationCalculator CLibPrimesWrapper::CreateFactorizationCalculator () -{ - LibPrimesHandle hInstance = nullptr; - CheckError (nullptr, libprimes_createfactorizationcalculator (&hInstance) ); - return std::make_shared (hInstance); -} - -/** -* CLibPrimesWrapper::CreateSieveCalculator - Creates a new SieveCalculator instance -* @return New SieveCalculator instance -*/ -PLibPrimesSieveCalculator CLibPrimesWrapper::CreateSieveCalculator () -{ - LibPrimesHandle hInstance = nullptr; - CheckError (nullptr, libprimes_createsievecalculator (&hInstance) ); - return std::make_shared (hInstance); -} - /** * CLibPrimesWrapper::ReleaseInstance - Releases the memory of an Instance * @param[in] pInstance - Instance Handle @@ -214,6 +180,28 @@ void CLibPrimesWrapper::GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_ CheckError (nullptr, libprimes_getlibraryversion (&nMajor, &nMinor, &nMicro) ); } +/** +* CLibPrimesWrapper::CreateFactorizationCalculator - Creates a new FactorizationCalculator instance +* @return New FactorizationCalculator instance +*/ +PLibPrimesFactorizationCalculator CLibPrimesWrapper::CreateFactorizationCalculator () +{ + LibPrimesHandle hInstance = nullptr; + CheckError (nullptr, libprimes_createfactorizationcalculator (&hInstance) ); + return std::make_shared (hInstance); +} + +/** +* CLibPrimesWrapper::CreateSieveCalculator - Creates a new SieveCalculator instance +* @return New SieveCalculator instance +*/ +PLibPrimesSieveCalculator CLibPrimesWrapper::CreateSieveCalculator () +{ + LibPrimesHandle hInstance = nullptr; + CheckError (nullptr, libprimes_createsievecalculator (&hInstance) ); + return std::make_shared (hInstance); +} + /** * CLibPrimesWrapper::SetJournal - Handles Library Journaling * @param[in] sFileName - Journal FileName diff --git a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.h b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.h index d6ebf0e3..ef110e11 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.h +++ b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.h @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated plain C Header file in order to allow an easy - use of Prime Numbers Interface + use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -41,7 +41,7 @@ extern "C" { * @param[out] pValue - The current value of this Calculator * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue(LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue); /** * Sets the value to be factorized @@ -50,31 +50,31 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calc * @param[in] nValue - The value to be factorized * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 nValue); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setvalue(LibPrimes_Calculator pCalculator, LibPrimes_uint64 nValue); /** -* Sets the progress callback function +* Performs the specific calculation of this Calculator * * @param[in] pCalculator - Calculator instance. -* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setprogresscallback (LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_calculate(LibPrimes_Calculator pCalculator); /** -* Performs the specific calculation of this Calculator +* Sets the progress callback function * * @param[in] pCalculator - Calculator instance. +* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_calculate (LibPrimes_Calculator pCalculator); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setprogresscallback(LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback); /************************************************************************************************************************* Class definition for FactorizationCalculator **************************************************************************************************************************/ /** -* Returns the prime factors of this number (with multiplicity) +* Returns the prime factors of this number (without multiplicity) * * @param[in] pFactorizationCalculator - FactorizationCalculator instance. * @param[in] nPrimeFactorsBufferSize - Number of elements in buffer @@ -82,18 +82,7 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_calculate (LibPrimes_Cal * @param[out] pPrimeFactorsBuffer - PrimeFactor buffer of The prime factors of this number * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_getprimefactors (LibPrimes_FactorizationCalculator pFactorizationCalculator, const LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); - -/** -* Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value -* -* @param[in] pFactorizationCalculator - FactorizationCalculator instance. -* @param[in] nPrimeFactorsBufferSize - Number of elements in buffer -* @param[in] pPrimeFactorsBuffer - PrimeFactor buffer of -* @param[out] pAreEqual - Do the prime factors decompose this calculator's value -* @return error code or 0 (success) -*/ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_checkprimefactors (LibPrimes_FactorizationCalculator pFactorizationCalculator, LibPrimes_uint64 nPrimeFactorsBufferSize, const sLibPrimesPrimeFactor * pPrimeFactorsBuffer, bool * pAreEqual); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_getprimefactors(LibPrimes_FactorizationCalculator pFactorizationCalculator, const LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); /************************************************************************************************************************* Class definition for SieveCalculator @@ -108,45 +97,45 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_checkprimef * @param[out] pPrimesBuffer - uint64 buffer of The primes lower or equal to the sieve's value * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_sievecalculator_getprimes (LibPrimes_SieveCalculator pSieveCalculator, const LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_sievecalculator_getprimes(LibPrimes_SieveCalculator pSieveCalculator, const LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer); /************************************************************************************************************************* Global functions **************************************************************************************************************************/ /** -* Creates a new FactorizationCalculator instance +* Releases the memory of an Instance * -* @param[out] pInstance - New FactorizationCalculator instance +* @param[in] pInstance - Instance Handle * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createfactorizationcalculator (LibPrimes_FactorizationCalculator * pInstance); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_releaseinstance(LibPrimes_BaseClass pInstance); /** -* Creates a new SieveCalculator instance +* retrieves the current version of the library. * -* @param[out] pInstance - New SieveCalculator instance +* @param[out] pMajor - returns the major version of the library +* @param[out] pMinor - returns the minor version of the library +* @param[out] pMicro - returns the micro version of the library * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createsievecalculator (LibPrimes_SieveCalculator * pInstance); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_getlibraryversion(LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro); /** -* Releases the memory of an Instance +* Creates a new FactorizationCalculator instance * -* @param[in] pInstance - Instance Handle +* @param[out] pInstance - New FactorizationCalculator instance * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_releaseinstance (LibPrimes_BaseClass pInstance); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createfactorizationcalculator(LibPrimes_FactorizationCalculator * pInstance); /** -* retrieves the current version of the library. +* Creates a new SieveCalculator instance * -* @param[out] pMajor - returns the major version of the library -* @param[out] pMinor - returns the minor version of the library -* @param[out] pMicro - returns the micro version of the library +* @param[out] pInstance - New SieveCalculator instance * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_getlibraryversion (LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createsievecalculator(LibPrimes_SieveCalculator * pInstance); /** * Handles Library Journaling @@ -154,7 +143,7 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_getlibraryversion (LibPrimes_uint32 * @param[in] pFileName - Journal FileName * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_setjournal (const char * pFileName); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_setjournal(const char * pFileName); } diff --git a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.hpp b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.hpp index 1999bf39..bebc5cc1 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.hpp +++ b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes.hpp @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated C++ Header file in order to allow an easy use - of Prime Numbers Interface + of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -162,15 +162,15 @@ class CLibPrimesCalculator : public CLibPrimesBaseClass { void SetValue (const LibPrimes_uint64 nValue); /** - * CLibPrimesCalculator::SetProgressCallback - Sets the progress callback function - * @param[in] pProgressCallback - The progress callback + * CLibPrimesCalculator::Calculate - Performs the specific calculation of this Calculator */ - void SetProgressCallback (const LibPrimesProgressCallback pProgressCallback); + void Calculate (); /** - * CLibPrimesCalculator::Calculate - Performs the specific calculation of this Calculator + * CLibPrimesCalculator::SetProgressCallback - Sets the progress callback function + * @param[in] pProgressCallback - The progress callback */ - void Calculate (); + void SetProgressCallback (const LibPrimesProgressCallback pProgressCallback); }; /************************************************************************************************************************* @@ -185,17 +185,10 @@ class CLibPrimesFactorizationCalculator : public CLibPrimesCalculator { CLibPrimesFactorizationCalculator (LibPrimesHandle pHandle); /** - * CLibPrimesFactorizationCalculator::GetPrimeFactors - Returns the prime factors of this number (with multiplicity) + * CLibPrimesFactorizationCalculator::GetPrimeFactors - Returns the prime factors of this number (without multiplicity) * @param[out] PrimeFactorsBuffer - The prime factors of this number */ void GetPrimeFactors (std::vector & PrimeFactorsBuffer); - - /** - * CLibPrimesFactorizationCalculator::CheckPrimeFactors - Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value - * @param[in] PrimeFactorsBuffer - - * @return Do the prime factors decompose this calculator's value - */ - bool CheckPrimeFactors (const CLibPrimesInputVector & PrimeFactorsBuffer); }; /************************************************************************************************************************* @@ -223,18 +216,6 @@ class CLibPrimesWrapper { public: static void CheckError(LibPrimesHandle handle, LibPrimesResult nResult); - /** - * CLibPrimesWrapper::CreateFactorizationCalculator - Creates a new FactorizationCalculator instance - * @return New FactorizationCalculator instance - */ - static PLibPrimesFactorizationCalculator CreateFactorizationCalculator (); - - /** - * CLibPrimesWrapper::CreateSieveCalculator - Creates a new SieveCalculator instance - * @return New SieveCalculator instance - */ - static PLibPrimesSieveCalculator CreateSieveCalculator (); - /** * CLibPrimesWrapper::ReleaseInstance - Releases the memory of an Instance * @param[in] pInstance - Instance Handle @@ -249,6 +230,18 @@ class CLibPrimesWrapper { */ static void GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_uint32 & nMinor, LibPrimes_uint32 & nMicro); + /** + * CLibPrimesWrapper::CreateFactorizationCalculator - Creates a new FactorizationCalculator instance + * @return New FactorizationCalculator instance + */ + static PLibPrimesFactorizationCalculator CreateFactorizationCalculator (); + + /** + * CLibPrimesWrapper::CreateSieveCalculator - Creates a new SieveCalculator instance + * @return New SieveCalculator instance + */ + static PLibPrimesSieveCalculator CreateSieveCalculator (); + /** * CLibPrimesWrapper::SetJournal - Handles Library Journaling * @param[in] sFileName - Journal FileName diff --git a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes_types.h b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes_types.h index 92b19290..2b14eea7 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes_types.h +++ b/Examples/Primes/LibPrimes_component/Bindings/Cpp/libprimes_types.h @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated plain C Header file with basic types in -order to allow an easy use of Prime Numbers Interface +order to allow an easy use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -61,7 +61,7 @@ typedef void * LibPrimesHandle; **************************************************************************************************************************/ #define LIBPRIMES_VERSION_MAJOR 1 -#define LIBPRIMES_VERSION_MINOR 3 +#define LIBPRIMES_VERSION_MINOR 2 #define LIBPRIMES_VERSION_MICRO 0 /************************************************************************************************************************* @@ -76,8 +76,9 @@ typedef void * LibPrimesHandle; #define LIBPRIMES_ERROR_GENERICEXCEPTION 5 #define LIBPRIMES_ERROR_COULDNOTLOADLIBRARY 6 #define LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT 7 -#define LIBPRIMES_ERROR_NORESULTAVAILABLE 8 -#define LIBPRIMES_ERROR_CALCULATIONABORTED 9 +#define LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION 8 +#define LIBPRIMES_ERROR_NORESULTAVAILABLE 9 +#define LIBPRIMES_ERROR_CALCULATIONABORTED 10 /************************************************************************************************************************* Declaration of handle classes diff --git a/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.h b/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.h index f97c0e33..b665434a 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.h +++ b/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.h @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated plain C Header file in order to allow an easy - use of Prime Numbers Interface + use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -42,28 +42,28 @@ typedef LibPrimesResult (*PLibPrimesCalculator_GetValuePtr) (LibPrimes_Calculato typedef LibPrimesResult (*PLibPrimesCalculator_SetValuePtr) (LibPrimes_Calculator pCalculator, LibPrimes_uint64 nValue); /** -* Sets the progress callback function +* Performs the specific calculation of this Calculator * * @param[in] pCalculator - Calculator instance. -* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) */ -typedef LibPrimesResult (*PLibPrimesCalculator_SetProgressCallbackPtr) (LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback); +typedef LibPrimesResult (*PLibPrimesCalculator_CalculatePtr) (LibPrimes_Calculator pCalculator); /** -* Performs the specific calculation of this Calculator +* Sets the progress callback function * * @param[in] pCalculator - Calculator instance. +* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) */ -typedef LibPrimesResult (*PLibPrimesCalculator_CalculatePtr) (LibPrimes_Calculator pCalculator); +typedef LibPrimesResult (*PLibPrimesCalculator_SetProgressCallbackPtr) (LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback); /************************************************************************************************************************* Class definition for FactorizationCalculator **************************************************************************************************************************/ /** -* Returns the prime factors of this number (with multiplicity) +* Returns the prime factors of this number (without multiplicity) * * @param[in] pFactorizationCalculator - FactorizationCalculator instance. * @param[in] nPrimeFactorsBufferSize - Number of elements in buffer @@ -73,17 +73,6 @@ typedef LibPrimesResult (*PLibPrimesCalculator_CalculatePtr) (LibPrimes_Calculat */ typedef LibPrimesResult (*PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) (LibPrimes_FactorizationCalculator pFactorizationCalculator, const LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); -/** -* Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value -* -* @param[in] pFactorizationCalculator - FactorizationCalculator instance. -* @param[in] nPrimeFactorsBufferSize - Number of elements in buffer -* @param[in] pPrimeFactorsBuffer - PrimeFactor buffer of -* @param[out] pAreEqual - Do the prime factors decompose this calculator's value -* @return error code or 0 (success) -*/ -typedef LibPrimesResult (*PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr) (LibPrimes_FactorizationCalculator pFactorizationCalculator, LibPrimes_uint64 nPrimeFactorsBufferSize, const sLibPrimesPrimeFactor * pPrimeFactorsBuffer, bool * pAreEqual); - /************************************************************************************************************************* Class definition for SieveCalculator **************************************************************************************************************************/ @@ -104,38 +93,38 @@ typedef LibPrimesResult (*PLibPrimesSieveCalculator_GetPrimesPtr) (LibPrimes_Sie **************************************************************************************************************************/ /** -* Creates a new FactorizationCalculator instance +* Releases the memory of an Instance * -* @param[out] pInstance - New FactorizationCalculator instance +* @param[in] pInstance - Instance Handle * @return error code or 0 (success) */ -typedef LibPrimesResult (*PLibPrimesCreateFactorizationCalculatorPtr) (LibPrimes_FactorizationCalculator * pInstance); +typedef LibPrimesResult (*PLibPrimesReleaseInstancePtr) (LibPrimes_BaseClass pInstance); /** -* Creates a new SieveCalculator instance +* retrieves the current version of the library. * -* @param[out] pInstance - New SieveCalculator instance +* @param[out] pMajor - returns the major version of the library +* @param[out] pMinor - returns the minor version of the library +* @param[out] pMicro - returns the micro version of the library * @return error code or 0 (success) */ -typedef LibPrimesResult (*PLibPrimesCreateSieveCalculatorPtr) (LibPrimes_SieveCalculator * pInstance); +typedef LibPrimesResult (*PLibPrimesGetLibraryVersionPtr) (LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro); /** -* Releases the memory of an Instance +* Creates a new FactorizationCalculator instance * -* @param[in] pInstance - Instance Handle +* @param[out] pInstance - New FactorizationCalculator instance * @return error code or 0 (success) */ -typedef LibPrimesResult (*PLibPrimesReleaseInstancePtr) (LibPrimes_BaseClass pInstance); +typedef LibPrimesResult (*PLibPrimesCreateFactorizationCalculatorPtr) (LibPrimes_FactorizationCalculator * pInstance); /** -* retrieves the current version of the library. +* Creates a new SieveCalculator instance * -* @param[out] pMajor - returns the major version of the library -* @param[out] pMinor - returns the minor version of the library -* @param[out] pMicro - returns the micro version of the library +* @param[out] pInstance - New SieveCalculator instance * @return error code or 0 (success) */ -typedef LibPrimesResult (*PLibPrimesGetLibraryVersionPtr) (LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro); +typedef LibPrimesResult (*PLibPrimesCreateSieveCalculatorPtr) (LibPrimes_SieveCalculator * pInstance); /** * Handles Library Journaling @@ -153,15 +142,14 @@ typedef struct { void * m_LibraryHandle; PLibPrimesCalculator_GetValuePtr m_Calculator_GetValue; PLibPrimesCalculator_SetValuePtr m_Calculator_SetValue; - PLibPrimesCalculator_SetProgressCallbackPtr m_Calculator_SetProgressCallback; PLibPrimesCalculator_CalculatePtr m_Calculator_Calculate; + PLibPrimesCalculator_SetProgressCallbackPtr m_Calculator_SetProgressCallback; PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr m_FactorizationCalculator_GetPrimeFactors; - PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr m_FactorizationCalculator_CheckPrimeFactors; PLibPrimesSieveCalculator_GetPrimesPtr m_SieveCalculator_GetPrimes; - PLibPrimesCreateFactorizationCalculatorPtr m_CreateFactorizationCalculator; - PLibPrimesCreateSieveCalculatorPtr m_CreateSieveCalculator; PLibPrimesReleaseInstancePtr m_ReleaseInstance; PLibPrimesGetLibraryVersionPtr m_GetLibraryVersion; + PLibPrimesCreateFactorizationCalculatorPtr m_CreateFactorizationCalculator; + PLibPrimesCreateSieveCalculatorPtr m_CreateSieveCalculator; PLibPrimesSetJournalPtr m_SetJournal; } sLibPrimesDynamicWrapperTable; diff --git a/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.hpp b/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.hpp index 26ce4c9b..8fde3a7f 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.hpp +++ b/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_dynamic.hpp @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated C++ Header file in order to allow an easy - use of Prime Numbers Interface + use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -137,6 +137,8 @@ class CLibPrimesWrapper { { CheckError (nullptr, initWrapperTable (&m_WrapperTable)); CheckError (nullptr, loadWrapperTable (&m_WrapperTable, sFileName.c_str ())); + + CheckError(nullptr, checkBinaryVersion()); } static PLibPrimesWrapper loadLibrary (const std::string &sFileName) @@ -156,15 +158,24 @@ class CLibPrimesWrapper { } - PLibPrimesFactorizationCalculator CreateFactorizationCalculator (); - PLibPrimesSieveCalculator CreateSieveCalculator (); - void ReleaseInstance (CLibPrimesBaseClass * pInstance); - void GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_uint32 & nMinor, LibPrimes_uint32 & nMicro); - void SetJournal (const std::string & sFileName); + inline void ReleaseInstance (CLibPrimesBaseClass * pInstance); + inline void GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_uint32 & nMinor, LibPrimes_uint32 & nMicro); + inline PLibPrimesFactorizationCalculator CreateFactorizationCalculator (); + inline PLibPrimesSieveCalculator CreateSieveCalculator (); + inline void SetJournal (const std::string & sFileName); private: sLibPrimesDynamicWrapperTable m_WrapperTable; + LibPrimesResult checkBinaryVersion() + { + LibPrimes_uint32 nMajor, nMinor, nMicro; + GetLibraryVersion(nMajor, nMinor, nMicro); + if ( (nMajor != LIBPRIMES_VERSION_MAJOR) || (nMinor < LIBPRIMES_VERSION_MINOR) ) { + return LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION; + } + return LIBPRIMES_SUCCESS; + } LibPrimesResult initWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable); LibPrimesResult releaseWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable); LibPrimesResult loadWrapperTable (sLibPrimesDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName); @@ -236,43 +247,10 @@ class CLibPrimesCalculator : public CLibPrimesBaseClass { { } - - /** - * CLibPrimesCalculator::GetValue - Returns the current value of this Calculator - * @return The current value of this Calculator - */ - LibPrimes_uint64 GetValue () - { - LibPrimes_uint64 resultValue = 0; - CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_GetValue (m_pHandle, &resultValue) ); - return resultValue; - } - - /** - * CLibPrimesCalculator::SetValue - Sets the value to be factorized - * @param[in] nValue - The value to be factorized - */ - void SetValue (const LibPrimes_uint64 nValue) - { - CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_SetValue (m_pHandle, nValue) ); - } - - /** - * CLibPrimesCalculator::SetProgressCallback - Sets the progress callback function - * @param[in] pProgressCallback - The progress callback - */ - void SetProgressCallback (const LibPrimesProgressCallback pProgressCallback) - { - CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_SetProgressCallback (m_pHandle, pProgressCallback) ); - } - - /** - * CLibPrimesCalculator::Calculate - Performs the specific calculation of this Calculator - */ - void Calculate () - { - CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_Calculate (m_pHandle) ); - } + inline LibPrimes_uint64 GetValue (); + inline void SetValue (const LibPrimes_uint64 nValue); + inline void Calculate (); + inline void SetProgressCallback (const LibPrimesProgressCallback pProgressCallback); }; /************************************************************************************************************************* @@ -289,31 +267,7 @@ class CLibPrimesFactorizationCalculator : public CLibPrimesCalculator { { } - - /** - * CLibPrimesFactorizationCalculator::GetPrimeFactors - Returns the prime factors of this number (with multiplicity) - * @param[out] PrimeFactorsBuffer - The prime factors of this number - */ - void GetPrimeFactors (std::vector & PrimeFactorsBuffer) - { - LibPrimes_uint64 elementsNeededPrimeFactors = 0; - LibPrimes_uint64 elementsWrittenPrimeFactors = 0; - CheckError ( m_pWrapper->m_WrapperTable.m_FactorizationCalculator_GetPrimeFactors (m_pHandle, 0, &elementsNeededPrimeFactors, nullptr) ); - PrimeFactorsBuffer.resize(elementsNeededPrimeFactors); - CheckError ( m_pWrapper->m_WrapperTable.m_FactorizationCalculator_GetPrimeFactors (m_pHandle, elementsNeededPrimeFactors, &elementsWrittenPrimeFactors, PrimeFactorsBuffer.data()) ); - } - - /** - * CLibPrimesFactorizationCalculator::CheckPrimeFactors - Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value - * @param[in] PrimeFactorsBuffer - - * @return Do the prime factors decompose this calculator's value - */ - bool CheckPrimeFactors (const CLibPrimesInputVector & PrimeFactorsBuffer) - { - bool resultAreEqual = 0; - CheckError ( m_pWrapper->m_WrapperTable.m_FactorizationCalculator_CheckPrimeFactors (m_pHandle, (LibPrimes_uint64)PrimeFactorsBuffer.size(), PrimeFactorsBuffer.data(), &resultAreEqual) ); - return resultAreEqual; - } + inline void GetPrimeFactors (std::vector & PrimeFactorsBuffer); }; /************************************************************************************************************************* @@ -330,20 +284,32 @@ class CLibPrimesSieveCalculator : public CLibPrimesCalculator { { } + inline void GetPrimes (std::vector & PrimesBuffer); +}; /** - * CLibPrimesSieveCalculator::GetPrimes - Returns all prime numbers lower or equal to the sieve's value - * @param[out] PrimesBuffer - The primes lower or equal to the sieve's value + * CLibPrimesWrapper::ReleaseInstance - Releases the memory of an Instance + * @param[in] pInstance - Instance Handle */ - void GetPrimes (std::vector & PrimesBuffer) + inline void CLibPrimesWrapper::ReleaseInstance (CLibPrimesBaseClass * pInstance) { - LibPrimes_uint64 elementsNeededPrimes = 0; - LibPrimes_uint64 elementsWrittenPrimes = 0; - CheckError ( m_pWrapper->m_WrapperTable.m_SieveCalculator_GetPrimes (m_pHandle, 0, &elementsNeededPrimes, nullptr) ); - PrimesBuffer.resize(elementsNeededPrimes); - CheckError ( m_pWrapper->m_WrapperTable.m_SieveCalculator_GetPrimes (m_pHandle, elementsNeededPrimes, &elementsWrittenPrimes, PrimesBuffer.data()) ); + LibPrimesHandle hInstance = nullptr; + if (pInstance != nullptr) { + hInstance = pInstance->GetHandle (); + }; + CheckError (nullptr, m_WrapperTable.m_ReleaseInstance (hInstance) ); + } + + /** + * CLibPrimesWrapper::GetLibraryVersion - retrieves the current version of the library. + * @param[out] nMajor - returns the major version of the library + * @param[out] nMinor - returns the minor version of the library + * @param[out] nMicro - returns the micro version of the library + */ + inline void CLibPrimesWrapper::GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_uint32 & nMinor, LibPrimes_uint32 & nMicro) + { + CheckError (nullptr, m_WrapperTable.m_GetLibraryVersion (&nMajor, &nMinor, &nMicro) ); } -}; /** * CLibPrimesWrapper::CreateFactorizationCalculator - Creates a new FactorizationCalculator instance @@ -367,30 +333,6 @@ class CLibPrimesSieveCalculator : public CLibPrimesCalculator { return std::make_shared (this, hInstance); } - /** - * CLibPrimesWrapper::ReleaseInstance - Releases the memory of an Instance - * @param[in] pInstance - Instance Handle - */ - inline void CLibPrimesWrapper::ReleaseInstance (CLibPrimesBaseClass * pInstance) - { - LibPrimesHandle hInstance = nullptr; - if (pInstance != nullptr) { - hInstance = pInstance->GetHandle (); - }; - CheckError (nullptr, m_WrapperTable.m_ReleaseInstance (hInstance) ); - } - - /** - * CLibPrimesWrapper::GetLibraryVersion - retrieves the current version of the library. - * @param[out] nMajor - returns the major version of the library - * @param[out] nMinor - returns the minor version of the library - * @param[out] nMicro - returns the micro version of the library - */ - inline void CLibPrimesWrapper::GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_uint32 & nMinor, LibPrimes_uint32 & nMicro) - { - CheckError (nullptr, m_WrapperTable.m_GetLibraryVersion (&nMajor, &nMinor, &nMicro) ); - } - /** * CLibPrimesWrapper::SetJournal - Handles Library Journaling * @param[in] sFileName - Journal FileName @@ -408,15 +350,14 @@ class CLibPrimesSieveCalculator : public CLibPrimesCalculator { pWrapperTable->m_LibraryHandle = nullptr; pWrapperTable->m_Calculator_GetValue = nullptr; pWrapperTable->m_Calculator_SetValue = nullptr; - pWrapperTable->m_Calculator_SetProgressCallback = nullptr; pWrapperTable->m_Calculator_Calculate = nullptr; + pWrapperTable->m_Calculator_SetProgressCallback = nullptr; pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = nullptr; - pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors = nullptr; pWrapperTable->m_SieveCalculator_GetPrimes = nullptr; - pWrapperTable->m_CreateFactorizationCalculator = nullptr; - pWrapperTable->m_CreateSieveCalculator = nullptr; pWrapperTable->m_ReleaseInstance = nullptr; pWrapperTable->m_GetLibraryVersion = nullptr; + pWrapperTable->m_CreateFactorizationCalculator = nullptr; + pWrapperTable->m_CreateSieveCalculator = nullptr; pWrapperTable->m_SetJournal = nullptr; return LIBPRIMES_SUCCESS; @@ -476,15 +417,6 @@ class CLibPrimesSieveCalculator : public CLibPrimesCalculator { if (pWrapperTable->m_Calculator_SetValue == nullptr) return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - #ifdef WIN32 - pWrapperTable->m_Calculator_SetProgressCallback = (PLibPrimesCalculator_SetProgressCallbackPtr) GetProcAddress (hLibrary, "libprimes_calculator_setprogresscallback"); - #else // WIN32 - pWrapperTable->m_Calculator_SetProgressCallback = (PLibPrimesCalculator_SetProgressCallbackPtr) dlsym (hLibrary, "libprimes_calculator_setprogresscallback"); - dlerror(); - #endif // WIN32 - if (pWrapperTable->m_Calculator_SetProgressCallback == nullptr) - return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; - #ifdef WIN32 pWrapperTable->m_Calculator_Calculate = (PLibPrimesCalculator_CalculatePtr) GetProcAddress (hLibrary, "libprimes_calculator_calculate"); #else // WIN32 @@ -495,21 +427,21 @@ class CLibPrimesSieveCalculator : public CLibPrimesCalculator { return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 - pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = (PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) GetProcAddress (hLibrary, "libprimes_factorizationcalculator_getprimefactors"); + pWrapperTable->m_Calculator_SetProgressCallback = (PLibPrimesCalculator_SetProgressCallbackPtr) GetProcAddress (hLibrary, "libprimes_calculator_setprogresscallback"); #else // WIN32 - pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = (PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) dlsym (hLibrary, "libprimes_factorizationcalculator_getprimefactors"); + pWrapperTable->m_Calculator_SetProgressCallback = (PLibPrimesCalculator_SetProgressCallbackPtr) dlsym (hLibrary, "libprimes_calculator_setprogresscallback"); dlerror(); #endif // WIN32 - if (pWrapperTable->m_FactorizationCalculator_GetPrimeFactors == nullptr) + if (pWrapperTable->m_Calculator_SetProgressCallback == nullptr) return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 - pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors = (PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr) GetProcAddress (hLibrary, "libprimes_factorizationcalculator_checkprimefactors"); + pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = (PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) GetProcAddress (hLibrary, "libprimes_factorizationcalculator_getprimefactors"); #else // WIN32 - pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors = (PLibPrimesFactorizationCalculator_CheckPrimeFactorsPtr) dlsym (hLibrary, "libprimes_factorizationcalculator_checkprimefactors"); + pWrapperTable->m_FactorizationCalculator_GetPrimeFactors = (PLibPrimesFactorizationCalculator_GetPrimeFactorsPtr) dlsym (hLibrary, "libprimes_factorizationcalculator_getprimefactors"); dlerror(); #endif // WIN32 - if (pWrapperTable->m_FactorizationCalculator_CheckPrimeFactors == nullptr) + if (pWrapperTable->m_FactorizationCalculator_GetPrimeFactors == nullptr) return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 @@ -522,39 +454,39 @@ class CLibPrimesSieveCalculator : public CLibPrimesCalculator { return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 - pWrapperTable->m_CreateFactorizationCalculator = (PLibPrimesCreateFactorizationCalculatorPtr) GetProcAddress (hLibrary, "libprimes_createfactorizationcalculator"); + pWrapperTable->m_ReleaseInstance = (PLibPrimesReleaseInstancePtr) GetProcAddress (hLibrary, "libprimes_releaseinstance"); #else // WIN32 - pWrapperTable->m_CreateFactorizationCalculator = (PLibPrimesCreateFactorizationCalculatorPtr) dlsym (hLibrary, "libprimes_createfactorizationcalculator"); + pWrapperTable->m_ReleaseInstance = (PLibPrimesReleaseInstancePtr) dlsym (hLibrary, "libprimes_releaseinstance"); dlerror(); #endif // WIN32 - if (pWrapperTable->m_CreateFactorizationCalculator == nullptr) + if (pWrapperTable->m_ReleaseInstance == nullptr) return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 - pWrapperTable->m_CreateSieveCalculator = (PLibPrimesCreateSieveCalculatorPtr) GetProcAddress (hLibrary, "libprimes_createsievecalculator"); + pWrapperTable->m_GetLibraryVersion = (PLibPrimesGetLibraryVersionPtr) GetProcAddress (hLibrary, "libprimes_getlibraryversion"); #else // WIN32 - pWrapperTable->m_CreateSieveCalculator = (PLibPrimesCreateSieveCalculatorPtr) dlsym (hLibrary, "libprimes_createsievecalculator"); + pWrapperTable->m_GetLibraryVersion = (PLibPrimesGetLibraryVersionPtr) dlsym (hLibrary, "libprimes_getlibraryversion"); dlerror(); #endif // WIN32 - if (pWrapperTable->m_CreateSieveCalculator == nullptr) + if (pWrapperTable->m_GetLibraryVersion == nullptr) return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 - pWrapperTable->m_ReleaseInstance = (PLibPrimesReleaseInstancePtr) GetProcAddress (hLibrary, "libprimes_releaseinstance"); + pWrapperTable->m_CreateFactorizationCalculator = (PLibPrimesCreateFactorizationCalculatorPtr) GetProcAddress (hLibrary, "libprimes_createfactorizationcalculator"); #else // WIN32 - pWrapperTable->m_ReleaseInstance = (PLibPrimesReleaseInstancePtr) dlsym (hLibrary, "libprimes_releaseinstance"); + pWrapperTable->m_CreateFactorizationCalculator = (PLibPrimesCreateFactorizationCalculatorPtr) dlsym (hLibrary, "libprimes_createfactorizationcalculator"); dlerror(); #endif // WIN32 - if (pWrapperTable->m_ReleaseInstance == nullptr) + if (pWrapperTable->m_CreateFactorizationCalculator == nullptr) return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 - pWrapperTable->m_GetLibraryVersion = (PLibPrimesGetLibraryVersionPtr) GetProcAddress (hLibrary, "libprimes_getlibraryversion"); + pWrapperTable->m_CreateSieveCalculator = (PLibPrimesCreateSieveCalculatorPtr) GetProcAddress (hLibrary, "libprimes_createsievecalculator"); #else // WIN32 - pWrapperTable->m_GetLibraryVersion = (PLibPrimesGetLibraryVersionPtr) dlsym (hLibrary, "libprimes_getlibraryversion"); + pWrapperTable->m_CreateSieveCalculator = (PLibPrimesCreateSieveCalculatorPtr) dlsym (hLibrary, "libprimes_createsievecalculator"); dlerror(); #endif // WIN32 - if (pWrapperTable->m_GetLibraryVersion == nullptr) + if (pWrapperTable->m_CreateSieveCalculator == nullptr) return LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT; #ifdef WIN32 @@ -569,6 +501,59 @@ class CLibPrimesSieveCalculator : public CLibPrimesCalculator { pWrapperTable->m_LibraryHandle = hLibrary; return LIBPRIMES_SUCCESS; } + + + /** + * Method definitions for class CLibPrimesCalculator + */ + + LibPrimes_uint64 CLibPrimesCalculator::GetValue () + { + LibPrimes_uint64 resultValue = 0; + CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_GetValue (m_pHandle, &resultValue) ); + return resultValue; + } + + void CLibPrimesCalculator::SetValue (const LibPrimes_uint64 nValue) + { + CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_SetValue (m_pHandle, nValue) ); + } + + void CLibPrimesCalculator::Calculate () + { + CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_Calculate (m_pHandle) ); + } + + void CLibPrimesCalculator::SetProgressCallback (const LibPrimesProgressCallback pProgressCallback) + { + CheckError ( m_pWrapper->m_WrapperTable.m_Calculator_SetProgressCallback (m_pHandle, pProgressCallback) ); + } + + /** + * Method definitions for class CLibPrimesFactorizationCalculator + */ + + void CLibPrimesFactorizationCalculator::GetPrimeFactors (std::vector & PrimeFactorsBuffer) + { + LibPrimes_uint64 elementsNeededPrimeFactors = 0; + LibPrimes_uint64 elementsWrittenPrimeFactors = 0; + CheckError ( m_pWrapper->m_WrapperTable.m_FactorizationCalculator_GetPrimeFactors (m_pHandle, 0, &elementsNeededPrimeFactors, nullptr) ); + PrimeFactorsBuffer.resize(elementsNeededPrimeFactors); + CheckError ( m_pWrapper->m_WrapperTable.m_FactorizationCalculator_GetPrimeFactors (m_pHandle, elementsNeededPrimeFactors, &elementsWrittenPrimeFactors, PrimeFactorsBuffer.data()) ); + } + + /** + * Method definitions for class CLibPrimesSieveCalculator + */ + + void CLibPrimesSieveCalculator::GetPrimes (std::vector & PrimesBuffer) + { + LibPrimes_uint64 elementsNeededPrimes = 0; + LibPrimes_uint64 elementsWrittenPrimes = 0; + CheckError ( m_pWrapper->m_WrapperTable.m_SieveCalculator_GetPrimes (m_pHandle, 0, &elementsNeededPrimes, nullptr) ); + PrimesBuffer.resize(elementsNeededPrimes); + CheckError ( m_pWrapper->m_WrapperTable.m_SieveCalculator_GetPrimes (m_pHandle, elementsNeededPrimes, &elementsWrittenPrimes, PrimesBuffer.data()) ); + } } // namespace LibPrimes diff --git a/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_types.h b/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_types.h index 92b19290..2b14eea7 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_types.h +++ b/Examples/Primes/LibPrimes_component/Bindings/CppDynamic/libprimes_types.h @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated plain C Header file with basic types in -order to allow an easy use of Prime Numbers Interface +order to allow an easy use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -61,7 +61,7 @@ typedef void * LibPrimesHandle; **************************************************************************************************************************/ #define LIBPRIMES_VERSION_MAJOR 1 -#define LIBPRIMES_VERSION_MINOR 3 +#define LIBPRIMES_VERSION_MINOR 2 #define LIBPRIMES_VERSION_MICRO 0 /************************************************************************************************************************* @@ -76,8 +76,9 @@ typedef void * LibPrimesHandle; #define LIBPRIMES_ERROR_GENERICEXCEPTION 5 #define LIBPRIMES_ERROR_COULDNOTLOADLIBRARY 6 #define LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT 7 -#define LIBPRIMES_ERROR_NORESULTAVAILABLE 8 -#define LIBPRIMES_ERROR_CALCULATIONABORTED 9 +#define LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION 8 +#define LIBPRIMES_ERROR_NORESULTAVAILABLE 9 +#define LIBPRIMES_ERROR_CALCULATIONABORTED 10 /************************************************************************************************************************* Declaration of handle classes diff --git a/Examples/Primes/LibPrimes_component/Bindings/Pascal/Unit_LibPrimes.pas b/Examples/Primes/LibPrimes_component/Bindings/Pascal/Unit_LibPrimes.pas index 84befe46..ab507961 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/Pascal/Unit_LibPrimes.pas +++ b/Examples/Primes/LibPrimes_component/Bindings/Pascal/Unit_LibPrimes.pas @@ -1,16 +1,16 @@ {$IFDEF FPC}{$MODE DELPHI}{$ENDIF} (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated Pascal Header file in order to allow an easy - use of Prime Numbers Interface + use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 *) @@ -34,7 +34,7 @@ interface const LIBPRIMES_VERSION_MAJOR = 1; - LIBPRIMES_VERSION_MINOR = 3; + LIBPRIMES_VERSION_MINOR = 2; LIBPRIMES_VERSION_MICRO = 0; @@ -62,8 +62,9 @@ interface LIBPRIMES_ERROR_GENERICEXCEPTION = 5; LIBPRIMES_ERROR_COULDNOTLOADLIBRARY = 6; LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT = 7; - LIBPRIMES_ERROR_NORESULTAVAILABLE = 8; - LIBPRIMES_ERROR_CALCULATIONABORTED = 9; + LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION = 8; + LIBPRIMES_ERROR_NORESULTAVAILABLE = 9; + LIBPRIMES_ERROR_CALCULATIONABORTED = 10; (************************************************************************************************************************* Declaration of structs @@ -88,7 +89,9 @@ interface Declaration of function types **************************************************************************************************************************) - PLibPrimes_ProgressCallback = function(const fProgressPercentage: Single; out pShouldAbort: Cardinal): Integer; +type + + PLibPrimes_ProgressCallback = function(const fProgressPercentage: Single; out pShouldAbort: Byte): Integer; cdecl; (************************************************************************************************************************* Declaration of handle classes @@ -125,21 +128,21 @@ TLibPrimesSieveCalculator = class; TLibPrimesCalculator_SetValueFunc = function (pCalculator: TLibPrimesHandle; const nValue: QWord): TLibPrimesResult; cdecl; (** - * Sets the progress callback function + * Performs the specific calculation of this Calculator * * @param[in] pCalculator - Calculator instance. - * @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) *) - TLibPrimesCalculator_SetProgressCallbackFunc = function (pCalculator: TLibPrimesHandle; const pProgressCallback: PLibPrimes_ProgressCallback): TLibPrimesResult; cdecl; + TLibPrimesCalculator_CalculateFunc = function (pCalculator: TLibPrimesHandle): TLibPrimesResult; cdecl; (** - * Performs the specific calculation of this Calculator + * Sets the progress callback function * * @param[in] pCalculator - Calculator instance. + * @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) *) - TLibPrimesCalculator_CalculateFunc = function (pCalculator: TLibPrimesHandle): TLibPrimesResult; cdecl; + TLibPrimesCalculator_SetProgressCallbackFunc = function (pCalculator: TLibPrimesHandle; const pProgressCallback: PLibPrimes_ProgressCallback): TLibPrimesResult; cdecl; (************************************************************************************************************************* @@ -147,7 +150,7 @@ TLibPrimesSieveCalculator = class; **************************************************************************************************************************) (** - * Returns the prime factors of this number (with multiplicity) + * Returns the prime factors of this number (without multiplicity) * * @param[in] pFactorizationCalculator - FactorizationCalculator instance. * @param[in] nPrimeFactorsCount - Number of elements in buffer @@ -157,17 +160,6 @@ TLibPrimesSieveCalculator = class; *) TLibPrimesFactorizationCalculator_GetPrimeFactorsFunc = function (pFactorizationCalculator: TLibPrimesHandle; const nPrimeFactorsCount: QWord; out pPrimeFactorsNeededCount: QWord; pPrimeFactorsBuffer: PLibPrimesPrimeFactor): TLibPrimesResult; cdecl; - (** - * Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value - * - * @param[in] pFactorizationCalculator - FactorizationCalculator instance. - * @param[in] nPrimeFactorsCount - Number of elements in buffer - * @param[in] pPrimeFactorsBuffer - PrimeFactor buffer of - * @param[out] pAreEqual - Do the prime factors decompose this calculator's value - * @return error code or 0 (success) - *) - TLibPrimesFactorizationCalculator_CheckPrimeFactorsFunc = function (pFactorizationCalculator: TLibPrimesHandle; const nPrimeFactorsCount: QWord; const pPrimeFactorsBuffer: PLibPrimesPrimeFactor; out pAreEqual: Cardinal): TLibPrimesResult; cdecl; - (************************************************************************************************************************* Function type definitions for SieveCalculator @@ -189,38 +181,38 @@ TLibPrimesSieveCalculator = class; **************************************************************************************************************************) (** - * Creates a new FactorizationCalculator instance + * Releases the memory of an Instance * - * @param[out] pInstance - New FactorizationCalculator instance + * @param[in] pInstance - Instance Handle * @return error code or 0 (success) *) - TLibPrimesCreateFactorizationCalculatorFunc = function (out pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; + TLibPrimesReleaseInstanceFunc = function (const pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; (** - * Creates a new SieveCalculator instance + * retrieves the current version of the library. * - * @param[out] pInstance - New SieveCalculator instance + * @param[out] pMajor - returns the major version of the library + * @param[out] pMinor - returns the minor version of the library + * @param[out] pMicro - returns the micro version of the library * @return error code or 0 (success) *) - TLibPrimesCreateSieveCalculatorFunc = function (out pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; + TLibPrimesGetLibraryVersionFunc = function (out pMajor: Cardinal; out pMinor: Cardinal; out pMicro: Cardinal): TLibPrimesResult; cdecl; (** - * Releases the memory of an Instance + * Creates a new FactorizationCalculator instance * - * @param[in] pInstance - Instance Handle + * @param[out] pInstance - New FactorizationCalculator instance * @return error code or 0 (success) *) - TLibPrimesReleaseInstanceFunc = function (const pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; + TLibPrimesCreateFactorizationCalculatorFunc = function (out pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; (** - * retrieves the current version of the library. + * Creates a new SieveCalculator instance * - * @param[out] pMajor - returns the major version of the library - * @param[out] pMinor - returns the minor version of the library - * @param[out] pMicro - returns the micro version of the library + * @param[out] pInstance - New SieveCalculator instance * @return error code or 0 (success) *) - TLibPrimesGetLibraryVersionFunc = function (out pMajor: Cardinal; out pMinor: Cardinal; out pMicro: Cardinal): TLibPrimesResult; cdecl; + TLibPrimesCreateSieveCalculatorFunc = function (out pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; (** * Handles Library Journaling @@ -270,8 +262,8 @@ TLibPrimesCalculator = class (TLibPrimesBaseClass) destructor Destroy; override; function GetValue(): QWord; procedure SetValue(const AValue: QWord); - procedure SetProgressCallback(const AProgressCallback: PLibPrimes_ProgressCallback); procedure Calculate(); + procedure SetProgressCallback(const AProgressCallback: PLibPrimes_ProgressCallback); end; @@ -285,7 +277,6 @@ TLibPrimesFactorizationCalculator = class (TLibPrimesCalculator) constructor Create (AWrapper: TLibPrimesWrapper; AHandle: TLibPrimesHandle); destructor Destroy; override; procedure GetPrimeFactors(out APrimeFactors: ArrayOfLibPrimesPrimeFactor); - function CheckPrimeFactors(const APrimeFactors: ArrayOfLibPrimesPrimeFactor): Boolean; end; @@ -310,15 +301,14 @@ TLibPrimesWrapper = class (TObject) FModule: HMODULE; FLibPrimesCalculator_GetValueFunc: TLibPrimesCalculator_GetValueFunc; FLibPrimesCalculator_SetValueFunc: TLibPrimesCalculator_SetValueFunc; - FLibPrimesCalculator_SetProgressCallbackFunc: TLibPrimesCalculator_SetProgressCallbackFunc; FLibPrimesCalculator_CalculateFunc: TLibPrimesCalculator_CalculateFunc; + FLibPrimesCalculator_SetProgressCallbackFunc: TLibPrimesCalculator_SetProgressCallbackFunc; FLibPrimesFactorizationCalculator_GetPrimeFactorsFunc: TLibPrimesFactorizationCalculator_GetPrimeFactorsFunc; - FLibPrimesFactorizationCalculator_CheckPrimeFactorsFunc: TLibPrimesFactorizationCalculator_CheckPrimeFactorsFunc; FLibPrimesSieveCalculator_GetPrimesFunc: TLibPrimesSieveCalculator_GetPrimesFunc; - FLibPrimesCreateFactorizationCalculatorFunc: TLibPrimesCreateFactorizationCalculatorFunc; - FLibPrimesCreateSieveCalculatorFunc: TLibPrimesCreateSieveCalculatorFunc; FLibPrimesReleaseInstanceFunc: TLibPrimesReleaseInstanceFunc; FLibPrimesGetLibraryVersionFunc: TLibPrimesGetLibraryVersionFunc; + FLibPrimesCreateFactorizationCalculatorFunc: TLibPrimesCreateFactorizationCalculatorFunc; + FLibPrimesCreateSieveCalculatorFunc: TLibPrimesCreateSieveCalculatorFunc; FLibPrimesSetJournalFunc: TLibPrimesSetJournalFunc; {$IFDEF MSWINDOWS} @@ -327,27 +317,28 @@ TLibPrimesWrapper = class (TObject) function LoadFunction (AFunctionName: AnsiString; FailIfNotExistent: Boolean = True): Pointer; {$ENDIF MSWINDOWS} + procedure checkBinaryVersion(); + protected property LibPrimesCalculator_GetValueFunc: TLibPrimesCalculator_GetValueFunc read FLibPrimesCalculator_GetValueFunc; property LibPrimesCalculator_SetValueFunc: TLibPrimesCalculator_SetValueFunc read FLibPrimesCalculator_SetValueFunc; - property LibPrimesCalculator_SetProgressCallbackFunc: TLibPrimesCalculator_SetProgressCallbackFunc read FLibPrimesCalculator_SetProgressCallbackFunc; property LibPrimesCalculator_CalculateFunc: TLibPrimesCalculator_CalculateFunc read FLibPrimesCalculator_CalculateFunc; + property LibPrimesCalculator_SetProgressCallbackFunc: TLibPrimesCalculator_SetProgressCallbackFunc read FLibPrimesCalculator_SetProgressCallbackFunc; property LibPrimesFactorizationCalculator_GetPrimeFactorsFunc: TLibPrimesFactorizationCalculator_GetPrimeFactorsFunc read FLibPrimesFactorizationCalculator_GetPrimeFactorsFunc; - property LibPrimesFactorizationCalculator_CheckPrimeFactorsFunc: TLibPrimesFactorizationCalculator_CheckPrimeFactorsFunc read FLibPrimesFactorizationCalculator_CheckPrimeFactorsFunc; property LibPrimesSieveCalculator_GetPrimesFunc: TLibPrimesSieveCalculator_GetPrimesFunc read FLibPrimesSieveCalculator_GetPrimesFunc; - property LibPrimesCreateFactorizationCalculatorFunc: TLibPrimesCreateFactorizationCalculatorFunc read FLibPrimesCreateFactorizationCalculatorFunc; - property LibPrimesCreateSieveCalculatorFunc: TLibPrimesCreateSieveCalculatorFunc read FLibPrimesCreateSieveCalculatorFunc; property LibPrimesReleaseInstanceFunc: TLibPrimesReleaseInstanceFunc read FLibPrimesReleaseInstanceFunc; property LibPrimesGetLibraryVersionFunc: TLibPrimesGetLibraryVersionFunc read FLibPrimesGetLibraryVersionFunc; + property LibPrimesCreateFactorizationCalculatorFunc: TLibPrimesCreateFactorizationCalculatorFunc read FLibPrimesCreateFactorizationCalculatorFunc; + property LibPrimesCreateSieveCalculatorFunc: TLibPrimesCreateSieveCalculatorFunc read FLibPrimesCreateSieveCalculatorFunc; property LibPrimesSetJournalFunc: TLibPrimesSetJournalFunc read FLibPrimesSetJournalFunc; procedure CheckError (AInstance: TLibPrimesBaseClass; AErrorCode: TLibPrimesResult); public constructor Create (ADLLName: String); destructor Destroy; override; - function CreateFactorizationCalculator(): TLibPrimesFactorizationCalculator; - function CreateSieveCalculator(): TLibPrimesSieveCalculator; procedure ReleaseInstance(const AInstance: TLibPrimesBaseClass); procedure GetLibraryVersion(out AMajor: Cardinal; out AMinor: Cardinal; out AMicro: Cardinal); + function CreateFactorizationCalculator(): TLibPrimesFactorizationCalculator; + function CreateSieveCalculator(): TLibPrimesSieveCalculator; procedure SetJournal(const AFileName: String); end; @@ -372,13 +363,14 @@ implementation LIBPRIMES_ERROR_GENERICEXCEPTION: ADescription := 'a generic exception occurred'; LIBPRIMES_ERROR_COULDNOTLOADLIBRARY: ADescription := 'the library could not be loaded'; LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT: ADescription := 'a required exported symbol could not be found in the library'; + LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION: ADescription := 'the version of the binary interface does not match the bindings interface'; LIBPRIMES_ERROR_NORESULTAVAILABLE: ADescription := 'no result is available'; LIBPRIMES_ERROR_CALCULATIONABORTED: ADescription := 'a calculation has been aborted'; else ADescription := 'unknown'; end; - inherited Create (Format ('Prime Numbers Interface Error - %s (#%d)', [ ADescription, AErrorCode ])); + inherited Create (Format ('Prime Numbers Library Error - %s (#%d)', [ ADescription, AErrorCode ])); end; constructor ELibPrimesException.CreateCustomMessage (AErrorCode: TLibPrimesResult; AMessage: String); @@ -434,6 +426,11 @@ implementation FWrapper.CheckError (Self, FWrapper.LibPrimesCalculator_SetValueFunc (FHandle, AValue)); end; + procedure TLibPrimesCalculator.Calculate(); + begin + FWrapper.CheckError (Self, FWrapper.LibPrimesCalculator_CalculateFunc (FHandle)); + end; + procedure TLibPrimesCalculator.SetProgressCallback(const AProgressCallback: PLibPrimes_ProgressCallback); begin if not Assigned (AProgressCallback) then @@ -441,11 +438,6 @@ implementation FWrapper.CheckError (Self, FWrapper.LibPrimesCalculator_SetProgressCallbackFunc (FHandle, AProgressCallback)); end; - procedure TLibPrimesCalculator.Calculate(); - begin - FWrapper.CheckError (Self, FWrapper.LibPrimesCalculator_CalculateFunc (FHandle)); - end; - (************************************************************************************************************************* Class implementation for FactorizationCalculator **************************************************************************************************************************) @@ -472,25 +464,6 @@ implementation FWrapper.CheckError (Self, FWrapper.LibPrimesFactorizationCalculator_GetPrimeFactorsFunc (FHandle, countNeededPrimeFactors, countWrittenPrimeFactors, @APrimeFactors[0])); end; - function TLibPrimesFactorizationCalculator.CheckPrimeFactors(const APrimeFactors: ArrayOfLibPrimesPrimeFactor): Boolean; - var - PtrPrimeFactors: PLibPrimesPrimeFactor; - LenPrimeFactors: QWord; - ResultAreEqual: Cardinal; - begin - LenPrimeFactors := Length (APrimeFactors); - if LenPrimeFactors > $FFFFFFFF then - raise ELibPrimesException.CreateCustomMessage (LIBPRIMES_ERROR_INVALIDPARAM, 'array has too many entries.'); - if LenPrimeFactors > 0 then - PtrPrimeFactors := @APrimeFactors[0] - else - PtrPrimeFactors := nil; - - ResultAreEqual := 0; - FWrapper.CheckError (Self, FWrapper.LibPrimesFactorizationCalculator_CheckPrimeFactorsFunc (FHandle, QWord (LenPrimeFactors), PtrPrimeFactors, ResultAreEqual)); - Result := (ResultAreEqual <> 0); - end; - (************************************************************************************************************************* Class implementation for SieveCalculator **************************************************************************************************************************) @@ -539,16 +512,17 @@ implementation FLibPrimesCalculator_GetValueFunc := LoadFunction ('libprimes_calculator_getvalue'); FLibPrimesCalculator_SetValueFunc := LoadFunction ('libprimes_calculator_setvalue'); - FLibPrimesCalculator_SetProgressCallbackFunc := LoadFunction ('libprimes_calculator_setprogresscallback'); FLibPrimesCalculator_CalculateFunc := LoadFunction ('libprimes_calculator_calculate'); + FLibPrimesCalculator_SetProgressCallbackFunc := LoadFunction ('libprimes_calculator_setprogresscallback'); FLibPrimesFactorizationCalculator_GetPrimeFactorsFunc := LoadFunction ('libprimes_factorizationcalculator_getprimefactors'); - FLibPrimesFactorizationCalculator_CheckPrimeFactorsFunc := LoadFunction ('libprimes_factorizationcalculator_checkprimefactors'); FLibPrimesSieveCalculator_GetPrimesFunc := LoadFunction ('libprimes_sievecalculator_getprimes'); - FLibPrimesCreateFactorizationCalculatorFunc := LoadFunction ('libprimes_createfactorizationcalculator'); - FLibPrimesCreateSieveCalculatorFunc := LoadFunction ('libprimes_createsievecalculator'); FLibPrimesReleaseInstanceFunc := LoadFunction ('libprimes_releaseinstance'); FLibPrimesGetLibraryVersionFunc := LoadFunction ('libprimes_getlibraryversion'); + FLibPrimesCreateFactorizationCalculatorFunc := LoadFunction ('libprimes_createfactorizationcalculator'); + FLibPrimesCreateSieveCalculatorFunc := LoadFunction ('libprimes_createsievecalculator'); FLibPrimesSetJournalFunc := LoadFunction ('libprimes_setjournal'); + + checkBinaryVersion(); end; destructor TLibPrimesWrapper.Destroy; @@ -589,6 +563,27 @@ implementation end; {$ENDIF MSWINDOWS} + procedure TLibPrimesWrapper.checkBinaryVersion(); + var + AMajor, AMinor, AMicro: Cardinal; + begin + GetLibraryVersion(AMajor, AMinor, AMicro); + if (AMajor <> LIBPRIMES_VERSION_MAJOR) or (AMinor < LIBPRIMES_VERSION_MINOR) then + raise ELibPrimesException.Create(LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION); + end; + + procedure TLibPrimesWrapper.ReleaseInstance(const AInstance: TLibPrimesBaseClass); + begin + if not Assigned (AInstance) then + raise ELibPrimesException.CreateCustomMessage (LIBPRIMES_ERROR_INVALIDPARAM, 'AInstance is a nil value.'); + CheckError (nil, LibPrimesReleaseInstanceFunc (AInstance.FHandle)); + end; + + procedure TLibPrimesWrapper.GetLibraryVersion(out AMajor: Cardinal; out AMinor: Cardinal; out AMicro: Cardinal); + begin + CheckError (nil, LibPrimesGetLibraryVersionFunc (AMajor, AMinor, AMicro)); + end; + function TLibPrimesWrapper.CreateFactorizationCalculator(): TLibPrimesFactorizationCalculator; var HInstance: TLibPrimesHandle; @@ -611,18 +606,6 @@ implementation Result := TLibPrimesSieveCalculator.Create (Self, HInstance); end; - procedure TLibPrimesWrapper.ReleaseInstance(const AInstance: TLibPrimesBaseClass); - begin - if not Assigned (AInstance) then - raise ELibPrimesException.CreateCustomMessage (LIBPRIMES_ERROR_INVALIDPARAM, 'AInstance is a nil value.'); - CheckError (nil, LibPrimesReleaseInstanceFunc (AInstance.FHandle)); - end; - - procedure TLibPrimesWrapper.GetLibraryVersion(out AMajor: Cardinal; out AMinor: Cardinal; out AMicro: Cardinal); - begin - CheckError (nil, LibPrimesGetLibraryVersionFunc (AMajor, AMinor, AMicro)); - end; - procedure TLibPrimesWrapper.SetJournal(const AFileName: String); begin CheckError (nil, LibPrimesSetJournalFunc (PAnsiChar (AFileName))); diff --git a/Examples/Primes/LibPrimes_component/Bindings/Python/LibPrimes.py b/Examples/Primes/LibPrimes_component/Bindings/Python/LibPrimes.py index 87eb9aa8..32645f3c 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/Python/LibPrimes.py +++ b/Examples/Primes/LibPrimes_component/Bindings/Python/LibPrimes.py @@ -1,15 +1,15 @@ '''++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated Python file in order to allow an easy - use of Prime Numbers Interface + use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 ''' @@ -30,6 +30,13 @@ def __str__(self): return 'LibPrimesException ' + str(self._code) + ': '+ str(self._message) return 'LibPrimesException ' + str(self._code) +'''Definition of binding API version +''' +class LibPrimesBindingVersion(enum.IntEnum): + MAJOR = 1 + MINOR = 2 + MICRO = 0 + '''Definition Error Codes ''' class LibPrimesErrorCodes(enum.IntEnum): @@ -41,8 +48,9 @@ class LibPrimesErrorCodes(enum.IntEnum): GENERICEXCEPTION = 5 COULDNOTLOADLIBRARY = 6 COULDNOTFINDLIBRARYEXPORT = 7 - NORESULTAVAILABLE = 8 - CALCULATIONABORTED = 9 + INCOMPATIBLEBINARYVERSION = 8 + NORESULTAVAILABLE = 9 + CALCULATIONABORTED = 10 '''Definition of Structs ''' @@ -86,21 +94,23 @@ def __init__(self, libraryName): raise ELibPrimesException(LibPrimesErrorCodes.COULDNOTLOADLIBRARY, str(e) + '| "'+path + '"' ) self._loadFunctionTable() + + self._checkBinaryVersion() def _loadFunctionTable(self): try: - self.lib.libprimes_createfactorizationcalculator.restype = ctypes.c_int64 - self.lib.libprimes_createfactorizationcalculator.argtypes = [ctypes.POINTER(ctypes.c_void_p)] - - self.lib.libprimes_createsievecalculator.restype = ctypes.c_int64 - self.lib.libprimes_createsievecalculator.argtypes = [ctypes.POINTER(ctypes.c_void_p)] - self.lib.libprimes_releaseinstance.restype = ctypes.c_int64 self.lib.libprimes_releaseinstance.argtypes = [ctypes.c_void_p] self.lib.libprimes_getlibraryversion.restype = ctypes.c_int64 self.lib.libprimes_getlibraryversion.argtypes = [ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32), ctypes.POINTER(ctypes.c_uint32)] + self.lib.libprimes_createfactorizationcalculator.restype = ctypes.c_int64 + self.lib.libprimes_createfactorizationcalculator.argtypes = [ctypes.POINTER(ctypes.c_void_p)] + + self.lib.libprimes_createsievecalculator.restype = ctypes.c_int64 + self.lib.libprimes_createsievecalculator.argtypes = [ctypes.POINTER(ctypes.c_void_p)] + self.lib.libprimes_setjournal.restype = ctypes.c_int64 self.lib.libprimes_setjournal.argtypes = [ctypes.c_char_p] @@ -110,24 +120,26 @@ def _loadFunctionTable(self): self.lib.libprimes_calculator_setvalue.restype = ctypes.c_int64 self.lib.libprimes_calculator_setvalue.argtypes = [ctypes.c_void_p, ctypes.c_uint64] - self.lib.libprimes_calculator_setprogresscallback.restype = ctypes.c_int64 - self.lib.libprimes_calculator_setprogresscallback.argtypes = [ctypes.c_void_p, LibPrimesProgressCallback] - self.lib.libprimes_calculator_calculate.restype = ctypes.c_int64 self.lib.libprimes_calculator_calculate.argtypes = [ctypes.c_void_p] + self.lib.libprimes_calculator_setprogresscallback.restype = ctypes.c_int64 + self.lib.libprimes_calculator_setprogresscallback.argtypes = [ctypes.c_void_p, LibPrimesProgressCallback] + self.lib.libprimes_factorizationcalculator_getprimefactors.restype = ctypes.c_int64 self.lib.libprimes_factorizationcalculator_getprimefactors.argtypes = [ctypes.c_void_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64), ctypes.POINTER(LibPrimesPrimeFactor)] - self.lib.libprimes_factorizationcalculator_checkprimefactors.restype = ctypes.c_int64 - self.lib.libprimes_factorizationcalculator_checkprimefactors.argtypes = [ctypes.c_void_p, ctypes.c_uint64, ctypes.POINTER(LibPrimesPrimeFactor), ctypes.POINTER(ctypes.c_bool)] - self.lib.libprimes_sievecalculator_getprimes.restype = ctypes.c_int64 self.lib.libprimes_sievecalculator_getprimes.argtypes = [ctypes.c_void_p, ctypes.c_uint64, ctypes.POINTER(ctypes.c_uint64), ctypes.POINTER(ctypes.c_uint64)] except AttributeError as ae: raise ELibPrimesException(LibPrimesErrorCodes.COULDNOTFINDLIBRARYEXPORT, ae.args[0]) + def _checkBinaryVersion(self): + nMajor, nMinor, _ = self.GetLibraryVersion() + if (nMajor != LibPrimesBindingVersion.MAJOR) or (nMinor < LibPrimesBindingVersion.MINOR): + raise ELibPrimesException(LibPrimesErrorCodes.INCOMPATIBLEBINARYVERSION) + def checkError(self, instance, errorCode): if instance: if instance._wrapper != self: @@ -135,6 +147,16 @@ def checkError(self, instance, errorCode): if errorCode != LibPrimesErrorCodes.SUCCESS.value: raise ELibPrimesException(errorCode) + def ReleaseInstance(self, InstanceObject): + self.checkError(None, self.lib.libprimes_releaseinstance(InstanceObject._handle)) + + def GetLibraryVersion(self): + pMajor = ctypes.c_uint32() + pMinor = ctypes.c_uint32() + pMicro = ctypes.c_uint32() + self.checkError(None, self.lib.libprimes_getlibraryversion(pMajor, pMinor, pMicro)) + return pMajor.value, pMinor.value, pMicro.value + def CreateFactorizationCalculator(self): InstanceHandle = ctypes.c_void_p() self.checkError(None, self.lib.libprimes_createfactorizationcalculator(InstanceHandle)) @@ -147,16 +169,6 @@ def CreateSieveCalculator(self): InstanceObject = LibPrimesSieveCalculator(InstanceHandle, self) return InstanceObject - def ReleaseInstance(self, InstanceObject): - self.checkError(None, self.lib.libprimes_releaseinstance(InstanceObject._handle)) - - def GetLibraryVersion(self): - pMajor = ctypes.c_uint32() - pMinor = ctypes.c_uint32() - pMicro = ctypes.c_uint32() - self.checkError(None, self.lib.libprimes_getlibraryversion(pMajor, pMinor, pMicro)) - return pMajor.value, pMinor.value, pMicro.value - def SetJournal(self, FileName): pFileName = ctypes.c_char_p(str.encode(FileName)) self.checkError(None, self.lib.libprimes_setjournal(pFileName)) @@ -189,12 +201,12 @@ def SetValue(self, Value): nValue = ctypes.c_uint64(Value) self._wrapper.checkError(self, self._wrapper.lib.libprimes_calculator_setvalue(self._handle, nValue)) - def SetProgressCallback(self, ProgressCallbackFunc): - self._wrapper.checkError(self, self._wrapper.lib.libprimes_calculator_setprogresscallback(self._handle, ProgressCallbackFunc)) - def Calculate(self): self._wrapper.checkError(self, self._wrapper.lib.libprimes_calculator_calculate(self._handle)) + def SetProgressCallback(self, ProgressCallbackFunc): + self._wrapper.checkError(self, self._wrapper.lib.libprimes_calculator_setprogresscallback(self._handle, ProgressCallbackFunc)) + '''FactorizationCalculator Class Implementation @@ -213,13 +225,6 @@ def GetPrimeFactors(self): self._wrapper.checkError(self, self._wrapper.lib.libprimes_factorizationcalculator_getprimefactors(self._handle, nPrimeFactorsCount, nPrimeFactorsNeededCount, pPrimeFactorsBuffer)) return [pPrimeFactorsBuffer[i] for i in range(nPrimeFactorsNeededCount.value)] - def CheckPrimeFactors(self, PrimeFactors): - nPrimeFactorsCount = ctypes.c_uint64(len(PrimeFactors)) - pPrimeFactorsBuffer = (LibPrimesPrimeFactor*len(PrimeFactors))(*PrimeFactors) - pAreEqual = ctypes.c_bool() - self._wrapper.checkError(self, self._wrapper.lib.libprimes_factorizationcalculator_checkprimefactors(self._handle, nPrimeFactorsCount, pPrimeFactorsBuffer, pAreEqual)) - return pAreEqual.value - '''SieveCalculator Class Implementation diff --git a/Examples/Primes/LibPrimes_component/Examples/CPP/CMakeLists.txt b/Examples/Primes/LibPrimes_component/Examples/CPP/CMakeLists.txt index 10131494..d33b1633 100644 --- a/Examples/Primes/LibPrimes_component/Examples/CPP/CMakeLists.txt +++ b/Examples/Primes/LibPrimes_component/Examples/CPP/CMakeLists.txt @@ -1,15 +1,15 @@ #[[++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.0. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated CMake Project that demonstrates the - usage of the C++ bindings of Prime Numbers Interface + usage of the C++ bindings of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 ]] @@ -18,8 +18,8 @@ cmake_minimum_required(VERSION 3.5) project(LibPrimesExample_CPP) set (CMAKE_CXX_STANDARD 11) -link_directories("") # TODO: put the correct path of the import library here +link_directories("PATHTO_LibPrimes_component/Bindings/Cpp") # TODO: put the correct path of the import library here add_executable(LibPrimesExample_CPP "${CMAKE_CURRENT_SOURCE_DIR}/LibPrimes_example.cpp" - "${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/Cpp/libprimes.cpp") + "PATHTO_LibPrimes_component/Bindings/Cpp/libprimes.cpp") target_link_libraries(LibPrimesExample_CPP libprimes) -target_include_directories(LibPrimesExample_CPP PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/Cpp") +target_include_directories(LibPrimesExample_CPP PRIVATE "PATHTO_LibPrimes_component/Bindings/Cpp") diff --git a/Examples/Primes/LibPrimes_component/Examples/CPP/LibPrimes_example.cpp b/Examples/Primes/LibPrimes_component/Examples/CPP/LibPrimes_example.cpp index 6577fc93..61a09128 100644 --- a/Examples/Primes/LibPrimes_component/Examples/CPP/LibPrimes_example.cpp +++ b/Examples/Primes/LibPrimes_component/Examples/CPP/LibPrimes_example.cpp @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated C++ application that demonstrates the - usage of the C++ bindings of Prime Numbers Interface + usage of the C++ bindings of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ diff --git a/Examples/Primes/LibPrimes_component/Examples/CppDynamic/CMakeLists.txt b/Examples/Primes/LibPrimes_component/Examples/CppDynamic/CMakeLists.txt index 90a32d5c..b7d34e0c 100644 --- a/Examples/Primes/LibPrimes_component/Examples/CppDynamic/CMakeLists.txt +++ b/Examples/Primes/LibPrimes_component/Examples/CppDynamic/CMakeLists.txt @@ -1,13 +1,13 @@ #[[++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.2.6. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated CMake Project that demonstrates the - usage of the Dynamic C++ bindings of Prime Numbers Interface + usage of the Dynamic C++ bindings of Prime Numbers Library Interface version: 1.2.0 diff --git a/Examples/Primes/LibPrimes_component/Examples/CppDynamic/LibPrimes_example.cpp b/Examples/Primes/LibPrimes_component/Examples/CppDynamic/LibPrimes_example.cpp index f1bec88e..bcee6558 100644 --- a/Examples/Primes/LibPrimes_component/Examples/CppDynamic/LibPrimes_example.cpp +++ b/Examples/Primes/LibPrimes_component/Examples/CppDynamic/LibPrimes_example.cpp @@ -1,22 +1,26 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + Abstract: This is an autogenerated C++ application that demonstrates the - usage of the Dynamic C++ bindings of Prime Numbers Interface -Interface version: 1.0.0 + usage of the Dynamic C++ bindings of Prime Numbers Library + +Interface version: 1.2.0 */ #include #include "libprimes_dynamic.hpp" +#include void progressCallback(float progress, bool* shouldAbort) { - std::cout << "Progress = " << round(progress * 100) << "%" << std::endl; + std::cout << "Progress = " << std::round(progress * 100) << "%" << std::endl; if (shouldAbort) { *shouldAbort = progress > 0.5; } @@ -47,11 +51,6 @@ int main() std::cout << pF.m_Prime << "^" << pF.m_Multiplicity << ((i < (primeFactors.size() - 1)) ? " * " : ""); } std::cout << std::endl; - - bool areEqual = factorization->CheckPrimeFactors(primeFactors); - if (!areEqual) { - std::cout << "Calculated prime factors are incorrect!"<< std::endl; - } } catch (std::exception &e) { diff --git a/Examples/Primes/LibPrimes_component/Examples/Pascal/LibPrimes_Example.lpr b/Examples/Primes/LibPrimes_component/Examples/Pascal/LibPrimes_Example.lpr index 0336c281..a8db4d17 100644 --- a/Examples/Primes/LibPrimes_component/Examples/Pascal/LibPrimes_Example.lpr +++ b/Examples/Primes/LibPrimes_component/Examples/Pascal/LibPrimes_Example.lpr @@ -1,12 +1,15 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + Abstract: This is an autogenerated Pascal application that demonstrates the - usage of the Pascal bindings of Prime Numbers Interface -Interface version: 1.0.0 + usage of the Pascal bindings of Prime Numbers Library + +Interface version: 1.2.0 *) diff --git a/Examples/Primes/LibPrimes_component/Examples/Python/LibPrimes_Example.py b/Examples/Primes/LibPrimes_component/Examples/Python/LibPrimes_Example.py index c6d26a70..897f8c4b 100644 --- a/Examples/Primes/LibPrimes_component/Examples/Python/LibPrimes_Example.py +++ b/Examples/Primes/LibPrimes_component/Examples/Python/LibPrimes_Example.py @@ -1,26 +1,28 @@ '''++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + Abstract: This is an autogenerated Python application that demonstrates the - usage of the Python bindings of Prime Numbers Interface -Interface version: 1.0.0 + usage of the Python bindings of Prime Numbers Library -''' +Interface version: 1.2.0 -def progressCallback(progress, shouldAbort): - print("Progress = {:d}%".format(round(progress*100))) - if (shouldAbort is not None): - shouldAbort[0] = progress > 0.5; +''' import os import sys -sys.path.append(os.path.join(os.path.realpath(__file__),"..", "..", "..", "Bindings", "Python")) +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "Bindings", "Python")) import LibPrimes +def progressCallback(progress, shouldAbort): + print("Progress = {:d}%".format(round(progress*100))) + if (shouldAbort is not None): + shouldAbort[0] = progress > 0.5 def main(): libpath = '' # TODO add the location of the shared library binary here @@ -40,7 +42,7 @@ def main(): commaString = "" print("{:d}".format(primes[i]), end=commaString) print("]") - + factorization = wrapper.CreateFactorizationCalculator() factorization.SetValue(735) cTypesCallback = LibPrimes.LibPrimesProgressCallback(progressCallback) @@ -55,8 +57,6 @@ def main(): productString = "\n" print(" {:d}^{:d} ".format(pF.Prime, pF.Multiplicity), end=productString) - - if __name__ == "__main__": try: main() diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/CMakeLists.txt b/Examples/Primes/LibPrimes_component/Implementations/Cpp/CMakeLists.txt index 47e036c5..ccf3ea4d 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/CMakeLists.txt +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/CMakeLists.txt @@ -1,10 +1,13 @@ #[[++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -Abstract: This is an autogenerated CMakeLists file for the development of Prime Numbers Interface. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + +Abstract: This is an autogenerated CMakeLists file for the development of Prime Numbers Library. + Interface version: 1.2.0 @@ -12,9 +15,11 @@ Interface version: 1.2.0 cmake_minimum_required(VERSION 3.5) -### The implementation of the Prime Numbers Interface component +### The implementation of the Prime Numbers Library component project(LibPrimes) +set (CMAKE_CXX_STANDARD 11) + # The location of autogenerated interfaces set(CMAKE_CURRENT_AUTOGENERATED_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Interfaces) @@ -24,17 +29,17 @@ file(GLOB LIBPRIMES_SRC file(GLOB LIBPRIMES_HDR ${CMAKE_CURRENT_SOURCE_DIR}/Stub/*.hpp ) -set(LIBPRIMES_SRC ${LIBPRIMES_SRC} +set(LIBPRIMES_SRC ${LIBPRIMES_SRC} ${LIBPRIMES_SRC} ${CMAKE_CURRENT_AUTOGENERATED_DIR}/libprimes_interfaceexception.cpp ${CMAKE_CURRENT_AUTOGENERATED_DIR}/libprimes_interfacewrapper.cpp ${CMAKE_CURRENT_AUTOGENERATED_DIR}/libprimes_interfacejournal.cpp ) -add_library(libprimes SHARED ${LIBPRIMES_SRC} ${LIBPRIMES_HDR}) -# This makes sure symbols are exported -target_compile_options(libprimes PRIVATE "-D__LIBPRIMES_EXPORTS") -# The following two properties are crucial to reduce the number of unwantedly exported symbols +add_library(libprimes SHARED ${LIBPRIMES_SRC}) +# The following two properties are crucial to reduce the number of undesirably exported symbols set_target_properties(libprimes PROPERTIES CXX_VISIBILITY_PRESET hidden) set_target_properties(libprimes PROPERTIES VISIBILITY_INLINES_HIDDEN ON) +# This makes sure symbols are exported +target_compile_options(libprimes PRIVATE "-D__LIBPRIMES_EXPORTS") target_include_directories(libprimes PRIVATE ${CMAKE_CURRENT_AUTOGENERATED_DIR}) target_include_directories(libprimes PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Stub) diff --git a/Examples/Primes/LibPrimes_component/Bindings/C/libprimes.h b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes.h similarity index 69% rename from Examples/Primes/LibPrimes_component/Bindings/C/libprimes.h rename to Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes.h index d6ebf0e3..ef110e11 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/C/libprimes.h +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes.h @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated plain C Header file in order to allow an easy - use of Prime Numbers Interface + use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -41,7 +41,7 @@ extern "C" { * @param[out] pValue - The current value of this Calculator * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue(LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue); /** * Sets the value to be factorized @@ -50,31 +50,31 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calc * @param[in] nValue - The value to be factorized * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 nValue); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setvalue(LibPrimes_Calculator pCalculator, LibPrimes_uint64 nValue); /** -* Sets the progress callback function +* Performs the specific calculation of this Calculator * * @param[in] pCalculator - Calculator instance. -* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setprogresscallback (LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_calculate(LibPrimes_Calculator pCalculator); /** -* Performs the specific calculation of this Calculator +* Sets the progress callback function * * @param[in] pCalculator - Calculator instance. +* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_calculate (LibPrimes_Calculator pCalculator); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_setprogresscallback(LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback); /************************************************************************************************************************* Class definition for FactorizationCalculator **************************************************************************************************************************/ /** -* Returns the prime factors of this number (with multiplicity) +* Returns the prime factors of this number (without multiplicity) * * @param[in] pFactorizationCalculator - FactorizationCalculator instance. * @param[in] nPrimeFactorsBufferSize - Number of elements in buffer @@ -82,18 +82,7 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_calculate (LibPrimes_Cal * @param[out] pPrimeFactorsBuffer - PrimeFactor buffer of The prime factors of this number * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_getprimefactors (LibPrimes_FactorizationCalculator pFactorizationCalculator, const LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); - -/** -* Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value -* -* @param[in] pFactorizationCalculator - FactorizationCalculator instance. -* @param[in] nPrimeFactorsBufferSize - Number of elements in buffer -* @param[in] pPrimeFactorsBuffer - PrimeFactor buffer of -* @param[out] pAreEqual - Do the prime factors decompose this calculator's value -* @return error code or 0 (success) -*/ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_checkprimefactors (LibPrimes_FactorizationCalculator pFactorizationCalculator, LibPrimes_uint64 nPrimeFactorsBufferSize, const sLibPrimesPrimeFactor * pPrimeFactorsBuffer, bool * pAreEqual); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_getprimefactors(LibPrimes_FactorizationCalculator pFactorizationCalculator, const LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); /************************************************************************************************************************* Class definition for SieveCalculator @@ -108,45 +97,45 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_factorizationcalculator_checkprimef * @param[out] pPrimesBuffer - uint64 buffer of The primes lower or equal to the sieve's value * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_sievecalculator_getprimes (LibPrimes_SieveCalculator pSieveCalculator, const LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_sievecalculator_getprimes(LibPrimes_SieveCalculator pSieveCalculator, const LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer); /************************************************************************************************************************* Global functions **************************************************************************************************************************/ /** -* Creates a new FactorizationCalculator instance +* Releases the memory of an Instance * -* @param[out] pInstance - New FactorizationCalculator instance +* @param[in] pInstance - Instance Handle * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createfactorizationcalculator (LibPrimes_FactorizationCalculator * pInstance); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_releaseinstance(LibPrimes_BaseClass pInstance); /** -* Creates a new SieveCalculator instance +* retrieves the current version of the library. * -* @param[out] pInstance - New SieveCalculator instance +* @param[out] pMajor - returns the major version of the library +* @param[out] pMinor - returns the minor version of the library +* @param[out] pMicro - returns the micro version of the library * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createsievecalculator (LibPrimes_SieveCalculator * pInstance); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_getlibraryversion(LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro); /** -* Releases the memory of an Instance +* Creates a new FactorizationCalculator instance * -* @param[in] pInstance - Instance Handle +* @param[out] pInstance - New FactorizationCalculator instance * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_releaseinstance (LibPrimes_BaseClass pInstance); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createfactorizationcalculator(LibPrimes_FactorizationCalculator * pInstance); /** -* retrieves the current version of the library. +* Creates a new SieveCalculator instance * -* @param[out] pMajor - returns the major version of the library -* @param[out] pMinor - returns the minor version of the library -* @param[out] pMicro - returns the micro version of the library +* @param[out] pInstance - New SieveCalculator instance * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_getlibraryversion (LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_createsievecalculator(LibPrimes_SieveCalculator * pInstance); /** * Handles Library Journaling @@ -154,7 +143,7 @@ LIBPRIMES_DECLSPEC LibPrimesResult libprimes_getlibraryversion (LibPrimes_uint32 * @param[in] pFileName - Journal FileName * @return error code or 0 (success) */ -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_setjournal (const char * pFileName); +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_setjournal(const char * pFileName); } diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaceexception.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaceexception.cpp new file mode 100644 index 00000000..440b7040 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaceexception.cpp @@ -0,0 +1,39 @@ +/*++ + +Copyright (C) 2018 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + +Abstract: This is an autogenerated C++ Implementation file with the basic internal + exception type in order to allow an easy use of Prime Numbers Library + +Interface version: 1.2.0 + +*/ + + +#include + +#include "libprimes_interfaceexception.hpp" + +/************************************************************************************************************************* + Class ELibPrimesInterfaceException +**************************************************************************************************************************/ +ELibPrimesInterfaceException::ELibPrimesInterfaceException(LibPrimesResult errorCode) + : m_errorMessage("LibPrimes Error " + std::to_string (errorCode)) +{ + m_errorCode = errorCode; +} + +LibPrimesResult ELibPrimesInterfaceException::getErrorCode () +{ + return m_errorCode; +} + +const char * ELibPrimesInterfaceException::what () const noexcept +{ + return m_errorMessage.c_str(); +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaceexception.hpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaceexception.hpp new file mode 100644 index 00000000..8ea42a10 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaceexception.hpp @@ -0,0 +1,55 @@ +/*++ + +Copyright (C) 2018 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + +Abstract: This is an autogenerated C++ Header file with the basic internal + exception type in order to allow an easy use of Prime Numbers Library + +Interface version: 1.2.0 + +*/ + +#ifndef __LIBPRIMES_INTERFACEEXCEPTION_HEADER +#define __LIBPRIMES_INTERFACEEXCEPTION_HEADER + +#include +#include +#include "libprimes_types.h" + +/************************************************************************************************************************* + Class ELibPrimesInterfaceException +**************************************************************************************************************************/ + + +class ELibPrimesInterfaceException : public std::exception { +protected: + /** + * Error code for the Exception. + */ + LibPrimesResult m_errorCode; + /** + * Error message for the Exception. + */ + std::string m_errorMessage; + +public: + /** + * Exception Constructor. + */ + ELibPrimesInterfaceException (LibPrimesResult errorCode); + + /** + * Returns error code + */ + LibPrimesResult getErrorCode (); + /** + * Returns error message + */ + const char* what () const noexcept override; +}; + +#endif // __LIBPRIMES_INTERFACEEXCEPTION_HEADER diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacejournal.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacejournal.cpp new file mode 100644 index 00000000..d89395c5 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacejournal.cpp @@ -0,0 +1,312 @@ +/*++ + +Copyright (C) 2018 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + +Abstract: This is an autogenerated C++ implementation file in order to allow easy +development of Prime Numbers Library. It provides an automatic Journaling mechanism for the library implementation. + +Interface version: 1.2.0 + +*/ + + +#include +#include +#include + +#include "libprimes_interfacejournal.hpp" +#include "libprimes_interfaceexception.hpp" + + +std::string LibPrimesHandleToHex (LibPrimesHandle pHandle) +{ + std::stringstream stream; + stream << std::setfill('0') << std::setw(sizeof(LibPrimes_uint64) * 2) + << std::hex << (LibPrimes_uint64) pHandle; + return stream.str(); +} + +CLibPrimesInterfaceJournalEntry::CLibPrimesInterfaceJournalEntry(CLibPrimesInterfaceJournal * pJournal, std::string sClassName, std::string sMethodName, LibPrimesHandle pInstanceHandle) + : m_sClassName(sClassName), m_sMethodName(sMethodName), m_pJournal (pJournal), m_nInitTimeStamp (0), m_nFinishTimeStamp (0), m_ErrorCode (LIBPRIMES_SUCCESS) +{ + if (pJournal == nullptr) + throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_INVALIDPARAM); + m_nInitTimeStamp = m_pJournal->getTimeStamp (); + m_sInstanceHandle = LibPrimesHandleToHex (pInstanceHandle); +} + +CLibPrimesInterfaceJournalEntry::~CLibPrimesInterfaceJournalEntry() +{ +} + +void CLibPrimesInterfaceJournalEntry::addParameter(const std::string & sName, const std::string & sParameterType, const std::string & sParameterValue) +{ + m_sParameters.push_back(std::make_pair(std::make_pair(sName, sParameterType), sParameterValue)); +} + +void CLibPrimesInterfaceJournalEntry::addResult(const std::string & sName, const std::string & sResultType, const std::string & sResultValue) +{ + m_sResultValues.push_back(std::make_pair(std::make_pair(sName, sResultType), sResultValue)); +} + +std::string CLibPrimesInterfaceJournalEntry::getXMLString() +{ + std::stringstream sStream; + LibPrimes_uint64 nDuration = 0; + + if (m_nFinishTimeStamp > m_nInitTimeStamp) + nDuration = m_nFinishTimeStamp - m_nInitTimeStamp; + + sStream << " \n"; + + if (m_sClassName != "") + sStream << " \n"; + + auto iParamIter = m_sParameters.begin(); + while (iParamIter != m_sParameters.end()) { + sStream << " first.first << "\" type=\"" << iParamIter->first.second << "\" value=\"" << iParamIter->second <<"\" />\n"; + iParamIter++; + } + + auto iResultIter = m_sResultValues.begin(); + while (iResultIter != m_sResultValues.end()) { + sStream << " first.first << "\" type=\"" << iResultIter->first.second << "\" value=\"" << iResultIter->second << "\" />\n"; + iResultIter++; + } + + sStream << " \n"; + return sStream.str (); +} + +void CLibPrimesInterfaceJournalEntry::writeSuccess() +{ + writeError(LIBPRIMES_SUCCESS); +} + +void CLibPrimesInterfaceJournalEntry::writeError(LibPrimesResult nErrorCode) +{ + m_ErrorCode = nErrorCode; + m_nFinishTimeStamp = m_pJournal->getTimeStamp(); + m_pJournal->writeEntry(this); +} + +void CLibPrimesInterfaceJournalEntry::addBooleanParameter(const std::string & sName, const bool bValue) +{ + addParameter (sName, "bool", std::to_string((int)bValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt8Parameter(const std::string & sName, const LibPrimes_uint8 nValue) +{ + addParameter(sName, "uint8", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt16Parameter(const std::string & sName, const LibPrimes_uint16 nValue) +{ + addParameter(sName, "uint16", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt32Parameter(const std::string & sName, const LibPrimes_uint32 nValue) +{ + addParameter(sName, "uint32", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt64Parameter(const std::string & sName, const LibPrimes_uint64 nValue) +{ + addParameter(sName, "uint64", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt8Parameter(const std::string & sName, const LibPrimes_int8 nValue) +{ + addParameter(sName, "int8", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt16Parameter(const std::string & sName, const LibPrimes_int16 nValue) +{ + addParameter(sName, "int16", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt32Parameter(const std::string & sName, const LibPrimes_int32 nValue) +{ + addParameter(sName, "uint32", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt64Parameter(const std::string & sName, const LibPrimes_int64 nValue) +{ + addParameter(sName, "int64", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addSingleParameter(const std::string & sName, const LibPrimes_single fValue) +{ + addParameter(sName, "single", std::to_string(fValue)); +} + +void CLibPrimesInterfaceJournalEntry::addDoubleParameter(const std::string & sName, const LibPrimes_double dValue) +{ + addParameter(sName, "double", std::to_string(dValue)); +} + +void CLibPrimesInterfaceJournalEntry::addStringParameter(const std::string & sName, const char * pValue) +{ + if (pValue != nullptr) { + addParameter(sName, "string", pValue); + } + else { + addParameter(sName, "nullstring", ""); + } +} + +void CLibPrimesInterfaceJournalEntry::addHandleParameter(const std::string & sName, const LibPrimesHandle pHandle) +{ + addParameter(sName, "handle", LibPrimesHandleToHex(pHandle)); +} + +void CLibPrimesInterfaceJournalEntry::addEnumParameter(const std::string & sName, const std::string & sEnumType, const LibPrimes_uint32 nValue) +{ + addParameter(sName, "enum" + sEnumType, std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addBooleanResult(const std::string & sName, const bool bValue) +{ + addResult(sName, "bool", std::to_string((int)bValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt8Result(const std::string & sName, const LibPrimes_uint8 nValue) +{ + addResult(sName, "uint8", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt16Result(const std::string & sName, const LibPrimes_uint16 nValue) +{ + addResult(sName, "uint16", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt32Result(const std::string & sName, const LibPrimes_uint32 nValue) +{ + addResult(sName, "uint32", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addUInt64Result(const std::string & sName, const LibPrimes_uint64 nValue) +{ + addResult(sName, "uint64", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt8Result(const std::string & sName, const LibPrimes_int8 nValue) +{ + addResult(sName, "int8", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt16Result(const std::string & sName, const LibPrimes_int16 nValue) +{ + addResult(sName, "int16", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt32Result(const std::string & sName, const LibPrimes_int32 nValue) +{ + addResult(sName, "uint32", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addInt64Result(const std::string & sName, const LibPrimes_int64 nValue) +{ + addResult(sName, "int64", std::to_string(nValue)); +} + +void CLibPrimesInterfaceJournalEntry::addSingleResult(const std::string & sName, const LibPrimes_single fValue) +{ + addResult(sName, "single", std::to_string(fValue)); +} + +void CLibPrimesInterfaceJournalEntry::addDoubleResult(const std::string & sName, const LibPrimes_double dValue) +{ + addResult(sName, "double", std::to_string(dValue)); +} + +void CLibPrimesInterfaceJournalEntry::addStringResult(const std::string & sName, const char * pValue) +{ + if (pValue != nullptr) { + addResult(sName, "string", pValue); + } + else { + addResult(sName, "nullstring", ""); + } +} + +void CLibPrimesInterfaceJournalEntry::addHandleResult(const std::string & sName, const LibPrimesHandle pHandle) +{ + addResult(sName, "handle", LibPrimesHandleToHex(pHandle)); +} + +void CLibPrimesInterfaceJournalEntry::addEnumResult(const std::string & sName, const std::string & sEnumType, const LibPrimes_uint32 nValue) +{ + addResult(sName, "enum" + sEnumType, std::to_string(nValue)); +} + + +CLibPrimesInterfaceJournal::CLibPrimesInterfaceJournal (const std::string & sFileName) + : m_sFileName (sFileName) +{ + m_StartTime = std::chrono::high_resolution_clock::now(); + m_Stream.open (sFileName, std::ios::out); + m_Stream << "\n"; + m_Stream << "\n"; + m_Stream << "\n"; + +} + +CLibPrimesInterfaceJournal::~CLibPrimesInterfaceJournal () +{ + m_Stream << "\n"; +} + +PLibPrimesInterfaceJournalEntry CLibPrimesInterfaceJournal::beginClassMethod(const LibPrimesHandle pHandle, const std::string & sClassName, const std::string & sMethodName) +{ + return std::make_shared(this, sClassName, sMethodName, pHandle); +} + +PLibPrimesInterfaceJournalEntry CLibPrimesInterfaceJournal::beginStaticFunction(const std::string & sMethodName) +{ + return std::make_shared(this, "", sMethodName, nullptr); +} + +void CLibPrimesInterfaceJournal::writeEntry (CLibPrimesInterfaceJournalEntry * pEntry) +{ + if (pEntry == nullptr) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + std::string sXMLString = pEntry->getXMLString(); + m_Mutex.lock(); + try { + m_Stream << sXMLString; + m_Stream << "\n"; + + m_Mutex.unlock(); + } + catch (...) { + m_Mutex.unlock(); + } +} + +LibPrimes_uint64 CLibPrimesInterfaceJournal::getTimeStamp () +{ + auto currentTime = std::chrono::high_resolution_clock::now(); + if (m_StartTime < currentTime) { + auto duration = currentTime - m_StartTime; + auto milliSeconds = std::chrono::duration_cast (duration); + + return (LibPrimes_uint64) milliSeconds.count(); + } + else { + return 0; + } + +} + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacejournal.hpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacejournal.hpp new file mode 100644 index 00000000..65d8e2f0 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacejournal.hpp @@ -0,0 +1,120 @@ +/*++ + +Copyright (C) 2018 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + +Abstract: This is an autogenerated C++ header file in order to allow easy +development of Prime Numbers Library. It provides an automatic Journaling mechanism for the library implementation. + +Interface version: 1.2.0 + +*/ + +#ifndef __LIBPRIMES_INTERFACEJOURNAL_HEADER +#define __LIBPRIMES_INTERFACEJOURNAL_HEADER + +#include +#include +#include +#include +#include +#include +#include +#include "libprimes_types.h" + +/************************************************************************************************************************* + Class CLibPrimesInterfaceJournal +**************************************************************************************************************************/ + +class CLibPrimesInterfaceJournal; + +class CLibPrimesInterfaceJournalEntry { + + protected: + + CLibPrimesInterfaceJournal * m_pJournal; + LibPrimesResult m_ErrorCode; + std::string m_sClassName; + std::string m_sMethodName; + std::string m_sInstanceHandle; + LibPrimes_uint64 m_nInitTimeStamp; + LibPrimes_uint64 m_nFinishTimeStamp; + std::list, std::string>> m_sParameters; + std::list, std::string>> m_sResultValues; + + std::string getXMLString(); + void addParameter (const std::string & sName, const std::string & sParameterType, const std::string & sParameterValue); + void addResult (const std::string & sName, const std::string & sResultType, const std::string & sResultValue); + + public: + CLibPrimesInterfaceJournalEntry(CLibPrimesInterfaceJournal * pJournal, std::string sClassName, std::string sMethodName, LibPrimesHandle pInstanceHandle); + ~CLibPrimesInterfaceJournalEntry(); + + void writeSuccess (); + void writeError (LibPrimesResult nErrorCode); + + void addBooleanParameter(const std::string & sName, const bool bValue); + void addUInt8Parameter(const std::string & sName, const LibPrimes_uint8 nValue); + void addUInt16Parameter(const std::string & sName, const LibPrimes_uint16 nValue); + void addUInt32Parameter(const std::string & sName, const LibPrimes_uint32 nValue); + void addUInt64Parameter(const std::string & sName, const LibPrimes_uint64 nValue); + void addInt8Parameter(const std::string & sName, const LibPrimes_int8 nValue); + void addInt16Parameter(const std::string & sName, const LibPrimes_int16 nValue); + void addInt32Parameter(const std::string & sName, const LibPrimes_int32 nValue); + void addInt64Parameter(const std::string & sName, const LibPrimes_int64 nValue); + void addSingleParameter(const std::string & sName, const LibPrimes_single fValue); + void addDoubleParameter(const std::string & sName, const LibPrimes_double dValue); + void addStringParameter(const std::string & sName, const char * pValue); + void addHandleParameter(const std::string & sName, const LibPrimesHandle pHandle); + void addEnumParameter(const std::string & sName, const std::string & sEnumType, const LibPrimes_uint32 nValue); + + void addBooleanResult(const std::string & sName, const bool bValue); + void addUInt8Result(const std::string & sName, const LibPrimes_uint8 nValue); + void addUInt16Result(const std::string & sName, const LibPrimes_uint16 nValue); + void addUInt32Result(const std::string & sName, const LibPrimes_uint32 nValue); + void addUInt64Result(const std::string & sName, const LibPrimes_uint64 nValue); + void addInt8Result(const std::string & sName, const LibPrimes_int8 nValue); + void addInt16Result(const std::string & sName, const LibPrimes_int16 nValue); + void addInt32Result(const std::string & sName, const LibPrimes_int32 nValue); + void addInt64Result(const std::string & sName, const LibPrimes_int64 nValue); + void addSingleResult(const std::string & sName, const LibPrimes_single fValue); + void addDoubleResult(const std::string & sName, const LibPrimes_double dValue); + void addStringResult(const std::string & sName, const char * pValue); + void addHandleResult(const std::string & sName, const LibPrimesHandle pHandle); + void addEnumResult(const std::string & sName, const std::string & sEnumType, const LibPrimes_uint32 nValue); + +friend class CLibPrimesInterfaceJournal; + +}; + +typedef std::shared_ptr PLibPrimesInterfaceJournalEntry; + + + +class CLibPrimesInterfaceJournal { + + protected: + + std::string m_sFileName; + std::mutex m_Mutex; + std::ofstream m_Stream; + std::chrono::time_point m_StartTime; + void writeEntry (CLibPrimesInterfaceJournalEntry * pEntry); + LibPrimes_uint64 getTimeStamp (); + + public: + + CLibPrimesInterfaceJournal (const std::string & sFileName); + ~CLibPrimesInterfaceJournal (); + PLibPrimesInterfaceJournalEntry beginClassMethod (const LibPrimesHandle pHandle, const std::string & sClassName, const std::string & sMethodName); + PLibPrimesInterfaceJournalEntry beginStaticFunction (const std::string & sMethodName); + friend class CLibPrimesInterfaceJournalEntry; +}; + +typedef std::shared_ptr PLibPrimesInterfaceJournal; + +#endif // __LIBPRIMES_INTERFACEJOURNAL_HEADER + diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaces.hpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaces.hpp new file mode 100644 index 00000000..71b5002f --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfaces.hpp @@ -0,0 +1,154 @@ +/*++ + +Copyright (C) 2018 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + +Abstract: This is an autogenerated C++ header 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 + +*/ + + +#ifndef __LIBPRIMES_CPPINTERFACES +#define __LIBPRIMES_CPPINTERFACES + +#include + +#include "libprimes_types.h" + +namespace LibPrimes { +namespace Impl { + +/** + Forward declarations of class interfaces +*/ +class ILibPrimesCalculator; +class ILibPrimesFactorizationCalculator; +class ILibPrimesSieveCalculator; + + +/************************************************************************************************************************* + Class ILibPrimesBaseClass +**************************************************************************************************************************/ + +class ILibPrimesBaseClass { +public: + virtual ~ILibPrimesBaseClass () {} +}; + + +/************************************************************************************************************************* + Class interface for LibPrimesCalculator +**************************************************************************************************************************/ + +class ILibPrimesCalculator : public virtual ILibPrimesBaseClass { +public: + /** + * ICalculator::GetValue - Returns the current value of this Calculator + * @return The current value of this Calculator + */ + virtual LibPrimes_uint64 GetValue () = 0; + + /** + * ICalculator::SetValue - Sets the value to be factorized + * @param[in] nValue - The value to be factorized + */ + virtual void SetValue (const LibPrimes_uint64 nValue) = 0; + + /** + * ICalculator::Calculate - Performs the specific calculation of this Calculator + */ + virtual void Calculate () = 0; + + /** + * ICalculator::SetProgressCallback - Sets the progress callback function + * @param[in] pProgressCallback - callback function + */ + virtual void SetProgressCallback (const LibPrimesProgressCallback pProgressCallback) = 0; + +}; + + +/************************************************************************************************************************* + Class interface for LibPrimesFactorizationCalculator +**************************************************************************************************************************/ + +class ILibPrimesFactorizationCalculator : public virtual ILibPrimesBaseClass, public virtual ILibPrimesCalculator { +public: + /** + * IFactorizationCalculator::GetPrimeFactors - Returns the prime factors of this number (without multiplicity) + * @param[in] nPrimeFactorsBufferSize - Number of elements in buffer + * @param[out] pPrimeFactorsNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pPrimeFactorsBuffer - PrimeFactor buffer of The prime factors of this number + */ + virtual void GetPrimeFactors (LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) = 0; + +}; + + +/************************************************************************************************************************* + Class interface for LibPrimesSieveCalculator +**************************************************************************************************************************/ + +class ILibPrimesSieveCalculator : public virtual ILibPrimesBaseClass, public virtual ILibPrimesCalculator { +public: + /** + * ISieveCalculator::GetPrimes - Returns all prime numbers lower or equal to the sieve's value + * @param[in] nPrimesBufferSize - Number of elements in buffer + * @param[out] pPrimesNeededCount - will be filled with the count of the written structs, or needed buffer size. + * @param[out] pPrimesBuffer - uint64 buffer of The primes lower or equal to the sieve's value + */ + virtual void GetPrimes (LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer) = 0; + +}; + + +/************************************************************************************************************************* + Global functions declarations +**************************************************************************************************************************/ +class CLibPrimesWrapper { +public: + /** + * Ilibprimes::ReleaseInstance - Releases the memory of an Instance + * @param[in] pInstance - Instance Handle + */ + static void ReleaseInstance (ILibPrimesBaseClass* pInstance); + + /** + * Ilibprimes::GetLibraryVersion - retrieves the current version of the library. + * @param[out] nMajor - returns the major version of the library + * @param[out] nMinor - returns the minor version of the library + * @param[out] nMicro - returns the micro version of the library + */ + static void GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_uint32 & nMinor, LibPrimes_uint32 & nMicro); + + /** + * Ilibprimes::CreateFactorizationCalculator - Creates a new FactorizationCalculator instance + * @return New FactorizationCalculator instance + */ + static ILibPrimesFactorizationCalculator * CreateFactorizationCalculator (); + + /** + * Ilibprimes::CreateSieveCalculator - Creates a new SieveCalculator instance + * @return New SieveCalculator instance + */ + static ILibPrimesSieveCalculator * CreateSieveCalculator (); + + /** + * Ilibprimes::SetJournal - Handles Library Journaling + * @param[in] sFileName - Journal FileName + */ + static void SetJournal (const std::string & sFileName); + +}; + +} // namespace Impl +} // namespace LibPrimes + +#endif // __LIBPRIMES_CPPINTERFACES diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacewrapper.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacewrapper.cpp new file mode 100644 index 00000000..884063fd --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_interfacewrapper.cpp @@ -0,0 +1,447 @@ +/*++ + +Copyright (C) 2018 PrimeDevelopers + +All rights reserved. + +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + +Abstract: This is an autogenerated C++ 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 + +*/ + +#include "libprimes.h" +#include "libprimes_interfaces.hpp" +#include "libprimes_interfaceexception.hpp" +#include "libprimes_interfacejournal.hpp" + +using namespace LibPrimes::Impl; + +PLibPrimesInterfaceJournal m_GlobalJournal; + +extern "C" { + + +/************************************************************************************************************************* + Class implementation for Calculator +**************************************************************************************************************************/ +LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pCalculator, "Calculator", "GetValue"); + } + + if (pValue == nullptr) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + ILibPrimesBaseClass* pIBaseClass = (ILibPrimesBaseClass *)pCalculator; + ILibPrimesCalculator* pICalculator = dynamic_cast(pIBaseClass); + if (!pICalculator) + throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_INVALIDCAST); + + + *pValue = pICalculator->GetValue(); + + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt64Result ("Value", *pValue); + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +LibPrimesResult libprimes_calculator_setvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 nValue) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pCalculator, "Calculator", "SetValue"); + pJournalEntry->addUInt64Parameter ("Value", nValue); + } + + + ILibPrimesBaseClass* pIBaseClass = (ILibPrimesBaseClass *)pCalculator; + ILibPrimesCalculator* pICalculator = dynamic_cast(pIBaseClass); + if (!pICalculator) + throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_INVALIDCAST); + + + pICalculator->SetValue(nValue); + + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +LibPrimesResult libprimes_calculator_calculate (LibPrimes_Calculator pCalculator) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pCalculator, "Calculator", "Calculate"); + } + + + ILibPrimesBaseClass* pIBaseClass = (ILibPrimesBaseClass *)pCalculator; + ILibPrimesCalculator* pICalculator = dynamic_cast(pIBaseClass); + if (!pICalculator) + throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_INVALIDCAST); + + + pICalculator->Calculate(); + + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +LibPrimesResult libprimes_calculator_setprogresscallback (LibPrimes_Calculator pCalculator, LibPrimesProgressCallback pProgressCallback) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pCalculator, "Calculator", "SetProgressCallback"); + } + + + ILibPrimesBaseClass* pIBaseClass = (ILibPrimesBaseClass *)pCalculator; + ILibPrimesCalculator* pICalculator = dynamic_cast(pIBaseClass); + if (!pICalculator) + throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_INVALIDCAST); + + + pICalculator->SetProgressCallback(pProgressCallback); + + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + + +/************************************************************************************************************************* + Class implementation for FactorizationCalculator +**************************************************************************************************************************/ +LibPrimesResult libprimes_factorizationcalculator_getprimefactors (LibPrimes_FactorizationCalculator pFactorizationCalculator, const LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pFactorizationCalculator, "FactorizationCalculator", "GetPrimeFactors"); + } + + if ((!pPrimeFactorsBuffer) && !(pPrimeFactorsNeededCount)) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + ILibPrimesBaseClass* pIBaseClass = (ILibPrimesBaseClass *)pFactorizationCalculator; + ILibPrimesFactorizationCalculator* pIFactorizationCalculator = dynamic_cast(pIBaseClass); + if (!pIFactorizationCalculator) + throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_INVALIDCAST); + + + pIFactorizationCalculator->GetPrimeFactors(nPrimeFactorsBufferSize, pPrimeFactorsNeededCount, pPrimeFactorsBuffer); + + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + + +/************************************************************************************************************************* + Class implementation for SieveCalculator +**************************************************************************************************************************/ +LibPrimesResult libprimes_sievecalculator_getprimes (LibPrimes_SieveCalculator pSieveCalculator, const LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginClassMethod(pSieveCalculator, "SieveCalculator", "GetPrimes"); + } + + if ((!pPrimesBuffer) && !(pPrimesNeededCount)) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + ILibPrimesBaseClass* pIBaseClass = (ILibPrimesBaseClass *)pSieveCalculator; + ILibPrimesSieveCalculator* pISieveCalculator = dynamic_cast(pIBaseClass); + if (!pISieveCalculator) + throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_INVALIDCAST); + + + pISieveCalculator->GetPrimes(nPrimesBufferSize, pPrimesNeededCount, pPrimesBuffer); + + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + + +/************************************************************************************************************************* + Global functions implementation +**************************************************************************************************************************/ +LibPrimesResult libprimes_releaseinstance (LibPrimes_BaseClass pInstance) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("ReleaseInstance"); + pJournalEntry->addHandleParameter ("Instance", pInstance); + } + + + ILibPrimesBaseClass* pIBaseClassInstance = (ILibPrimesBaseClass *)pInstance; + ILibPrimesBaseClass* pIInstance = dynamic_cast(pIBaseClassInstance); + if (!pIInstance) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDCAST); + + + CLibPrimesWrapper::ReleaseInstance(pIInstance); + + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +LibPrimesResult libprimes_getlibraryversion (LibPrimes_uint32 * pMajor, LibPrimes_uint32 * pMinor, LibPrimes_uint32 * pMicro) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("GetLibraryVersion"); + } + + if (!pMajor) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + if (!pMinor) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + if (!pMicro) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + LibPrimes_uint32 nMajor; + LibPrimes_uint32 nMinor; + LibPrimes_uint32 nMicro; + + CLibPrimesWrapper::GetLibraryVersion(nMajor, nMinor, nMicro); + + *pMajor = nMajor; + *pMinor = nMinor; + *pMicro = nMicro; + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addUInt32Result ("Major", *pMajor); + pJournalEntry->addUInt32Result ("Minor", *pMinor); + pJournalEntry->addUInt32Result ("Micro", *pMicro); + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +LibPrimesResult libprimes_createfactorizationcalculator (LibPrimes_FactorizationCalculator * pInstance) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateFactorizationCalculator"); + } + + if (pInstance == nullptr) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + ILibPrimesBaseClass* pBaseInstance(nullptr); + + pBaseInstance = CLibPrimesWrapper::CreateFactorizationCalculator(); + + *pInstance = (ILibPrimesBaseClass*)(pBaseInstance); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult ("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +LibPrimesResult libprimes_createsievecalculator (LibPrimes_SieveCalculator * pInstance) +{ + PLibPrimesInterfaceJournalEntry pJournalEntry; + try { + if (m_GlobalJournal.get() != nullptr) { + pJournalEntry = m_GlobalJournal->beginStaticFunction("CreateSieveCalculator"); + } + + if (pInstance == nullptr) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + ILibPrimesBaseClass* pBaseInstance(nullptr); + + pBaseInstance = CLibPrimesWrapper::CreateSieveCalculator(); + + *pInstance = (ILibPrimesBaseClass*)(pBaseInstance); + + if (pJournalEntry.get() != nullptr) { + pJournalEntry->addHandleResult ("Instance", *pInstance); + pJournalEntry->writeSuccess(); + } + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(E.getErrorCode()); + return E.getErrorCode(); + } + catch (...) { + if (pJournalEntry.get() != nullptr) + pJournalEntry->writeError(LIBPRIMES_ERROR_GENERICEXCEPTION); + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +LibPrimesResult libprimes_setjournal (const char * pFileName) +{ + try { + if (pFileName == nullptr) + throw ELibPrimesInterfaceException (LIBPRIMES_ERROR_INVALIDPARAM); + + std::string sFileName(pFileName); + + m_GlobalJournal = nullptr; + if (sFileName != "") { + m_GlobalJournal = std::make_shared (sFileName); + } + + + return LIBPRIMES_SUCCESS; + } + catch (ELibPrimesInterfaceException & E) { + return E.getErrorCode(); + } + catch (...) { + return LIBPRIMES_ERROR_GENERICEXCEPTION; + } +} + +} + diff --git a/Examples/Primes/LibPrimes_component/Bindings/C/libprimes_types.h b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_types.h similarity index 93% rename from Examples/Primes/LibPrimes_component/Bindings/C/libprimes_types.h rename to Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_types.h index 92b19290..2b14eea7 100644 --- a/Examples/Primes/LibPrimes_component/Bindings/C/libprimes_types.h +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Interfaces/libprimes_types.h @@ -1,15 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated plain C Header file with basic types in -order to allow an easy use of Prime Numbers Interface +order to allow an easy use of Prime Numbers Library -Interface version: 1.3.0 +Interface version: 1.2.0 */ @@ -61,7 +61,7 @@ typedef void * LibPrimesHandle; **************************************************************************************************************************/ #define LIBPRIMES_VERSION_MAJOR 1 -#define LIBPRIMES_VERSION_MINOR 3 +#define LIBPRIMES_VERSION_MINOR 2 #define LIBPRIMES_VERSION_MICRO 0 /************************************************************************************************************************* @@ -76,8 +76,9 @@ typedef void * LibPrimesHandle; #define LIBPRIMES_ERROR_GENERICEXCEPTION 5 #define LIBPRIMES_ERROR_COULDNOTLOADLIBRARY 6 #define LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT 7 -#define LIBPRIMES_ERROR_NORESULTAVAILABLE 8 -#define LIBPRIMES_ERROR_CALCULATIONABORTED 9 +#define LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION 8 +#define LIBPRIMES_ERROR_NORESULTAVAILABLE 9 +#define LIBPRIMES_ERROR_CALCULATIONABORTED 10 /************************************************************************************************************************* Declaration of handle classes diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes.cpp index dc0d9c46..5d0b0757 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes.cpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes.cpp @@ -1,12 +1,15 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + Abstract: This is an autogenerated C++ implementation file in order to allow easy -development of Prime Numbers Interface. It needs to be generated only once. -Interface version: 1.0.0 +development of Prime Numbers Library. It needs to be generated only once. + +Interface version: 1.2.0 */ @@ -17,7 +20,7 @@ Interface version: 1.0.0 #include "libprimes_factorizationcalculator.hpp" #include "libprimes_sievecalculator.hpp" -using namespace LibPrimes; +using namespace LibPrimes::Impl; ILibPrimesFactorizationCalculator * CLibPrimesWrapper::CreateFactorizationCalculator () { diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.cpp index 85cb285b..94b6d391 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.cpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.cpp @@ -1,6 +1,6 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. @@ -14,7 +14,7 @@ Abstract: This is a stub class definition of CLibPrimesCalculator // Include custom headers here. -using namespace LibPrimes; +using namespace LibPrimes::Impl; /************************************************************************************************************************* Class definition of CLibPrimesCalculator @@ -27,12 +27,12 @@ CLibPrimesCalculator::CLibPrimesCalculator() } -unsigned long long CLibPrimesCalculator::GetValue() +LibPrimes_uint64 CLibPrimesCalculator::GetValue() { return m_value; } -void CLibPrimesCalculator::SetValue(const unsigned long long nValue) +void CLibPrimesCalculator::SetValue(const LibPrimes_uint64 nValue) { m_value = nValue; } @@ -42,4 +42,3 @@ void CLibPrimesCalculator::SetProgressCallback (const LibPrimesProgressCallback m_Callback = pProgressCallback; } - diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.hpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.hpp index a7d08109..121b1789 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.hpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_calculator.hpp @@ -1,6 +1,6 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. @@ -19,6 +19,7 @@ Abstract: This is the class declaration of CLibPrimesCalculator namespace LibPrimes { +namespace Impl { /************************************************************************************************************************* @@ -30,7 +31,7 @@ class CLibPrimesCalculator : public virtual ILibPrimesCalculator { protected: - unsigned long long m_value; + LibPrimes_uint64 m_value; LibPrimesProgressCallback m_Callback; public: @@ -43,15 +44,16 @@ class CLibPrimesCalculator : public virtual ILibPrimesCalculator { /** * Public member functions to implement. */ - unsigned long long GetValue(); + LibPrimes_uint64 GetValue(); - void SetValue(const unsigned long long nValue); + void SetValue(const LibPrimes_uint64 nValue); void SetProgressCallback (const LibPrimesProgressCallback pProgressCallback); virtual void Calculate () = 0; }; -} +} // namespace Impl +} // namespace LibPrimes #endif // __LIBPRIMES_LIBPRIMESCALCULATOR diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.cpp index e517aa14..6f9d1a49 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.cpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.cpp @@ -1,6 +1,6 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. @@ -14,7 +14,7 @@ Abstract: This is a stub class definition of CLibPrimesFactorizationCalculator // Include custom headers here. -using namespace LibPrimes; +using namespace LibPrimes::Impl; /************************************************************************************************************************* Class definition of CLibPrimesFactorizationCalculator @@ -24,8 +24,8 @@ void CLibPrimesFactorizationCalculator::Calculate() { primeFactors.clear(); - unsigned long long nValue = m_value; - for (unsigned long long i = 2; i <= nValue; i++) { + LibPrimes_uint64 nValue = m_value; + for (LibPrimes_uint64 i = 2; i <= nValue; i++) { if (m_Callback) { bool shouldAbort = false; @@ -66,8 +66,3 @@ void CLibPrimesFactorizationCalculator::GetPrimeFactors (LibPrimes_uint64 nPrime } } -bool CLibPrimesFactorizationCalculator::CheckPrimeFactors(const LibPrimes_uint64 nPrimeFactorsBufferSize, const sLibPrimesPrimeFactor * pPrimeFactorsBuffer) -{ - throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_NOTIMPLEMENTED); -} - diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.hpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.hpp index 5f5d6e70..c1f61b12 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.hpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.hpp @@ -1,6 +1,6 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. @@ -23,10 +23,11 @@ Abstract: This is the class declaration of CLibPrimesFactorizationCalculator #include namespace LibPrimes { +namespace Impl { /************************************************************************************************************************* - Class declaration of CLibPrimesFactorizationCalculator + Class declaration of CLibPrimesFactorizationCalculator **************************************************************************************************************************/ class CLibPrimesFactorizationCalculator : public virtual ILibPrimesFactorizationCalculator, public virtual CLibPrimesCalculator { @@ -52,12 +53,12 @@ class CLibPrimesFactorizationCalculator : public virtual ILibPrimesFactorization * Public member functions to implement. */ - void GetPrimeFactors (LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64 * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); + void GetPrimeFactors(LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64* pPrimeFactorsNeededCount, sLibPrimesPrimeFactor* pPrimeFactorsBuffer); - bool CheckPrimeFactors (const LibPrimes_uint64 nPrimeFactorsBufferSize, const sLibPrimesPrimeFactor * pPrimeFactorsBuffer); }; -} +} // namespace Impl +} // namespace LibPrimes #pragma warning( pop ) #endif // __LIBPRIMES_LIBPRIMESFACTORIZATIONCALCULATOR diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp index 71886609..6f17111c 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.cpp @@ -1,6 +1,6 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. @@ -15,7 +15,7 @@ Abstract: This is a stub class definition of CLibPrimesSieveCalculator #include -using namespace LibPrimes; +using namespace LibPrimes::Impl; /************************************************************************************************************************* Class definition of CLibPrimesSieveCalculator diff --git a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.hpp b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.hpp index b708e4e4..c75920e4 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.hpp +++ b/Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_sievecalculator.hpp @@ -1,6 +1,6 @@ /*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. @@ -24,7 +24,7 @@ Abstract: This is the class declaration of CLibPrimesSieveCalculator #include namespace LibPrimes { - +namespace Impl { /************************************************************************************************************************* Class declaration of CLibPrimesSieveCalculator @@ -49,11 +49,12 @@ class CLibPrimesSieveCalculator : public virtual ILibPrimesSieveCalculator, publ * Public member functions to implement. */ - void GetPrimes (LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64 * pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer); + void GetPrimes (LibPrimes_uint64 nPrimesBufferSize, LibPrimes_uint64* pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer); }; -} +} // namespace Impl +} // namespace LibPrimes #pragma warning( pop ) #endif // __LIBPRIMES_LIBPRIMESSIEVECALCULATOR diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes.lpr b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes.lpr index cbd3c5f5..41b81dd2 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes.lpr +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes.lpr @@ -1,15 +1,15 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated Pascal project file in order to allow easy -development of Prime Numbers Interface. +development of Prime Numbers Library. -Interface version: 1.3.0 +Interface version: 1.2.0 *) @@ -29,15 +29,14 @@ exports libprimes_calculator_getvalue, libprimes_calculator_setvalue, - libprimes_calculator_setprogresscallback, libprimes_calculator_calculate, + libprimes_calculator_setprogresscallback, libprimes_factorizationcalculator_getprimefactors, - libprimes_factorizationcalculator_checkprimefactors, libprimes_sievecalculator_getprimes, - libprimes_createfactorizationcalculator, - libprimes_createsievecalculator, libprimes_releaseinstance, libprimes_getlibraryversion, + libprimes_createfactorizationcalculator, + libprimes_createsievecalculator, libprimes_setjournal; begin diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exception.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exception.pas index 6afa6a3e..0195a43e 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exception.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exception.pas @@ -1,15 +1,15 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated Pascal exception class definition file in order to allow easy -development of Prime Numbers Interface. The functions in this file need to be implemented. It needs to be generated only once. +development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once. -Interface version: 1.3.0 +Interface version: 1.2.0 *) @@ -51,13 +51,14 @@ implementation LIBPRIMES_ERROR_GENERICEXCEPTION: ADescription := 'a generic exception occurred'; LIBPRIMES_ERROR_COULDNOTLOADLIBRARY: ADescription := 'the library could not be loaded'; LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT: ADescription := 'a required exported symbol could not be found in the library'; + LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION: ADescription := 'the version of the binary interface does not match the bindings interface'; LIBPRIMES_ERROR_NORESULTAVAILABLE: ADescription := 'no result is available'; LIBPRIMES_ERROR_CALCULATIONABORTED: ADescription := 'a calculation has been aborted'; else ADescription := 'unknown'; end; - inherited Create (Format ('Prime Numbers Interface Error - %s (#%d)', [ ADescription, AErrorCode ])); + inherited Create (Format ('Prime Numbers Library Error - %s (#%d)', [ ADescription, AErrorCode ])); end; constructor ELibPrimesException.CreateCustomMessage (AErrorCode: TLibPrimesResult; AMessage: String); diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exports.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exports.pas index aca22b5f..8fbb0a30 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exports.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_exports.pas @@ -1,15 +1,15 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated Pascal export implementation file in order to allow easy -development of Prime Numbers Interface. The functions in this file need to be implemented. It needs to be generated only once. +development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once. -Interface version: 1.3.0 +Interface version: 1.2.0 *) @@ -49,28 +49,28 @@ function libprimes_calculator_getvalue (pCalculator: TLibPrimesHandle; pValue: P function libprimes_calculator_setvalue (pCalculator: TLibPrimesHandle; nValue: QWord): TLibPrimesResult; cdecl; (** -* Sets the progress callback function +* Performs the specific calculation of this Calculator * * @param[in] pCalculator - Calculator instance. -* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) *) -function libprimes_calculator_setprogresscallback (pCalculator: TLibPrimesHandle; pProgressCallback: PLibPrimes_ProgressCallback): TLibPrimesResult; cdecl; +function libprimes_calculator_calculate (pCalculator: TLibPrimesHandle): TLibPrimesResult; cdecl; (** -* Performs the specific calculation of this Calculator +* Sets the progress callback function * * @param[in] pCalculator - Calculator instance. +* @param[in] pProgressCallback - The progress callback * @return error code or 0 (success) *) -function libprimes_calculator_calculate (pCalculator: TLibPrimesHandle): TLibPrimesResult; cdecl; +function libprimes_calculator_setprogresscallback (pCalculator: TLibPrimesHandle; pProgressCallback: PLibPrimes_ProgressCallback): TLibPrimesResult; cdecl; (************************************************************************************************************************* Class export definition of FactorizationCalculator **************************************************************************************************************************) (** -* Returns the prime factors of this number (with multiplicity) +* Returns the prime factors of this number (without multiplicity) * * @param[in] pFactorizationCalculator - FactorizationCalculator instance. * @param[in] nPrimeFactorsCount - Number of elements in buffer @@ -80,17 +80,6 @@ function libprimes_calculator_calculate (pCalculator: TLibPrimesHandle): TLibPri *) function libprimes_factorizationcalculator_getprimefactors (pFactorizationCalculator: TLibPrimesHandle; nPrimeFactorsCount: QWord; pPrimeFactorsNeededCount: PQWord; pPrimeFactorsBuffer: PLibPrimesPrimeFactor): TLibPrimesResult; cdecl; -(** -* Checks, whether a list of prime factors (with multiplicity) is the prime factor decomposistion of the calculator's value -* -* @param[in] pFactorizationCalculator - FactorizationCalculator instance. -* @param[in] nPrimeFactorsCount - Number of elements in buffer -* @param[in] pPrimeFactorsBuffer - PrimeFactor buffer of -* @param[out] pAreEqual - Do the prime factors decompose this calculator's value -* @return error code or 0 (success) -*) -function libprimes_factorizationcalculator_checkprimefactors (pFactorizationCalculator: TLibPrimesHandle; nPrimeFactorsCount: QWord; pPrimeFactorsBuffer: PLibPrimesPrimeFactor; pAreEqual: PCardinal): TLibPrimesResult; cdecl; - (************************************************************************************************************************* Class export definition of SieveCalculator **************************************************************************************************************************) @@ -111,38 +100,38 @@ function libprimes_sievecalculator_getprimes (pSieveCalculator: TLibPrimesHandle **************************************************************************************************************************) (** -* Creates a new FactorizationCalculator instance +* Releases the memory of an Instance * -* @param[out] pInstance - New FactorizationCalculator instance +* @param[in] pInstance - Instance Handle * @return error code or 0 (success) *) -function libprimes_createfactorizationcalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; +function libprimes_releaseinstance (pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; (** -* Creates a new SieveCalculator instance +* retrieves the current version of the library. * -* @param[out] pInstance - New SieveCalculator instance +* @param[out] pMajor - returns the major version of the library +* @param[out] pMinor - returns the minor version of the library +* @param[out] pMicro - returns the micro version of the library * @return error code or 0 (success) *) -function libprimes_createsievecalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; +function libprimes_getlibraryversion (pMajor: PCardinal; pMinor: PCardinal; pMicro: PCardinal): TLibPrimesResult; cdecl; (** -* Releases the memory of an Instance +* Creates a new FactorizationCalculator instance * -* @param[in] pInstance - Instance Handle +* @param[out] pInstance - New FactorizationCalculator instance * @return error code or 0 (success) *) -function libprimes_releaseinstance (pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; +function libprimes_createfactorizationcalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; (** -* retrieves the current version of the library. +* Creates a new SieveCalculator instance * -* @param[out] pMajor - returns the major version of the library -* @param[out] pMinor - returns the minor version of the library -* @param[out] pMicro - returns the micro version of the library +* @param[out] pInstance - New SieveCalculator instance * @return error code or 0 (success) *) -function libprimes_getlibraryversion (pMajor: PCardinal; pMinor: PCardinal; pMicro: PCardinal): TLibPrimesResult; cdecl; +function libprimes_createsievecalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; (** * Handles Library Journaling @@ -214,7 +203,7 @@ function libprimes_calculator_setvalue (pCalculator: TLibPrimesHandle; nValue: Q end; end; -function libprimes_calculator_setprogresscallback (pCalculator: TLibPrimesHandle; pProgressCallback: PLibPrimes_ProgressCallback): TLibPrimesResult; cdecl; +function libprimes_calculator_calculate (pCalculator: TLibPrimesHandle): TLibPrimesResult; cdecl; var ObjectCalculator: TObject; IntfCalculator: ILibPrimesCalculator; @@ -226,7 +215,7 @@ function libprimes_calculator_setprogresscallback (pCalculator: TLibPrimesHandle ObjectCalculator := TObject (pCalculator); if Supports (ObjectCalculator, ILibPrimesCalculator) then begin IntfCalculator := ObjectCalculator as ILibPrimesCalculator; - IntfCalculator.SetProgressCallback(pProgressCallback); + IntfCalculator.Calculate(); end else raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDCAST); @@ -242,7 +231,7 @@ function libprimes_calculator_setprogresscallback (pCalculator: TLibPrimesHandle end; end; -function libprimes_calculator_calculate (pCalculator: TLibPrimesHandle): TLibPrimesResult; cdecl; +function libprimes_calculator_setprogresscallback (pCalculator: TLibPrimesHandle; pProgressCallback: PLibPrimes_ProgressCallback): TLibPrimesResult; cdecl; var ObjectCalculator: TObject; IntfCalculator: ILibPrimesCalculator; @@ -254,7 +243,7 @@ function libprimes_calculator_calculate (pCalculator: TLibPrimesHandle): TLibPri ObjectCalculator := TObject (pCalculator); if Supports (ObjectCalculator, ILibPrimesCalculator) then begin IntfCalculator := ObjectCalculator as ILibPrimesCalculator; - IntfCalculator.Calculate(); + IntfCalculator.SetProgressCallback(pProgressCallback); end else raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDCAST); @@ -300,40 +289,6 @@ function libprimes_factorizationcalculator_getprimefactors (pFactorizationCalcul end; end; -function libprimes_factorizationcalculator_checkprimefactors (pFactorizationCalculator: TLibPrimesHandle; nPrimeFactorsCount: QWord; pPrimeFactorsBuffer: PLibPrimesPrimeFactor; pAreEqual: PCardinal): TLibPrimesResult; cdecl; -var - ResultAreEqual: Boolean; - ObjectFactorizationCalculator: TObject; - IntfFactorizationCalculator: ILibPrimesFactorizationCalculator; -begin - try - if ((not Assigned (pPrimeFactorsBuffer)) and (nPrimeFactorsCount>0)) then - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); - if not Assigned (pAreEqual) then - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); - if not Assigned (pFactorizationCalculator) then - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); - - ObjectFactorizationCalculator := TObject (pFactorizationCalculator); - if Supports (ObjectFactorizationCalculator, ILibPrimesFactorizationCalculator) then begin - IntfFactorizationCalculator := ObjectFactorizationCalculator as ILibPrimesFactorizationCalculator; - ResultAreEqual := IntfFactorizationCalculator.CheckPrimeFactors(nPrimeFactorsCount, pPrimeFactorsBuffer); - - pAreEqual^ := Ord (ResultAreEqual); - end else - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDCAST); - - Result := LIBPRIMES_SUCCESS; - except - On E: ELibPrimesException do begin - Result := E.ErrorCode; - end; - On E: Exception do begin - Result := LIBPRIMES_ERROR_GENERICEXCEPTION; - end; - end; -end; - function libprimes_sievecalculator_getprimes (pSieveCalculator: TLibPrimesHandle; nPrimesCount: QWord; pPrimesNeededCount: PQWord; pPrimesBuffer: PQWord): TLibPrimesResult; cdecl; var ObjectSieveCalculator: TObject; @@ -364,17 +319,18 @@ function libprimes_sievecalculator_getprimes (pSieveCalculator: TLibPrimesHandle end; end; -function libprimes_createfactorizationcalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; +function libprimes_releaseinstance (pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; var - ResultInstance: TObject; + ObjectInstance: TObject; begin try - if not Assigned(pInstance) then - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); + ObjectInstance := TObject (pInstance); + if (not Supports (ObjectInstance, ILibPrimesBaseClass)) then + raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDCAST); + - ResultInstance := TLibPrimesWrapper.CreateFactorizationCalculator(); + TLibPrimesWrapper.ReleaseInstance(ObjectInstance); - pInstance^ := ResultInstance; Result := LIBPRIMES_SUCCESS; except On E: ELibPrimesException do begin @@ -386,17 +342,21 @@ function libprimes_createfactorizationcalculator (pInstance: PLibPrimesHandle): end; end; -function libprimes_createsievecalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; -var - ResultInstance: TObject; +function libprimes_getlibraryversion (pMajor: PCardinal; pMinor: PCardinal; pMicro: PCardinal): TLibPrimesResult; cdecl; begin try - if not Assigned(pInstance) then + if (not Assigned (pMajor)) then raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); - ResultInstance := TLibPrimesWrapper.CreateSieveCalculator(); + if (not Assigned (pMinor)) then + raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); + + if (not Assigned (pMicro)) then + raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); + + + TLibPrimesWrapper.GetLibraryVersion(pMajor^, pMinor^, pMicro^); - pInstance^ := ResultInstance; Result := LIBPRIMES_SUCCESS; except On E: ELibPrimesException do begin @@ -408,18 +368,17 @@ function libprimes_createsievecalculator (pInstance: PLibPrimesHandle): TLibPrim end; end; -function libprimes_releaseinstance (pInstance: TLibPrimesHandle): TLibPrimesResult; cdecl; +function libprimes_createfactorizationcalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; var - ObjectInstance: TObject; + ResultInstance: TObject; begin try - ObjectInstance := TObject (pInstance); - if (not Supports (ObjectInstance, ILibPrimesBaseClass)) then - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDCAST); - + if not Assigned(pInstance) then + raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); - TLibPrimesWrapper.ReleaseInstance(ObjectInstance); + ResultInstance := TLibPrimesWrapper.CreateFactorizationCalculator(); + pInstance^ := ResultInstance; Result := LIBPRIMES_SUCCESS; except On E: ELibPrimesException do begin @@ -431,21 +390,17 @@ function libprimes_releaseinstance (pInstance: TLibPrimesHandle): TLibPrimesResu end; end; -function libprimes_getlibraryversion (pMajor: PCardinal; pMinor: PCardinal; pMicro: PCardinal): TLibPrimesResult; cdecl; +function libprimes_createsievecalculator (pInstance: PLibPrimesHandle): TLibPrimesResult; cdecl; +var + ResultInstance: TObject; begin try - if (not Assigned (pMajor)) then - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); - - if (not Assigned (pMinor)) then - raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); - - if (not Assigned (pMicro)) then + if not Assigned(pInstance) then raise ELibPrimesException.Create (LIBPRIMES_ERROR_INVALIDPARAM); + ResultInstance := TLibPrimesWrapper.CreateSieveCalculator(); - TLibPrimesWrapper.GetLibraryVersion(pMajor^, pMinor^, pMicro^); - + pInstance^ := ResultInstance; Result := LIBPRIMES_SUCCESS; except On E: ELibPrimesException do begin diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_interfaces.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_interfaces.pas index 57e6da64..09728ad5 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_interfaces.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_interfaces.pas @@ -1,15 +1,15 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated Pascal interface definition file in order to allow easy -development of Prime Numbers Interface. The functions in this file need to be implemented. It needs to be generated only once. +development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once. -Interface version: 1.3.0 +Interface version: 1.2.0 *) @@ -44,8 +44,8 @@ interface function GetValue(): QWord; procedure SetValue(const AValue: QWord); - procedure SetProgressCallback(const AProgressCallback: PLibPrimes_ProgressCallback); procedure Calculate(); + procedure SetProgressCallback(const AProgressCallback: PLibPrimes_ProgressCallback); end; @@ -57,7 +57,6 @@ interface ['{81855AD8-681D-4D86-91E9-1E00167939CB}'] procedure GetPrimeFactors(const APrimeFactorsCount: QWord; PPrimeFactorsNeededCount: PQWord; APrimeFactors: PLibPrimesPrimeFactor); - function CheckPrimeFactors(const APrimeFactorsCount: QWord; const APrimeFactors: PLibPrimesPrimeFactor): Boolean; end; diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_types.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_types.pas index 0f6d4f16..f9829351 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_types.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Interfaces/libprimes_types.pas @@ -1,15 +1,15 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. -This file has been generated by the Automatic Component Toolkit (ACT) version 1.3.1. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. Abstract: This is an autogenerated Pascal type definition file in order to allow easy -development of Prime Numbers Interface. The functions in this file need to be implemented. It needs to be generated only once. +development of Prime Numbers Library. The functions in this file need to be implemented. It needs to be generated only once. -Interface version: 1.3.0 +Interface version: 1.2.0 *) @@ -28,7 +28,7 @@ interface const LIBPRIMES_VERSION_MAJOR = 1; - LIBPRIMES_VERSION_MINOR = 3; + LIBPRIMES_VERSION_MINOR = 2; LIBPRIMES_VERSION_MICRO = 0; @@ -56,8 +56,9 @@ interface LIBPRIMES_ERROR_GENERICEXCEPTION = 5; LIBPRIMES_ERROR_COULDNOTLOADLIBRARY = 6; LIBPRIMES_ERROR_COULDNOTFINDLIBRARYEXPORT = 7; - LIBPRIMES_ERROR_NORESULTAVAILABLE = 8; - LIBPRIMES_ERROR_CALCULATIONABORTED = 9; + LIBPRIMES_ERROR_INCOMPATIBLEBINARYVERSION = 8; + LIBPRIMES_ERROR_NORESULTAVAILABLE = 9; + LIBPRIMES_ERROR_CALCULATIONABORTED = 10; (************************************************************************************************************************* Declaration of structs @@ -82,7 +83,9 @@ interface Declaration of function types **************************************************************************************************************************) - PLibPrimes_ProgressCallback = function(const fProgressPercentage: Single; out pShouldAbort: Cardinal): Integer; +type + + PLibPrimes_ProgressCallback = function(const fProgressPercentage: Single; out pShouldAbort: Byte): Integer; cdecl; implementation diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl.pas index e1786742..5a929efa 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl.pas @@ -1,11 +1,14 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. +This file has been generated by the Automatic Component Toolkit (ACT) version 1.4.0. + Abstract: This is an autogenerated Pascal implementation file in order to allow easy -development of Prime Numbers Interface. It needs to be generated only once. +development of Prime Numbers Library. It needs to be generated only once. + Interface version: 1.2.0 *) diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_baseclass.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_baseclass.pas index b7743a6e..e7733694 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_baseclass.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_baseclass.pas @@ -1,6 +1,6 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_calculator.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_calculator.pas index 2852c346..9264f107 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_calculator.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_calculator.pas @@ -1,6 +1,6 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_factorizationcalculator.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_factorizationcalculator.pas index b53efaae..d84acbac 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_factorizationcalculator.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_factorizationcalculator.pas @@ -1,6 +1,6 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. @@ -29,7 +29,6 @@ TLibPrimesFactorizationCalculator = class (TLibPrimesCalculator, ILibPrimesFact public procedure GetPrimeFactors(const APrimeFactorsCount: QWord; PPrimeFactorsNeededCount: PQWord; APrimeFactors: PLibPrimesPrimeFactor); - function CheckPrimeFactors(const APrimeFactorsCount: QWord; const APrimeFactors: PLibPrimesPrimeFactor): Boolean; procedure Calculate(); override; destructor Destroy(); override; end; @@ -60,11 +59,6 @@ procedure TLibPrimesFactorizationCalculator.GetPrimeFactors(const APrimeFactorsC end; end; -function TLibPrimesFactorizationCalculator.CheckPrimeFactors(const APrimeFactorsCount: QWord; const APrimeFactors: PLibPrimesPrimeFactor): Boolean; -begin - raise ELibPrimesException.Create(LIBPRIMES_ERROR_NOTIMPLEMENTED); -end; - procedure TLibPrimesFactorizationCalculator.Calculate(); var AValue: QWord; diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_sievecalculator.pas b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_sievecalculator.pas index 2d647597..24e480fa 100644 --- a/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_sievecalculator.pas +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/Stub/libprimes_impl_sievecalculator.pas @@ -1,6 +1,6 @@ (*++ -Copyright (C) 2018 Automatic Component Toolkit Developers +Copyright (C) 2018 PrimeDevelopers All rights reserved. diff --git a/Examples/Primes/LibPrimes_component/Implementations/Pascal/libprimes.def b/Examples/Primes/LibPrimes_component/Implementations/Pascal/libprimes.def new file mode 100644 index 00000000..babde722 --- /dev/null +++ b/Examples/Primes/LibPrimes_component/Implementations/Pascal/libprimes.def @@ -0,0 +1,12 @@ +EXPORTS +libprimes_releaseinstance +libprimes_getlibraryversion +libprimes_createfactorizationcalculator +libprimes_createsievecalculator +libprimes_setjournal +libprimes_calculator_getvalue +libprimes_calculator_setvalue +libprimes_calculator_calculate +libprimes_calculator_setprogresscallback +libprimes_factorizationcalculator_getprimefactors +libprimes_sievecalculator_getprimes diff --git a/Examples/Primes/LibPrimes_component/license.txt b/Examples/Primes/LibPrimes_component/license.txt new file mode 100644 index 00000000..f0a7288b --- /dev/null +++ b/Examples/Primes/LibPrimes_component/license.txt @@ -0,0 +1,5 @@ +Copyright (C) 2018 PrimeDevelopers + +All rights reserved. + + diff --git a/Examples/Primes/PrimeUser/main.cpp b/Examples/Primes/PrimeUser/main.cpp deleted file mode 100644 index 1d478f1a..00000000 --- a/Examples/Primes/PrimeUser/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "libprimes_dynamic.hpp" -#include - - -void progressCallback(float progress, bool *shouldAbort) -{ - std::cout << "Progress = " << round(progress * 100) << std::endl; - if (shouldAbort) { - *shouldAbort = false; - } -} - -void progressCallbackCancel(float progress, bool *shouldAbort) -{ - std::cout << "Progress = " << round(progress * 100) << std::endl; - if (shouldAbort) { - *shouldAbort = progress > 0.5f; - } -} - - -void calculatePrimes(LibPrimes::CLibPrimesWrapper& wrapper, const unsigned long long number) { - auto sieve = wrapper.CreateSieveCalculator(); - - sieve->SetValue(number); - - std::cout << "Calculate using a cancelling callback" << std::endl; - try { - sieve->SetProgressCallback(progressCallbackCancel); - sieve->Calculate(); - } - catch (LibPrimes::ELibPrimesException &e) { - if (e.getErrorCode() == LIBPRIMES_ERROR_CALCULATIONABORTED) { - std::cout << "Calculation aborted" << std::endl; - } - else - throw e; - } - - std::cout << "Calculate using a noncancelling callback" << std::endl; - sieve->SetProgressCallback(progressCallback); - sieve->Calculate(); - - std::vector primes(0); - sieve->GetPrimes(primes); - - std::cout << "Primes <= " << number << ":" << std::endl; - for (size_t i = 0; i < primes.size(); i++) { - std::cout << primes[i] << " "; - } - std::cout << std::endl; -} - -void factorize(LibPrimes::CLibPrimesWrapper& wrapper, const unsigned long long number) { - auto factorisation = wrapper.CreateFactorizationCalculator(); - - factorisation->SetValue(number); - factorisation->Calculate(); - - std::vector primeFactors(0); - factorisation->GetPrimeFactors(primeFactors); - - std::cout << factorisation->GetValue() << " = "; - for (size_t i = 0; i < primeFactors.size(); i++) { - auto pF = primeFactors[i]; - std::cout << pF.m_Prime << "^" << pF.m_Multiplicity << ((i < (primeFactors.size() - 1)) ? " * " : ""); - } - std::cout << std::endl; -} - -int main() -{ - try { - auto wrapper = LibPrimes::CLibPrimesWrapper::loadLibrary("LibPrimes.dll"); - factorize(*wrapper.get(), 3 * 3 * 17 * 17); - calculatePrimes(*wrapper.get(), 100); - } - catch (std::exception &e) { - std::cout << e.what() << std::endl; - return -1; - } - - return 0; -} \ No newline at end of file diff --git a/Examples/Primes/Tutorial.md b/Examples/Primes/Tutorial.md index 4c4ab4c9..d141b217 100644 --- a/Examples/Primes/Tutorial.md +++ b/Examples/Primes/Tutorial.md @@ -37,15 +37,15 @@ _There are much more efficient algorithms and more suitable software packages to # 2. Requirements - CMake - - A C++ compiler / development environment. This tutorial was tested with Visual Studio 2017, but should also work with GCC and make - - ACT: This tutorial is tested to work with release 1.1.0 of ACT. You can get it from [the release page](https://github.com/Autodesk/AutomaticComponentToolkit/releases). -Decide on a location for your tutorial's component to live in, and download the binary for your platform into this folder. + - A C++ compiler / development environment. This tutorial was tested with Visual Studio 2017, but should also work with `GCC` and `make` or other development tools. + - ACT: This tutorial is tested to work with release 1.4.0 of ACT. You can get it from [the releases page](https://github.com/Autodesk/AutomaticComponentToolkit/releases). +Decide on a location for your tutorial's component to live in, and download the binary for your platform into this folder. Alternatively, stick it somwhere in your `$PATH`. # 3. The Library's Implementation ## 3.1. The definition of the component An ACT component's interface is fully described by its IDL file. -This section sets up a IDL-file for LibPrimes. +This section sets up an IDL-file for LibPrimes. First, copy the snippet, a bare-bone IDL-file, and save it into libPrimes.xml in your component's folder. ```xml @@ -64,8 +64,8 @@ First, copy the snippet, a bare-bone IDL-file, and save it into libPrimes.xml in - - + + @@ -76,6 +76,7 @@ First, copy the snippet, a bare-bone IDL-file, and save it into libPrimes.xml in + @@ -98,7 +99,7 @@ It's elements define the following: The errors listed in this snippet are required. -`\` defines the global functions that can be used as entry points into the component. It must contain a `versionmethod` and a `releasemethod` with the signatures in this snippet. -They will be explained in [](). +They will be explained in [this section](#331-required-steps-for-every-act-component). The syntax for methods will be explained when we add new classes and functions to the IDL-file now. @@ -158,7 +159,7 @@ Again, we will implement the actual calculation of primes by overwriting the the We want to use the error `LIBPRIMES_ERROR_NORESULTAVAILABLE` when a user tries to retrieve results from a calculator without having performed a calculation before. Thus add a new error ```xml - + ``` @@ -203,14 +204,14 @@ the interfaces `ILibPrimesCalculator` and `ILibPrimesFactorizationCalculator`: /*...*/ class ILibPrimesCalculator : public virtual ILibPrimesBaseClass { public: - virtual unsigned long long GetValue () = 0; - virtual void SetValue (const unsigned long long nValue) = 0; + virtual LibPrimes_uint64 long GetValue () = 0; + virtual void SetValue (const LibPrimes_uint64 nValue) = 0; virtual void Calculate () = 0; }; class ILibPrimesFactorizationCalculator : public virtual ILibPrimesBaseClass, public virtual ILibPrimesCalculator { public: - virtual void GetPrimeFactors (unsigned int nPrimeFactorsBufferSize, unsigned int * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) = 0; + virtual void GetPrimeFactors (LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64 * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) = 0; }; /*...*/ ``` @@ -220,7 +221,7 @@ The `libprimes_interfaceexception.hpp` and `libprimes_interfaceexception.cpp` fi The `libprimes_interfacewrapper.cpp` file implements the forwarding of the C89-interface functions to the classes you will implement. It also translates all exceptions into error codes. ```cpp -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calculator pCalculator, unsigned long long * pValue) +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue) { try { if (pValue == nullptr) @@ -254,14 +255,14 @@ They contain a concrete class definition derived from the corresponding interfac class CLibPrimesFactorizationCalculator : public virtual ILibPrimesFactorizationCalculator, public virtual CLibPrimesCalculator { public: void Calculate(); - void GetPrimeFactors (unsigned int nPrimeFactorsBufferSize, unsigned int * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); + void GetPrimeFactors (LibPrimes_uint64 nPrimeFactorsBufferSize, LibPrimes_uint64 * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer); }; ``` The autogenerated implementation of each of a class's methods throws a `NOTIMPLEMENTED` exception: ```cpp -void CLibPrimesFactorizationCalculator::GetPrimeFactors (unsigned int nPrimeFactorsBufferSize, - unsigned int * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) +void CLibPrimesFactorizationCalculator::GetPrimeFactors (LibPrimes_uint64 nPrimeFactorsBufferSize, + LibPrimes_uint64 * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) { throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_NOTIMPLEMENTED); } @@ -275,7 +276,7 @@ The following code snipped sets up a Visual Studio solution: cd LibPrimes_component/Implementation/ mkdir _build cd _build -cmake .. -G "Visual Studio 14 Win64" +cmake .. -G "Visual Studio 15 Win64" cmake --build . ``` Adjust the CMake-Generator for your development environment, if required. @@ -285,7 +286,7 @@ Now we can start actually implementing the library. ### 3.3.1. Required steps for every ACT component #### GetVersion function ```cpp -void CLibPrimesWrapper::GetLibraryVersion (unsigned int & nMajor, unsigned int & nMinor, unsigned int & nMicro) +void CLibPrimesWrapper::GetLibraryVersion (LibPrimes_uint32 & nMajor, LibPrimes_uint32 & nMinor, LibPrimes_uint32 & nMicro) { nMajor = LIBPRIMES_VERSION_MAJOR; nMinor = LIBPRIMES_VERSION_MINOR; @@ -336,18 +337,18 @@ Add a protected member `m_value` to the `CLibPrimesCalculator` ```cpp class CLibPrimesCalculator : public virtual ILibPrimesCalculator { protected: - unsined long long m_value; + LibPrimes_uint64 m_value; /*...*/ } ``` The `GetValue`/`SetValue` methods of the `Calculator` are straight-forward: ```cpp -unsigned long long CLibPrimesCalculator::GetValue() +LibPrimes_uint64 CLibPrimesCalculator::GetValue() { return m_value; } -void CLibPrimesCalculator::SetValue(const unsigned long long nValue) +void CLibPrimesCalculator::SetValue(const LibPrimes_uint64 nValue) { m_value = nValue; } @@ -372,8 +373,8 @@ public: A valid implementation of `GetPrimes` is the following ```cpp -void CLibPrimesFactorizationCalculator::GetPrimeFactors (unsigned int nPrimeFactorsBufferSize, - unsigned int * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) +void CLibPrimesFactorizationCalculator::GetPrimeFactors (LibPrimes_uint64 nPrimeFactorsBufferSize, + LibPrimes_uint64 * pPrimeFactorsNeededCount, sLibPrimesPrimeFactor * pPrimeFactorsBuffer) { if (primeFactors.size() == 0) throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_NORESULTAVAILABLE); @@ -397,8 +398,8 @@ void CLibPrimesFactorizationCalculator::Calculate() { primeFactors.clear(); - unsigned long long nValue = m_value; - for (unsigned long long i = 2; i <= nValue; i++) { + LibPrimes_uint64 nValue = m_value; + for (LibPrimes_uint64 i = 2; i <= nValue; i++) { sLibPrimesPrimeFactor primeFactor; primeFactor.m_Prime = i; primeFactor.m_Multiplicity = 0; @@ -419,7 +420,7 @@ and a public `Calculate` method: ```cpp class CLibPrimesSieveCalculator : public virtual ILibPrimesSieveCalculator, public virtual CLibPrimesCalculator { private: - std::vector primes; + std::vector primes; public: void Calculate(); /*...*/ @@ -429,12 +430,12 @@ public: The `GetPrimes` method is analogous to the above `GetPrimeFactors` ```cpp void CLibPrimesSieveCalculator::GetPrimes (unsigned int nPrimesBufferSize, - unsigned int * pPrimesNeededCount, unsigned long long * pPrimesBuffer) + LibPrimes_uint64 * pPrimesNeededCount, LibPrimes_uint64 * pPrimesBuffer) { if (primes.size() == 0) throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_NORESULTAVAILABLE); if (pPrimesNeededCount) - *pPrimesNeededCount = (unsigned int)primes.size(); + *pPrimesNeededCount = (LibPrimes_uint64)primes.size(); if (nPrimesBufferSize >= primes.size() && pPrimesBuffer) { for (int i = 0; i < primes.size(); i++) @@ -452,19 +453,19 @@ void CLibPrimesSieveCalculator::Calculate() primes.clear(); std::vector strikenOut(m_value + 1); - for (unsigned long long i = 0; i <= m_value; i++) { + for (LibPrimes_uint64 i = 0; i <= m_value; i++) { strikenOut[i] = i < 2; } - unsigned long sqrtValue = (unsigned long)(sqrt(m_value)); - for (unsigned long long i = 2; i <= sqrtValue; i++) { + LibPrimes_uint64 sqrtValue = (LibPrimes_uint64)(sqrt(m_value)); + for (LibPrimes_uint64 i = 2; i <= sqrtValue; i++) { if (!strikenOut[i]) { primes.push_back(i); - for (unsigned long long j = i * i; j < m_value; j += i) { + for (LibPrimes_uint64 j = i * i; j < m_value; j += i) { strikenOut[j] = true; } } } - for (unsigned long long i = sqrtValue; i <= m_value; i++) { + for (LibPrimes_uint64 i = sqrtValue; i <= m_value; i++) { if (!strikenOut[i]) { primes.push_back(i); } @@ -489,7 +490,7 @@ Generate a solution and build it cd LibPrimes_component/Examples/CppDynamic mkdir _build cd _build -cmake .. -G "Visual Studio 14 Win64" +cmake .. -G "Visual Studio 15 Win64" ``` You will have to modify the path to the binary library file we created in section [3. The Library's Implementation](#3-the-librarys-implementation). ```cpp @@ -498,20 +499,20 @@ You will have to modify the path to the binary library file we created in sectio int main() { - try - { - std::string libpath = (""); // TODO: put the location of the LibPrimes-library file here. - auto wrapper = LibPrimes::CLibPrimesWrapper::loadLibrary(libpath + "/libprimes"); - unsigned int nMajor, nMinor, nMicro; - wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); - std::cout << "LibPrimes.Version = " << nMajor << "." << nMinor << "." << nMicro << std::endl; - } - catch (std::exception &e) - { - std::cout << e.what() << std::endl; - return 1; - } - return 0; + try + { + std::string libpath = (""); // TODO: put the location of the LibPrimes-library file here. + auto wrapper = LibPrimes::CLibPrimesWrapper::loadLibrary(libpath + "/libprimes."); // TODO: add correct suffix of the library + unsigned int nMajor, nMinor, nMicro; + wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); + std::cout << "LibPrimes.Version = " << nMajor << "." << nMinor << "." << nMicro << std::endl; + } + catch (std::exception &e) + { + std::cout << e.what() << std::endl; + return 1; + } + return 0; } ``` Now build the solution @@ -550,8 +551,8 @@ e.g. a C++ function call is forwarded to the C-interface as follows ```cpp void GetPrimeFactors (std::vector & PrimeFactorsBuffer) { - unsigned int elementsNeededPrimeFactors = 0; - unsigned int elementsWrittenPrimeFactors = 0; + LibPrimes_uint64 elementsNeededPrimeFactors = 0; + LibPrimes_uint64 elementsWrittenPrimeFactors = 0; CheckError ( m_pWrapper->m_WrapperTable.m_FactorizationCalculator_GetPrimeFactors (m_pHandle, 0, &elementsNeededPrimeFactors, nullptr) ); PrimeFactorsBuffer.resize(elementsNeededPrimeFactors); CheckError ( m_pWrapper->m_WrapperTable.m_FactorizationCalculator_GetPrimeFactors (m_pHandle, elementsNeededPrimeFactors, &elementsWrittenPrimeFactors, PrimeFactorsBuffer.data()) ); @@ -711,7 +712,7 @@ Then add a method to the `Calculator` class that sets the progress callback: We will handle aborted calculations via a new exceptions, which a client can handle. Thus, add a new `\`: ```xml - + ``` In the [semantic versioning scheme](https://semver.org/), which is advocated by ACT, adding a new function to a components class @@ -736,7 +737,7 @@ function type and their usage is declared: /************************************************************************************************************************* Declaration of function pointers **************************************************************************************************************************/ -typedef void(*LibPrimesProgressCallback)(float, bool*); +typedef void(*LibPrimesProgressCallback)(LibPrimes_single, bool*); ``` ```cpp class ILibPrimesCalculator : public virtual ILibPrimesBaseClass { @@ -784,8 +785,8 @@ void CLibPrimesFactorizationCalculator::Calculate() { primeFactors.clear(); - unsigned long long nValue = m_value; - for (unsigned long long i = 2; i <= nValue; i++) { + LibPrimes_uint64 nValue = m_value; + for (LibPrimes_uint64 i = 2; i <= nValue; i++) { if (m_Callback) { bool shouldAbort = false; @@ -824,7 +825,7 @@ as their respective language bindings have already been updated at the end of st Open the solution from [Section 4.1](#41-cpp-dynamic), and add a concrete implementation of the "LibPrimesProgressCallback" function-type: ```cpp -void progressCallback(float progress, bool* shouldAbort) +void progressCallback(LibPrimes_single progress, bool* shouldAbort) { std::cout << "Progress = " << round(progress * 100) << "%" << std::endl; if (shouldAbort) { @@ -851,9 +852,9 @@ LibPrimes.Version = 1.1.0 Progress = 0% Progress = 0% Progress = 67% -LibPrimes Error 9 +LibPrimes Error 10 ``` -Error 9 (`CALCULATIONABORTED`) notifies us that a calculation has been aborted, as we expected. +Error 10 (`CALCULATIONABORTED`) notifies us that a calculation has been aborted, as we expected. ## 5.3.2 Python Application with a callback Open the Python example from [Section 4.2](42-python), and add an implementation of the @@ -862,7 +863,7 @@ a Python function: def progressCallback(progress, shouldAbort): print("Progress = {:d}%".format(round(progress*100))) if (shouldAbort is not None): - shouldAbort[0] = progress > 0.5; + shouldAbort[0] = progress > 0.5 ``` Using it in `main` requires one to first create a CTypes function pointer `cTypesCallback` to the Python function. @@ -883,7 +884,7 @@ LibPrimes version: 1.1.0 Progress = 0% Progress = 0% Progress = 67% -LibPrimesException 9 +LibPrimesException 10 ``` # 6. Enable journaling @@ -944,7 +945,7 @@ in the wrapper itself._ This is how the journal is filled by other methods: ```cpp -LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calculator pCalculator, unsigned long long * pValue) +LIBPRIMES_DECLSPEC LibPrimesResult libprimes_calculator_getvalue (LibPrimes_Calculator pCalculator, LibPrimes_uint64 * pValue) { PLibPrimesInterfaceJournalEntry pJournalEntry; try { diff --git a/Examples/Primes/libPrimes.xml b/Examples/Primes/libPrimes.xml index 8512c97d..373ecc42 100644 --- a/Examples/Primes/libPrimes.xml +++ b/Examples/Primes/libPrimes.xml @@ -1,22 +1,20 @@ + libraryname="Prime Numbers Library" namespace="LibPrimes" copyright="PrimeDevelopers" year="2018" basename="libprimes" + version="1.2.0"> - - - - + + @@ -27,8 +25,9 @@ - - + + + @@ -49,23 +48,19 @@ - - - - + + + + - + - - - - @@ -74,15 +69,7 @@ - - - - - - - - - + @@ -93,9 +80,16 @@ + + + + + + + + - - + \ No newline at end of file diff --git a/Examples/Primes/ressources/310/libPrimes.xml b/Examples/Primes/ressources/310/libPrimes.xml new file mode 100644 index 00000000..c0d12208 --- /dev/null +++ b/Examples/Primes/ressources/310/libPrimes.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Examples/Primes/ressources/315/libPrimes.xml b/Examples/Primes/ressources/315/libPrimes.xml index cf3ff707..c9fde167 100644 --- a/Examples/Primes/ressources/315/libPrimes.xml +++ b/Examples/Primes/ressources/315/libPrimes.xml @@ -1,22 +1,20 @@ - - - - + + @@ -27,7 +25,8 @@ - + + @@ -61,14 +60,6 @@ - - - - - - - - @@ -78,6 +69,13 @@ - - + + + + + + + + + \ No newline at end of file diff --git a/Examples/Primes/ressources/510/libPrimes.xml b/Examples/Primes/ressources/510/libPrimes.xml index 5347f3a3..4a0b6699 100644 --- a/Examples/Primes/ressources/510/libPrimes.xml +++ b/Examples/Primes/ressources/510/libPrimes.xml @@ -1,22 +1,20 @@ - - - - + + @@ -27,8 +25,9 @@ - - + + + @@ -36,7 +35,7 @@ - + @@ -49,13 +48,13 @@ - - - - + + + + @@ -71,14 +70,6 @@ - - - - - - - - @@ -88,6 +79,13 @@ - - + + + + + + + + + \ No newline at end of file diff --git a/Examples/Primes/ressources/610/libPrimes.xml b/Examples/Primes/ressources/610/libPrimes.xml index aec4062e..373ecc42 100644 --- a/Examples/Primes/ressources/610/libPrimes.xml +++ b/Examples/Primes/ressources/610/libPrimes.xml @@ -1,22 +1,20 @@ - - - - + + @@ -27,8 +25,9 @@ - - + + + @@ -36,7 +35,7 @@ - + @@ -49,13 +48,13 @@ - - - - + + + + @@ -70,15 +69,7 @@ - - - - - - - - - + @@ -89,9 +80,16 @@ + + + + + + + + - - + \ No newline at end of file diff --git a/README.md b/README.md index 95f0e494..c0f883b3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ # Automatic Component Toolkit +[![Build Status](https://travis-ci.org/Autodesk/AutomaticComponentToolkit.svg?branch=develop)](https://travis-ci.org/Autodesk/AutomaticComponentToolkit) + The Automatic Component Toolkit (ACT) is a code generator that takes an instance of an [Interface Description Language](#interface-description-language-idl) file and generates a [thin C89-API](#thin-c89-api), [implementation stubs](#implementation-stubs) and [language bindings](#language-bindings) of your desired software component. @@ -38,10 +40,10 @@ Alternatively to 1) build ACT from source ([master](../../tree/master) for a rel ## Contributing The Automatic Component Toolkit is an open source project. -Contributions are welcome and we are looking for people that can improve existing language bindings or create new bindings or implementation stubs. Have a look the [contributor's guide](CONTRIBUTING.md) for details. +Contributions are welcome and we are looking for people that can improve existing language bindings or create new bindings or implementation stubs. Have a look at the [contributor's guide](CONTRIBUTING.md) for details. ## Language Support -ACT supports generation of bindings or implementation stubs for C++, C, Pascal, Golang, NodeJS and Python. However, not all features of the IDL are yet supported by the individual binding or implementation language: +ACT supports generation of bindings or implementation stubs for C++, C, Pascal, Golang, NodeJS and Python3. However, not all features of the IDL are yet supported by the individual binding or implementation language: #### Feature Matrix: Bindings | Binding | Status | Operating Systems | class | scalar type | struct | enumeration | string | basicarray | structarray | Callbacks | @@ -51,7 +53,7 @@ ACT supports generation of bindings or implementation stubs for C++, C, Pascal, | C | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | | C Dynamic | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | | Pascal | ![](Documentation/images/Tick.png) mature | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | -| Python | ![](Documentation/images/Tick.png) complete (but unstable) | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | +| Python3 | ![](Documentation/images/Tick.png) complete (but unstable) | Win, Linux, MacOS | in,return | in,out,return | in,out,return | in,out,return | in,out,return | in,out | in,out | in | | Golang | ![](Documentation/images/O.png) partial support | Win, Linux, MacOS | in,return | in,out,return | ? | ? | ? | ? | ? | - | | NodeJS | ![](Documentation/images/O.png) partial support | Win, Linux, MacOS | in,return | in,out,return | ? | ? | ? | ? | ? | - | diff --git a/Source/ACT.xsd b/Source/ACT.xsd index 533d99f1..5e18ae9b 100644 --- a/Source/ACT.xsd +++ b/Source/ACT.xsd @@ -1,11 +1,13 @@ - + - + - - - - - - + + + + + + @@ -38,8 +40,8 @@ - - + + @@ -51,16 +53,16 @@ - - + + - - + + @@ -68,30 +70,30 @@ - - + + - - + + - + - - + + @@ -107,8 +109,8 @@ - - + + @@ -122,8 +124,8 @@ - - + + @@ -142,8 +144,8 @@ The global element contains all exported global methods. - - + + The <releasemethod> must match a method with the same name and the correct signature. @@ -157,8 +159,8 @@ - - + + @@ -213,31 +215,31 @@ - + - + - + - + - + @@ -295,31 +297,32 @@ - + - + - + - + + - + @@ -327,7 +330,7 @@ - + @@ -343,4 +346,4 @@ - + \ No newline at end of file diff --git a/Source/automaticcomponenttoolkit.go b/Source/automaticcomponenttoolkit.go index 3ad4ccfb..db2e394e 100644 --- a/Source/automaticcomponenttoolkit.go +++ b/Source/automaticcomponenttoolkit.go @@ -69,12 +69,12 @@ func readComponentDefinition(FileName string, ACTVersion string) (ComponentDefin } func main () { - ACTVersion := "1.3.2" + ACTVersion := "1.4.0" fmt.Fprintln(os.Stdout, "Automatic Component Toolkit v" + ACTVersion) if (len (os.Args) < 2) { log.Fatal ("Please run with the Interface Description XML as command line parameter."); log.Fatal ("To specify a path for the generated source code use the optional flag \"-o ABSOLUTE_PATH_TO_OUTPUT_FOLDER\""); - log.Fatal ("To create a diff between two versions of an Interface Description XML use the optional flagg \"-d OTHER_IDL_FILE\""); + log.Fatal ("To create a diff between two versions of an Interface Description XML use the optional flag \"-d OTHER_IDL_FILE\""); } if os.Args[1] == "-v" { fmt.Fprintln(os.Stdout, "Version: "+ACTVersion) diff --git a/Source/buildbindingcdynamic.go b/Source/buildbindingcdynamic.go index cf313555..4b2d3ee0 100644 --- a/Source/buildbindingcdynamic.go +++ b/Source/buildbindingcdynamic.go @@ -324,7 +324,7 @@ func buildDynamicCppImplementation(component ComponentDefinition, w LanguageWrit } -func writeDynamicCPPMethodDeclaration(method ComponentDefinitionMethod, w LanguageWriter, NameSpace string, ClassName string, isGlobal bool) error { +func writeDynamicCPPMethodDeclaration(method ComponentDefinitionMethod, w LanguageWriter, NameSpace string, ClassName string) error { parameters := "" returntype := "void" @@ -374,7 +374,7 @@ func writeDynamicCPPMethodDeclaration(method ComponentDefinitionMethod, w Langua } - w.Writeln(" %s %s (%s);", returntype, method.MethodName, parameters); + w.Writeln(" inline %s %s (%s);", returntype, method.MethodName, parameters); return nil } @@ -721,6 +721,8 @@ func buildDynamicCppHeader(component ComponentDefinition, w LanguageWriter, Name w.Writeln(" {") w.Writeln(" CheckError (nullptr, initWrapperTable (&m_WrapperTable));") w.Writeln(" CheckError (nullptr, loadWrapperTable (&m_WrapperTable, sFileName.c_str ()));") + w.Writeln(" ") + w.Writeln(" CheckError(nullptr, checkBinaryVersion());") w.Writeln(" }") w.Writeln(" ") @@ -749,16 +751,27 @@ func buildDynamicCppHeader(component ComponentDefinition, w LanguageWriter, Name for j := 0; j < len(global.Methods); j++ { method := global.Methods[j] - err := writeDynamicCPPMethodDeclaration(method, w, NameSpace, "Wrapper", true) + err := writeDynamicCPPMethodDeclaration(method, w, NameSpace, "Wrapper") if err != nil { return err } } - + w.Writeln("") w.Writeln("private:") w.Writeln(" s%sDynamicWrapperTable m_WrapperTable;", NameSpace) w.Writeln("") + + w.Writeln(" %sResult checkBinaryVersion()", NameSpace) + w.Writeln(" {") + w.Writeln(" %s_uint32 nMajor, nMinor, nMicro;", NameSpace) + w.Writeln(" %s(nMajor, nMinor, nMicro);", global.VersionMethod) + w.Writeln(" if ( (nMajor != %s_VERSION_MAJOR) || (nMinor < %s_VERSION_MINOR) ) {", strings.ToUpper(NameSpace), strings.ToUpper(NameSpace) ) + w.Writeln(" return %s_ERROR_INCOMPATIBLEBINARYVERSION;", strings.ToUpper(NameSpace)) + w.Writeln(" }") + w.Writeln(" return %s_SUCCESS;", strings.ToUpper(NameSpace)) + w.Writeln(" }") + w.Writeln(" %sResult initWrapperTable (s%sDynamicWrapperTable * pWrapperTable);", NameSpace, NameSpace) w.Writeln(" %sResult releaseWrapperTable (s%sDynamicWrapperTable * pWrapperTable);", NameSpace, NameSpace) w.Writeln(" %sResult loadWrapperTable (s%sDynamicWrapperTable * pWrapperTable, const char * pLibraryFileName);", NameSpace, NameSpace) @@ -855,7 +868,7 @@ func buildDynamicCppHeader(component ComponentDefinition, w LanguageWriter, Name for j := 0; j < len(class.Methods); j++ { method := class.Methods[j] - err := writeDynamicCPPMethodDeclaration(method, w, NameSpace, cppClassName, true) + err := writeDynamicCPPMethodDeclaration(method, w, NameSpace, cppClassName) if err != nil { return err } @@ -1023,7 +1036,7 @@ func buildDynamicCppExample(componentdefinition ComponentDefinition, w LanguageW w.Writeln(" std::string libpath = (\"\"); // TODO: put the location of the %s-library file here.", NameSpace) w.Writeln(" auto wrapper = %s::C%sWrapper::loadLibrary(libpath + \"/%s.\"); // TODO: add correct suffix of the library", NameSpace, NameSpace, BaseName) w.Writeln(" unsigned int nMajor, nMinor, nMicro;") - w.Writeln(" wrapper->GetLibraryVersion(nMajor, nMinor, nMicro);") + w.Writeln(" wrapper->%s(nMajor, nMinor, nMicro);", componentdefinition.Global.VersionMethod) w.Writeln(" std::cout << \"%s.Version = \" << nMajor << \".\" << nMinor << \".\" << nMicro << std::endl;", NameSpace); w.Writeln(" }") w.Writeln(" catch (std::exception &e)") diff --git a/Source/buildbindingcpp.go b/Source/buildbindingcpp.go index b08c0292..7e807999 100644 --- a/Source/buildbindingcpp.go +++ b/Source/buildbindingcpp.go @@ -755,7 +755,7 @@ func buildCppExample(componentdefinition ComponentDefinition, w LanguageWriter, w.Writeln(" try") w.Writeln(" {") w.Writeln(" unsigned int nMajor, nMinor, nMicro;") - w.Writeln(" %s::C%sWrapper::GetLibraryVersion(nMajor, nMinor, nMicro);", NameSpace, NameSpace) + w.Writeln(" %s::C%sWrapper::%s(nMajor, nMinor, nMicro);", NameSpace, NameSpace, componentdefinition.Global.VersionMethod) w.Writeln(" std::cout << \"%s.Version = \" << nMajor << \".\" << nMinor << \".\" << nMicro << std::endl;", NameSpace); w.Writeln(" }") w.Writeln(" catch (std::exception &e)") diff --git a/Source/buildbindinggo.go b/Source/buildbindinggo.go index 861ecafd..19c3d1ca 100644 --- a/Source/buildbindinggo.go +++ b/Source/buildbindinggo.go @@ -290,7 +290,7 @@ func buildGoWrapper (component ComponentDefinition, w io.Writer, implw io.Writer fmt.Fprintf (implw, " return uintptr (value);\n"); fmt.Fprintf (implw, "}\n"); fmt.Fprintf (implw, "\n"); - fmt.Fprintf (implw, "func Uint64InValue (value uint64) uintptr {\n"); + fmt.Fprintf (implw, "func UInt64InValue (value uint64) uintptr {\n"); fmt.Fprintf (implw, " return uintptr (value);\n"); fmt.Fprintf (implw, "}\n"); fmt.Fprintf (implw, "\n"); @@ -488,19 +488,40 @@ func buildGoWrapper (component ComponentDefinition, w io.Writer, implw io.Writer fmt.Fprintf (w, "\n"); fmt.Fprintf (w, classdefinitions); - + + fmt.Fprintf (implw, "\n"); + fmt.Fprintf (implw, "func (implementation *%sImplementation) checkBinaryVersion() (error) {\n", NameSpace) + fmt.Fprintf (implw, " var nBindingMajor uint32 = %d;\n", majorVersion(component.Version)) + fmt.Fprintf (implw, " var nBindingMinor uint32 = %d;\n", minorVersion(component.Version)) + fmt.Fprintf (implw, " nMajor, nMinor, _, err := implementation.%s()\n", global.VersionMethod); + fmt.Fprintf (implw, " if (err != nil) {\n"); + fmt.Fprintf (implw, " return err;\n"); + fmt.Fprintf (implw, " }\n"); + fmt.Fprintf (implw, " if ( (nMajor != nBindingMajor) || (nMinor < nBindingMinor) ) {\n" ) + fmt.Fprintf (implw, " return fmt.Errorf (\"%s Error: %.04x (%s)\", int(0), Get%sErrorMessage (uint32(0)));", NameSpace, "%", "%s", NameSpace) + fmt.Fprintf (implw, " }\n") + fmt.Fprintf (implw, " return nil\n") + fmt.Fprintf (implw, "}\n"); + fmt.Fprintf (implw, "\n"); + fmt.Fprintf (implw, "func %sLoadWrapper (DllFileName string) (%sWrapper, error) {\n", NameSpace, NameSpace); - fmt.Fprintf (implw, " var Wrapper %sWrapper;\n", NameSpace); - fmt.Fprintf (implw, " var Instance %sImplementation;\n", NameSpace); - fmt.Fprintf (implw, " \n"); - fmt.Fprintf (implw, " err := Instance.Initialize (DllFileName);\n"); - fmt.Fprintf (implw, " if (err != nil) {\n"); - fmt.Fprintf (implw, " return Wrapper, err;\n"); - fmt.Fprintf (implw, " }\n"); - fmt.Fprintf (implw, " \n"); - fmt.Fprintf (implw, " Wrapper.Interface = &Instance;\n"); - fmt.Fprintf (implw, " \n"); - fmt.Fprintf (implw, " return Wrapper, nil;\n"); + fmt.Fprintf (implw, " var Wrapper %sWrapper;\n", NameSpace); + fmt.Fprintf (implw, " var Instance %sImplementation;\n", NameSpace); + fmt.Fprintf (implw, " \n"); + fmt.Fprintf (implw, " err := Instance.Initialize (DllFileName);\n"); + fmt.Fprintf (implw, " if (err != nil) {\n"); + fmt.Fprintf (implw, " return Wrapper, err;\n"); + fmt.Fprintf (implw, " }\n"); + + fmt.Fprintf (implw, " err = Instance.checkBinaryVersion()\n") + fmt.Fprintf (implw, " if (err != nil) {\n"); + fmt.Fprintf (implw, " return Wrapper, err;\n"); + fmt.Fprintf (implw, " }\n"); + + fmt.Fprintf (implw, " Wrapper.Interface = &Instance;\n"); + fmt.Fprintf (implw, " \n"); + + fmt.Fprintf (implw, " return Wrapper, nil;\n"); fmt.Fprintf (implw, "}\n"); fmt.Fprintf (implw, "\n"); diff --git a/Source/buildbindingpascal.go b/Source/buildbindingpascal.go index 751e68e2..c7446806 100644 --- a/Source/buildbindingpascal.go +++ b/Source/buildbindingpascal.go @@ -75,7 +75,7 @@ func BuildBindingPascalDynamic(componentdefinition ComponentDefinition, outputFo dynpascalexamplefile.WritePascalLicenseHeader(componentdefinition, fmt.Sprintf("This is an autogenerated Pascal application that demonstrates the\n usage of the Pascal bindings of %s", libraryname), true) - err = buildDynamicPascalExample(dynpascalexamplefile, namespace, baseName, outputFolder) + err = buildDynamicPascalExample(dynpascalexamplefile, componentdefinition.Global, namespace, baseName, outputFolder) if err != nil { return err; } @@ -336,14 +336,16 @@ func buildDynamicPascalImplementation(componentdefinition ComponentDefinition, w } w.Writeln ("") - w.Writeln (" {$IFDEF MSWINDOWS}"); + w.Writeln (" {$IFDEF MSWINDOWS}"); w.Writeln (" function LoadFunction (AFunctionName: AnsiString; FailIfNotExistent: Boolean = True): FARPROC;"); - w.Writeln (" {$ELSE}"); + w.Writeln (" {$ELSE}"); w.Writeln (" function LoadFunction (AFunctionName: AnsiString; FailIfNotExistent: Boolean = True): Pointer;"); - w.Writeln (" {$ENDIF MSWINDOWS}"); + w.Writeln (" {$ENDIF MSWINDOWS}"); + w.Writeln ("") + w.Writeln (" procedure checkBinaryVersion();") w.Writeln ("") - - w.Writeln (" protected"); + + w.Writeln (" protected"); for i := 0; i < len(componentdefinition.Classes); i++ { class := componentdefinition.Classes[i] @@ -519,13 +521,14 @@ func buildDynamicPascalImplementation(componentdefinition ComponentDefinition, w w.Writeln (" F%s%sFunc := LoadFunction ('%s');", NameSpace, method.MethodName, GetCExportName (NameSpace, "Wrapper", method, true)); } - + w.Writeln (" ") + w.Writeln (" checkBinaryVersion();"); w.Writeln (" end;"); w.Writeln ("") w.Writeln (" destructor T%sWrapper.Destroy;", NameSpace); w.Writeln (" begin"); - w.Writeln (" {$IFDEF MSWINDOWS}"); - w.Writeln (" if FModule <> 0 then"); + w.Writeln (" {$IFDEF MSWINDOWS}"); + w.Writeln (" if FModule <> 0 then"); w.Writeln (" FreeLibrary (FModule);"); w.Writeln (" {$ELSE}"); w.Writeln (" if FModule <> 0 then"); @@ -552,16 +555,27 @@ func buildDynamicPascalImplementation(componentdefinition ComponentDefinition, w w.Writeln (" if FailIfNotExistent and not Assigned (Result) then"); w.Writeln (" raise E%sException.CreateCustomMessage (%s_ERROR_COULDNOTFINDLIBRARYEXPORT, 'could not find function ' + AFunctionName);", NameSpace, strings.ToUpper (NameSpace)); w.Writeln (" end;"); - w.Writeln (" {$ELSE}"); + w.Writeln (" {$ELSE}"); w.Writeln (" function T%sWrapper.LoadFunction (AFunctionName: AnsiString; FailIfNotExistent: Boolean): Pointer;", NameSpace); - w.Writeln (" begin"); + w.Writeln (" begin"); w.Writeln (" Result := dynlibs.GetProcAddress (FModule, AFunctionName);"); w.Writeln (" if FailIfNotExistent and not Assigned (Result) then"); w.Writeln (" raise E%sException.CreateCustomMessage (%s_ERROR_COULDNOTFINDLIBRARYEXPORT, 'could not find function ' + AFunctionName);", NameSpace, strings.ToUpper (NameSpace)); - w.Writeln (" end;"); - w.Writeln (" {$ENDIF MSWINDOWS}"); + w.Writeln (" end;"); + w.Writeln (" {$ENDIF MSWINDOWS}"); w.Writeln ("") + + w.Writeln (" procedure T%sWrapper.checkBinaryVersion();", NameSpace) + w.Writeln (" var") + w.Writeln (" AMajor, AMinor, AMicro: Cardinal;") + w.Writeln (" begin") + w.Writeln (" %s(AMajor, AMinor, AMicro);", global.VersionMethod) + w.Writeln (" if (AMajor <> %s_VERSION_MAJOR) or (AMinor < %s_VERSION_MINOR) then", strings.ToUpper(NameSpace), strings.ToUpper(NameSpace)) + w.Writeln (" raise E%sException.Create(%s_ERROR_INCOMPATIBLEBINARYVERSION);", NameSpace, strings.ToUpper(NameSpace)) + w.Writeln (" end;") + w.Writeln (" ") + for j := 0; j < len(global.Methods); j++ { method := global.Methods[j] @@ -881,7 +895,7 @@ func writePascalClassMethodImplementation (method ComponentDefinitionMethod, w L resultCommands = append (resultCommands, fmt.Sprintf (" Result := (Result%s <> 0);", param.ParamName)); case "struct": - callFunctionParameters = callFunctionParameters + "@A" + param.ParamName; + callFunctionParameters = callFunctionParameters + "@Result"; case "basicarray", "structarray": defineCommands = append (defineCommands, " countNeeded" + param.ParamName + ": QWord;"); @@ -1013,7 +1027,7 @@ func generatePlainPascalParameters(method ComponentDefinitionMethod, className s } -func buildDynamicPascalExample(w LanguageWriter, NameSpace string, BaseName string, outputFolder string) error { +func buildDynamicPascalExample(w LanguageWriter, global ComponentDefinitionGlobal, NameSpace string, BaseName string, outputFolder string) error { w.Writeln("program %sPascalTest;", NameSpace) w.Writeln("") w.Writeln("uses") @@ -1047,7 +1061,7 @@ func buildDynamicPascalExample(w LanguageWriter, NameSpace string, BaseName stri w.Writeln(" A%sWrapper := T%sWrapper.Create (ALibPath + '/' + '%s.dll');", NameSpace, NameSpace, BaseName) w.Writeln(" try") w.Writeln(" writeln ('loading DLL Done');") - w.Writeln(" A%sWrapper.GetLibraryVersion(AMajor, AMinor, AMicro);", NameSpace) + w.Writeln(" A%sWrapper.%s(AMajor, AMinor, AMicro);", NameSpace, global.VersionMethod) w.Writeln(" writeln (Format('%s.version = %s', [AMajor, AMinor, AMicro]));",NameSpace, "%d.%d.%d") w.Writeln(" finally") w.Writeln(" FreeAndNil(A%sWrapper);", NameSpace) diff --git a/Source/buildbindingpython.go b/Source/buildbindingpython.go index bada1ad6..bf0a3cf7 100644 --- a/Source/buildbindingpython.go +++ b/Source/buildbindingpython.go @@ -28,7 +28,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ////////////////////////////////////////////////////////////////////////////////////////////////////// // buildbindingpython.go -// functions to generate dynamic Python-bindings of a library's API in form of dynamically loaded functions +// functions to generate dynamic Python3-bindings of a library's API in form of dynamically loaded functions // handles. ////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -109,6 +109,15 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w w.Writeln(" return '%sException ' + str(self._code)", NameSpace) w.Writeln("") + + w.Writeln("'''Definition of binding API version") + w.Writeln("'''") + w.Writeln("class %sBindingVersion(enum.IntEnum):", NameSpace) + w.Writeln(" MAJOR = %d", majorVersion(componentdefinition.Version)) + w.Writeln(" MINOR = %d", minorVersion(componentdefinition.Version)) + w.Writeln(" MICRO = %d", microVersion(componentdefinition.Version)) + w.Writeln("") + w.Writeln("'''Definition Error Codes") w.Writeln("'''") w.Writeln("class %sErrorCodes(enum.IntEnum):", NameSpace) @@ -234,6 +243,8 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w w.Writeln(" raise E%sException(%sErrorCodes.COULDNOTLOADLIBRARY, str(e) + '| \"'+path + '\"' )", NameSpace, NameSpace ) w.Writeln(" ") w.Writeln(" self._loadFunctionTable()") + w.Writeln(" ") + w.Writeln(" self._checkBinaryVersion()") w.Writeln(" ") w.Writeln(" def _loadFunctionTable(self):") @@ -245,6 +256,13 @@ func buildDynamicPythonImplementation(componentdefinition ComponentDefinition, w w.Writeln(" except AttributeError as ae:") w.Writeln(" raise E%sException(%sErrorCodes.COULDNOTFINDLIBRARYEXPORT, ae.args[0])", NameSpace, NameSpace) w.Writeln(" ") + + w.Writeln(" def _checkBinaryVersion(self):") + w.Writeln(" nMajor, nMinor, _ = self.%s()", componentdefinition.Global.VersionMethod) + w.Writeln(" if (nMajor != %sBindingVersion.MAJOR) or (nMinor < %sBindingVersion.MINOR):", NameSpace, NameSpace) + w.Writeln(" raise E%sException(%sErrorCodes.INCOMPATIBLEBINARYVERSION)", NameSpace, NameSpace) + w.Writeln(" ") + w.Writeln(" def checkError(self, instance, errorCode):") w.Writeln(" if instance:") w.Writeln(" if instance._wrapper != self:") @@ -800,8 +818,8 @@ func buildDynamiCPythonExample(componentdefinition ComponentDefinition, w Langua w.Writeln("") w.Writeln("import os") - w.Writeln("import sys") - w.Writeln("sys.path.append(os.path.join(os.path.realpath(__file__),\"..\", \"..\", \"..\", \"Bindings\", \"Python\"))") + w.Writeln("import sys") + w.Writeln("sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), \"..\", \"..\", \"Bindings\", \"Python\"))") w.Writeln("import %s",NameSpace ) w.Writeln("") w.Writeln("") @@ -822,4 +840,4 @@ func buildDynamiCPythonExample(componentdefinition ComponentDefinition, w Langua w.Writeln(" print(e)") return nil -} \ No newline at end of file +} diff --git a/Source/buildimplementationcpp.go b/Source/buildimplementationcpp.go index ff02f884..6aa1121a 100644 --- a/Source/buildimplementationcpp.go +++ b/Source/buildimplementationcpp.go @@ -47,9 +47,10 @@ func BuildImplementationCPP(component ComponentDefinition, outputFolder string, doJournal := len (component.Global.JournalMethod) > 0; - namespace := component.NameSpace; - libraryname := component.LibraryName; - baseName := component.BaseName; + NameSpace := component.NameSpace; + ImplementationSubNameSpace := "Impl" + LibraryName := component.LibraryName; + BaseName := component.BaseName; indentString := getIndentationString(implementation.Indentation) stubIdentifier := "" @@ -57,78 +58,78 @@ func BuildImplementationCPP(component ComponentDefinition, outputFolder string, stubIdentifier = "_" + strings.ToLower(implementation.StubIdentifier) } - IntfExceptionHeaderName := path.Join(outputFolder, baseName+"_interfaceexception.hpp"); + IntfExceptionHeaderName := path.Join(outputFolder, BaseName+"_interfaceexception.hpp"); log.Printf("Creating \"%s\"", IntfExceptionHeaderName) hInternalExceptionHeaderFile, err := CreateLanguageFile (IntfExceptionHeaderName, indentString) if err != nil { return err } hInternalExceptionHeaderFile.WriteCLicenseHeader(component, - fmt.Sprintf("This is an autogenerated C++ Header file with the basic internal\n exception type in order to allow an easy use of %s", libraryname), + fmt.Sprintf("This is an autogenerated C++ Header file with the basic internal\n exception type in order to allow an easy use of %s", LibraryName), true) - IntfExceptionImplName := path.Join(outputFolder, baseName+"_interfaceexception.cpp"); + IntfExceptionImplName := path.Join(outputFolder, BaseName+"_interfaceexception.cpp"); log.Printf("Creating \"%s\"", IntfExceptionImplName) hInternalExceptionImplFile, err := CreateLanguageFile (IntfExceptionImplName, indentString) if err != nil { return err } hInternalExceptionImplFile.WriteCLicenseHeader(component, - fmt.Sprintf("This is an autogenerated C++ Implementation file with the basic internal\n exception type in order to allow an easy use of %s", libraryname), + fmt.Sprintf("This is an autogenerated C++ Implementation file with the basic internal\n exception type in order to allow an easy use of %s", LibraryName), true) - err = buildCPPInternalException(hInternalExceptionHeaderFile, hInternalExceptionImplFile, namespace, baseName ) + err = buildCPPInternalException(hInternalExceptionHeaderFile, hInternalExceptionImplFile, NameSpace, BaseName ) if err != nil { return err } - IntfHeaderName := path.Join(outputFolder, baseName+"_interfaces.hpp"); + IntfHeaderName := path.Join(outputFolder, BaseName+"_interfaces.hpp"); log.Printf("Creating \"%s\"", IntfHeaderName) interfaceshppfile, err := CreateLanguageFile (IntfHeaderName, indentString) if err != nil { return err } interfaceshppfile.WriteCLicenseHeader(component, - fmt.Sprintf("This is an autogenerated C++ header file in order to allow easy\ndevelopment of %s. The implementer of %s needs to\nderive concrete classes from the abstract classes in this header.", libraryname, libraryname), + fmt.Sprintf("This is an autogenerated C++ header file in order to allow easy\ndevelopment of %s. The implementer of %s needs to\nderive concrete classes from the abstract classes in this header.", LibraryName, LibraryName), true) - err = buildCPPInterfaces(component, interfaceshppfile, namespace, implementation.ClassIdentifier, baseName) + err = buildCPPInterfaces(component, interfaceshppfile, NameSpace, ImplementationSubNameSpace, implementation.ClassIdentifier, BaseName) if err != nil { return err } - IntfWrapperImplName := path.Join(outputFolder, baseName+"_interfacewrapper.cpp"); + IntfWrapperImplName := path.Join(outputFolder, BaseName+"_interfacewrapper.cpp"); log.Printf("Creating \"%s\"", IntfWrapperImplName) cppWrapperfile, err := CreateLanguageFile(IntfWrapperImplName, indentString) if err != nil { return err } cppWrapperfile.WriteCLicenseHeader(component, - fmt.Sprintf("This is an autogenerated C++ implementation file in order to allow easy\ndevelopment of %s. The functions in this file need to be implemented. It needs to be generated only once.", libraryname), + fmt.Sprintf("This is an autogenerated C++ implementation file in order to allow easy\ndevelopment of %s. The functions in this file need to be implemented. It needs to be generated only once.", LibraryName), true) - err = buildCPPInterfaceWrapper(component, cppWrapperfile, namespace, implementation.ClassIdentifier, baseName, doJournal) + err = buildCPPInterfaceWrapper(component, cppWrapperfile, NameSpace, ImplementationSubNameSpace, implementation.ClassIdentifier, BaseName, doJournal) if err != nil { return err } if (doJournal) { - IntfJournalHeaderName := path.Join(outputFolder, baseName+"_interfacejournal.hpp"); + IntfJournalHeaderName := path.Join(outputFolder, BaseName+"_interfacejournal.hpp"); log.Printf("Creating \"%s\"", IntfJournalHeaderName) interfacejournalhppfile, err := CreateLanguageFile (IntfJournalHeaderName, indentString) if err != nil { return err } interfacejournalhppfile.WriteCLicenseHeader(component, - fmt.Sprintf("This is an autogenerated C++ header file in order to allow easy\ndevelopment of %s. It provides an automatic Journaling mechanism for the library implementation.", libraryname), + fmt.Sprintf("This is an autogenerated C++ header file in order to allow easy\ndevelopment of %s. It provides an automatic Journaling mechanism for the library implementation.", LibraryName), true) - IntfJournalImplName := path.Join(outputFolder, baseName+"_interfacejournal.cpp"); + IntfJournalImplName := path.Join(outputFolder, BaseName+"_interfacejournal.cpp"); log.Printf("Creating \"%s\"", IntfJournalImplName) interfacejournalcppfile, err := CreateLanguageFile(IntfJournalImplName, indentString) if err != nil { return err } interfacejournalcppfile.WriteCLicenseHeader(component, - fmt.Sprintf("This is an autogenerated C++ implementation file in order to allow easy\ndevelopment of %s. It provides an automatic Journaling mechanism for the library implementation.", libraryname), + fmt.Sprintf("This is an autogenerated C++ implementation file in order to allow easy\ndevelopment of %s. It provides an automatic Journaling mechanism for the library implementation.", LibraryName), true) err = buildJournalingCPP(component, interfacejournalhppfile, interfacejournalcppfile) @@ -137,12 +138,12 @@ func BuildImplementationCPP(component ComponentDefinition, outputFolder string, } } - err = buildCPPStub(component, namespace, implementation.ClassIdentifier, baseName, stubOutputFolder, indentString, stubIdentifier, forceRecreation) + err = buildCPPStub(component, NameSpace, ImplementationSubNameSpace, implementation.ClassIdentifier, BaseName, stubOutputFolder, indentString, stubIdentifier, forceRecreation) if err != nil { return err } - IntfWrapperStubName := path.Join(stubOutputFolder, baseName + stubIdentifier + ".cpp") + IntfWrapperStubName := path.Join(stubOutputFolder, BaseName + stubIdentifier + ".cpp") if forceRecreation || (!FileExists(IntfWrapperStubName) ) { log.Printf("Creating \"%s\"", IntfWrapperStubName) stubfile, err := CreateLanguageFile (IntfWrapperStubName, indentString) @@ -150,10 +151,10 @@ func BuildImplementationCPP(component ComponentDefinition, outputFolder string, return err } stubfile.WriteCLicenseHeader(component, - fmt.Sprintf("This is an autogenerated C++ implementation file in order to allow easy\ndevelopment of %s. It needs to be generated only once.", libraryname), + fmt.Sprintf("This is an autogenerated C++ implementation file in order to allow easy\ndevelopment of %s. It needs to be generated only once.", LibraryName), true) - err = buildCPPGlobalStubFile(component, stubfile, namespace, implementation.ClassIdentifier, baseName) + err = buildCPPGlobalStubFile(component, stubfile, NameSpace, ImplementationSubNameSpace, implementation.ClassIdentifier, BaseName) if err != nil { return err } @@ -170,7 +171,7 @@ func BuildImplementationCPP(component ComponentDefinition, outputFolder string, return err } CMakeListsFile.WriteCMakeLicenseHeader(component, - fmt.Sprintf("This is an autogenerated CMakeLists file for the development of %s.", libraryname), + fmt.Sprintf("This is an autogenerated CMakeLists file for the development of %s.", LibraryName), true) buildCMakeForCPPImplementation(component, CMakeListsFile, doJournal) } else { @@ -221,7 +222,7 @@ func buildCPPInternalException (wHeader LanguageWriter, wImpl LanguageWriter, Na wHeader.Writeln(" /**"); wHeader.Writeln(" * Returns error message"); wHeader.Writeln(" */"); - wHeader.Writeln(" const char* what () const;"); + wHeader.Writeln(" const char* what () const noexcept override;"); wHeader.Writeln("};"); wHeader.Writeln(""); @@ -248,7 +249,7 @@ func buildCPPInternalException (wHeader LanguageWriter, wImpl LanguageWriter, Na wImpl.Writeln(" return m_errorCode;"); wImpl.Writeln("}"); wImpl.Writeln(""); - wImpl.Writeln("const char * E%sInterfaceException::what () const", NameSpace); + wImpl.Writeln("const char * E%sInterfaceException::what () const noexcept", NameSpace); wImpl.Writeln("{"); wImpl.Writeln(" return m_errorMessage.c_str();"); wImpl.Writeln("}"); @@ -258,7 +259,7 @@ func buildCPPInternalException (wHeader LanguageWriter, wImpl LanguageWriter, Na } -func buildCPPInterfaces(component ComponentDefinition, w LanguageWriter, NameSpace string, ClassIdentifier string, BaseName string) error { +func buildCPPInterfaces(component ComponentDefinition, w LanguageWriter, NameSpace string, NameSpaceImplementation string, ClassIdentifier string, BaseName string) error { w.Writeln("") w.Writeln("#ifndef __%s_CPPINTERFACES", strings.ToUpper(NameSpace)) w.Writeln("#define __%s_CPPINTERFACES", strings.ToUpper(NameSpace)) @@ -270,6 +271,7 @@ func buildCPPInterfaces(component ComponentDefinition, w LanguageWriter, NameSpa w.Writeln("") w.Writeln("namespace %s {", NameSpace) + w.Writeln("namespace %s {", NameSpaceImplementation) w.Writeln("") w.Writeln("/**") @@ -343,7 +345,8 @@ func buildCPPInterfaces(component ComponentDefinition, w LanguageWriter, NameSpa } w.Writeln("};") w.Writeln("") - w.Writeln("}") + w.Writeln("} // namespace %s", NameSpaceImplementation) + w.Writeln("} // namespace %s", NameSpace) w.Writeln("") w.Writeln("#endif // __%s_CPPINTERFACES", strings.ToUpper(NameSpace)) @@ -351,12 +354,12 @@ func buildCPPInterfaces(component ComponentDefinition, w LanguageWriter, NameSpa return nil } -func buildCPPGlobalStubFile(component ComponentDefinition, stubfile LanguageWriter, NameSpace string, ClassIdentifier string, BaseName string) error { +func buildCPPGlobalStubFile(component ComponentDefinition, stubfile LanguageWriter, NameSpace string, NameSpaceImplementation string, ClassIdentifier string, BaseName string) error { stubfile.Writeln("#include \"%s.h\"", BaseName) stubfile.Writeln("#include \"%s_interfaces.hpp\"", BaseName) stubfile.Writeln("#include \"%s_interfaceexception.hpp\"", BaseName) stubfile.Writeln("") - stubfile.Writeln("using namespace %s;", NameSpace) + stubfile.Writeln("using namespace %s::%s;", NameSpace, NameSpaceImplementation) stubfile.Writeln("") for j := 0; j < len(component.Global.Methods); j++ { @@ -379,7 +382,7 @@ func buildCPPGlobalStubFile(component ComponentDefinition, stubfile LanguageWrit return nil } -func buildCPPInterfaceWrapper(component ComponentDefinition, w LanguageWriter, NameSpace string, ClassIdentifier string, BaseName string, doJournal bool) error { +func buildCPPInterfaceWrapper(component ComponentDefinition, w LanguageWriter, NameSpace string, NameSpaceImplementation string, ClassIdentifier string, BaseName string, doJournal bool) error { w.Writeln("#include \"%s.h\"", BaseName) w.Writeln("#include \"%s_interfaces.hpp\"", BaseName) w.Writeln("#include \"%s_interfaceexception.hpp\"", BaseName) @@ -387,7 +390,7 @@ func buildCPPInterfaceWrapper(component ComponentDefinition, w LanguageWriter, N w.Writeln("#include \"%s_interfacejournal.hpp\"", BaseName) } w.Writeln("") - w.Writeln("using namespace %s;", NameSpace) + w.Writeln("using namespace %s::%s;", NameSpace, NameSpaceImplementation) w.Writeln("") if (doJournal) { @@ -560,7 +563,7 @@ func writeCImplementationMethod(method ComponentDefinitionMethod, w LanguageWrit return nil } -func buildCPPStub(component ComponentDefinition, NameSpace string, ClassIdentifier string, BaseName string, outputFolder string, indentString string, stubIdentifier string, forceRecreation bool) error { +func buildCPPStub(component ComponentDefinition, NameSpace string, NameSpaceImplementation string, ClassIdentifier string, BaseName string, outputFolder string, indentString string, stubIdentifier string, forceRecreation bool) error { for i := 0; i < len(component.Classes); i++ { class := component.Classes[i] @@ -613,6 +616,7 @@ func buildCPPStub(component ComponentDefinition, NameSpace string, ClassIdentifi stubheaderw.Writeln("") stubheaderw.Writeln("namespace %s {", NameSpace) + stubheaderw.Writeln("namespace Impl {") stubheaderw.Writeln("") stubheaderw.Writeln("") @@ -659,7 +663,7 @@ func buildCPPStub(component ComponentDefinition, NameSpace string, ClassIdentifi stubimplw.Writeln("") - stubimplw.Writeln("using namespace %s;", NameSpace) + stubimplw.Writeln("using namespace %s::%s;", NameSpace, NameSpaceImplementation) stubimplw.Writeln("") stubimplw.Writeln("/*************************************************************************************************************************") @@ -686,7 +690,8 @@ func buildCPPStub(component ComponentDefinition, NameSpace string, ClassIdentifi stubheaderw.Writeln("};") stubheaderw.Writeln("") - stubheaderw.Writeln("}") + stubheaderw.Writeln("} // namespace %s", NameSpaceImplementation) + stubheaderw.Writeln("} // namespace %s", NameSpace) stubheaderw.Writeln("") if class.ParentClass != "" { diff --git a/Source/buildimplementationpascal.go b/Source/buildimplementationpascal.go index 9c9b74b0..d7e61d6c 100644 --- a/Source/buildimplementationpascal.go +++ b/Source/buildimplementationpascal.go @@ -314,6 +314,10 @@ func buildPascalInterfaceDefinition(componentdefinition ComponentDefinition, w L w.Writeln ("uses"); w.Writeln (" %s_types,", BaseName); + if (len(componentdefinition.Enums) > 0) { + // Unit contains enums conversion that may raise exceptions + w.Writeln (" %s_exception,", BaseName); + } w.Writeln (" Classes,"); w.Writeln (" sysutils;"); w.Writeln (""); @@ -601,7 +605,7 @@ func generatePrePostCallPascalFunctionCode(method ComponentDefinitionMethod, Nam checkInputCode = append (checkInputCode, fmt.Sprintf("if not Assigned (%s) then", pascalParams[0].ParamName)) checkInputCode = append (checkInputCode, fmt.Sprintf(" raise E%sException.Create (%s_ERROR_INVALIDPARAM);", NameSpace, strings.ToUpper(NameSpace))) - variableDefinitions = append (variableDefinitions, fmt.Sprintf (" Result%s: %s;", param.ParamName, pascalParams[0].ParamType)); + variableDefinitions = append (variableDefinitions, fmt.Sprintf (" Result%s: T%s%s;", param.ParamName, NameSpace, param.ParamClass)); postCallCode = append (postCallCode, fmt.Sprintf("%s^ := Result%s;", pascalParams[0].ParamName, param.ParamName)) @@ -1126,7 +1130,7 @@ func writePascalClassMethodDummyStub (method ComponentDefinitionMethod, w Langua } w.Writeln("begin"); - w.Writeln(" raise E%sException (%s_ERROR_NOTIMPLEMENTED);", NameSpace, strings.ToUpper (NameSpace)); + w.Writeln(" raise E%sException.Create (%s_ERROR_NOTIMPLEMENTED);", NameSpace, strings.ToUpper (NameSpace)); w.Writeln("end;"); w.Writeln(""); diff --git a/Source/languagepascal.go b/Source/languagepascal.go index 933d791a..4571b50b 100644 --- a/Source/languagepascal.go +++ b/Source/languagepascal.go @@ -137,7 +137,7 @@ func writePascalBaseTypeDefinitions(componentdefinition ComponentDefinition, w L w.Writeln ( " F%s: %sWord;", element.Name, arrayprefix); case "uint32": w.Writeln ( " F%s: %sCardinal;", element.Name, arrayprefix); - case "uint64": + case "uint64": w.Writeln ( " F%s: %sQWord;", element.Name, arrayprefix); case "int8": w.Writeln ( " F%s: %sSmallInt;", element.Name, arrayprefix); @@ -145,10 +145,10 @@ func writePascalBaseTypeDefinitions(componentdefinition ComponentDefinition, w L w.Writeln ( " F%s: %sShortInt;", element.Name, arrayprefix); case "int32": w.Writeln ( " F%s: %sInteger;", element.Name, arrayprefix); - case "int64": + case "int64": w.Writeln ( " F%s: %sInt64;", element.Name, arrayprefix); - case "bool": - w.Writeln ( " F%s: %sCardinal;", element.Name, arrayprefix); + case "bool": + w.Writeln ( " F%s: %sByte;", element.Name, arrayprefix); case "single": w.Writeln ( " F%s: %sSingle;", element.Name, arrayprefix); case "double": @@ -241,7 +241,7 @@ func getPascalParameterType(ParamTypeName string, NameSpace string, ParamClass s case "bool": if isPlain { - PascalParamTypeName = "Cardinal"; + PascalParamTypeName = "Byte"; } else { PascalParamTypeName = "Boolean"; } @@ -529,7 +529,7 @@ func generatePlainPascalParameter(param ComponentDefinitionParam, className stri cParams[0].ParamType = cParamTypeName; cParams[0].ParamName = "p" + param.ParamName; cParams[0].ParamComment = fmt.Sprintf("* @param[out] %s - %s", cParams[0].ParamName, param.ParamDescription); - cParams[0].ParamConvention = "out "; + cParams[0].ParamConvention = ""; cParams[0].ParamTypeNoConvention = "P" + cParamTypeName[1:]; case "basicarray": @@ -608,4 +608,4 @@ func generatePlainPascalParameter(param ComponentDefinitionParam, className stri } return cParams, nil; -} \ No newline at end of file +} diff --git a/Source/lanugagec.go b/Source/lanugagec.go deleted file mode 100644 index 8a90f401..00000000 --- a/Source/lanugagec.go +++ /dev/null @@ -1,628 +0,0 @@ -/*++ - -Copyright (C) 2018 Autodesk Inc. (Original Author) - -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this -list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright notice, -this list of conditions and the following disclaimer in the documentation -and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ---*/ - -////////////////////////////////////////////////////////////////////////////////////////////////////// -// buildlayer.go -// functions to generate C-layer of a library's API (can be used in bindings or implementation) -////////////////////////////////////////////////////////////////////////////////////////////////////// - -package main - -import ( - "fmt" - "path" - "os" - "io" - "strings" - "log" -) - -// BuildBindingC builds C-bindings of a library's API in form of automatically C functions -func BuildBindingC(component ComponentDefinition, outputFolderBindingC string) error { - CTypesHeaderName := path.Join(outputFolderBindingC, component.BaseName + "_types.h"); - log.Printf("Creating \"%s\"", CTypesHeaderName) - err := CreateCTypesHeader (component, CTypesHeaderName); - if (err != nil) { - return err; - } - - CHeaderName := path.Join(outputFolderBindingC, component.BaseName + ".h"); - log.Printf("Creating \"%s\"", CTypesHeaderName) - err = CreateCHeader (component, CHeaderName); - if (err != nil) { - return err; - } - - return nil; -} - -// CreateCTypesHeader creates a C header file for the types in component's API -func CreateCTypesHeader (component ComponentDefinition, CTypesHeaderName string) (error) { - hTypesFile, err := os.Create(CTypesHeaderName); - if (err != nil) { - return err; - } - WriteLicenseHeader (hTypesFile, component, - fmt.Sprintf ("This is an autogenerated plain C Header file with basic types in\norder to allow an easy use of %s", component.LibraryName), - true); - - err = buildCTypesHeader (component, hTypesFile, component.NameSpace); - return err; -} - -func buildCTypesHeader (component ComponentDefinition, w io.Writer, NameSpace string) (error) { - fmt.Fprintf (w, "#ifndef __%s_TYPES_HEADER\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "#define __%s_TYPES_HEADER\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "\n"); - - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " General type definitions\n"); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "typedef int %sResult;\n", NameSpace); - fmt.Fprintf (w, "typedef void * %sHandle;\n", NameSpace); - - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Version for %s\n", NameSpace); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "#define %s_VERSION_MAJOR %d\n", strings.ToUpper (NameSpace), majorVersion(component.Version)); - fmt.Fprintf (w, "#define %s_VERSION_MINOR %d\n", strings.ToUpper (NameSpace), minorVersion(component.Version)); - fmt.Fprintf (w, "#define %s_VERSION_MICRO %d\n", strings.ToUpper (NameSpace), microVersion(component.Version)); - - fmt.Fprintf (w, "\n"); - - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Error constants for %s\n", NameSpace); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "#define %s_SUCCESS 0\n", strings.ToUpper (NameSpace)); - - - for i := 0; i < len(component.Errors.Errors); i++ { - errorcode := component.Errors.Errors[i]; - fmt.Fprintf (w, "#define %s_ERROR_%s %d\n", strings.ToUpper (NameSpace), errorcode.Name, errorcode.Code); - } - - fmt.Fprintf (w, "\n"); - - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Declaration of handle classes \n"); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - fmt.Fprintf (w, "\n"); - - fmt.Fprintf (w, "typedef %sHandle %s_BaseClass;\n", NameSpace, NameSpace); - - for i := 0; i < len(component.Classes); i++ { - class := component.Classes[i]; - fmt.Fprintf (w, "typedef %sHandle %s_%s;\n", NameSpace, NameSpace, class.ClassName); - } - fmt.Fprintf (w, "\n"); - - if (len(component.Enums) > 0) { - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Declaration of enums\n"); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - fmt.Fprintf (w, "\n"); - - for i := 0; i < len(component.Enums); i++ { - enum := component.Enums[i]; - fmt.Fprintf (w, "enum e%s%s {\n", NameSpace, enum.Name); - - for j := 0; j < len(enum.Options); j++ { - - comma := ""; - if (j < len(enum.Options) - 1) { - comma = ","; - } - - option := enum.Options[j]; - fmt.Fprintf (w, " e%s%s = %d%s\n", enum.Name, option.Name, option.Value, comma); - } - - fmt.Fprintf (w, "};\n"); - fmt.Fprintf (w, "\n"); - } - - - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Declaration of enum members for 4 byte struct alignment\n"); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - fmt.Fprintf (w, "\n"); - - for i := 0; i < len(component.Enums); i++ { - enum := component.Enums[i]; - fmt.Fprintf (w, "typedef union {\n"); - fmt.Fprintf (w, " e%s%s m_enum;\n", NameSpace, enum.Name); - fmt.Fprintf (w, " int m_code;\n"); - fmt.Fprintf (w, "} structEnum%s%s;\n", NameSpace, enum.Name); - fmt.Fprintf (w, "\n"); - } - } - - if len(component.Structs) > 0 { - - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Declaration of structs\n"); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - fmt.Fprintf (w, "\n"); - - fmt.Fprintf (w, "#pragma pack (1)\n"); - fmt.Fprintf (w, "\n"); - - for i := 0; i < len(component.Structs); i++ { - structinfo := component.Structs[i]; - fmt.Fprintf (w, "typedef struct {\n"); - - for j := 0; j < len(structinfo.Members); j++ { - - member := structinfo.Members[j]; - - arraysuffix := ""; - if (member.Rows > 0) { - if (member.Columns > 0) { - arraysuffix = fmt.Sprintf ("[%d][%d]", member.Columns, member.Rows) - } else { - arraysuffix = fmt.Sprintf ("[%d]",member.Rows) - } - } - - switch (member.Type) { - case "uint8": - fmt.Fprintf (w, " unsigned char m_%s%s;\n", member.Name, arraysuffix); - case "uint16": - fmt.Fprintf (w, " unsigned short m_%s%s;\n", member.Name, arraysuffix); - case "uint32": - fmt.Fprintf (w, " unsigned int m_%s%s;\n", member.Name, arraysuffix); - case "uint64": - fmt.Fprintf (w, " unsigned long long m_%s%s;\n", member.Name, arraysuffix); - case "int8": - fmt.Fprintf (w, " char m_%s%s;\n", member.Name, arraysuffix); - case "int16": - fmt.Fprintf (w, " short m_%s%s;\n", member.Name, arraysuffix); - case "int32": - fmt.Fprintf (w, " int m_%s%s;\n", member.Name, arraysuffix); - case "int64": - fmt.Fprintf (w, " long long m_%s%s;\n", member.Name, arraysuffix); - case "bool": - fmt.Fprintf (w, " bool m_%s%s;\n", member.Name, arraysuffix); - case "single": - fmt.Fprintf (w, " float m_%s%s;\n", member.Name, arraysuffix); - case "double": - fmt.Fprintf (w, " double m_%s%s;\n", member.Name, arraysuffix); - case "string": - return fmt.Errorf ("it is not possible for struct s%s%s to contain a string value", NameSpace, structinfo.Name); - case "handle": - return fmt.Errorf ("it is not possible for struct s%s%s to contain a handle value", NameSpace, structinfo.Name); - case "enum": - fmt.Fprintf (w, " structEnum%s%s m_%s%s;\n", NameSpace, member.Class, member.Name, arraysuffix); - } - - - } - - fmt.Fprintf (w, "} s%s%s;\n", NameSpace, structinfo.Name); - fmt.Fprintf (w, "\n"); - } - - fmt.Fprintf (w, "#pragma pack ()\n"); - fmt.Fprintf (w, "\n"); - - } - - if len(component.Functions) > 0 { - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Declaration of function pointers \n"); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - fmt.Fprintf (w, "\n"); - for i := 0; i < len(component.Functions); i++ { - functiontype := component.Functions[i] - returnType := "void" - parameters := "" - for j := 0; j < len(functiontype.Params); j++ { - param := functiontype.Params[j] - cParamTypeName, err := getCParameterTypeName(param.ParamType, NameSpace, param.ParamClass); - if (err != nil) { - return err; - } - if (parameters != "") { - parameters = parameters + ", " - } - if (param.ParamPass == "in") { - parameters = parameters + cParamTypeName - } else { - parameters = parameters + cParamTypeName + "*" - } - } - fmt.Fprintf (w, "typedef %s(*%s%s)(%s);\n", returnType, NameSpace, functiontype.FunctionName, parameters); - } - fmt.Fprintf (w, "\n"); - } - - - fmt.Fprintf (w, "#endif // __%s_TYPES_HEADER\n", strings.ToUpper (NameSpace)); - - return nil; -} - -// CreateCHeader creates a C header file for the component's API -func CreateCHeader (component ComponentDefinition, CHeaderName string) (error) { - hfile, err := os.Create(CHeaderName); - if (err != nil) { - return err; - } - WriteLicenseHeader (hfile, component, - fmt.Sprintf ("This is an autogenerated plain C Header file in order to allow an easy\n use of %s", component.LibraryName), - true); - err = buildCHeader (component, hfile, component.NameSpace, component.BaseName); - return err; -} - -func buildCHeader (component ComponentDefinition, w io.Writer, NameSpace string, BaseName string) (error) { - fmt.Fprintf (w, "#ifndef __%s_HEADER\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "#define __%s_HEADER\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "#ifdef __%s_DLL\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "#define %s_DECLSPEC __declspec (dllexport)\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "#else // __%s_DLL\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "#define %s_DECLSPEC\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "#endif // __%s_DLL\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "\n"); - - fmt.Fprintf (w, "#include \"%s_types.h\"\n", BaseName); - fmt.Fprintf (w, "\n"); - - fmt.Fprintf (w, "extern \"C\" {\n"); - - for i := 0; i < len(component.Classes); i++ { - class := component.Classes[i]; - - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Class definition for %s\n", class.ClassName); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - - for j := 0; j < len(class.Methods); j++ { - method := class.Methods[j]; - WriteCMethod (method, w, NameSpace, class.ClassName, false, false); - } - } - - - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "/*************************************************************************************************************************\n"); - fmt.Fprintf (w, " Global functions\n"); - fmt.Fprintf (w, "**************************************************************************************************************************/\n"); - - global := component.Global; - for j := 0; j < len(global.Methods); j++ { - method := global.Methods[j]; - err := WriteCMethod (method, w, NameSpace, "Wrapper", true, false); - if (err != nil) { - return err; - } - } - - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "}\n"); - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "#endif // __%s_HEADER\n", strings.ToUpper (NameSpace)); - fmt.Fprintf (w, "\n"); - - return nil; -} - - -// GetCExportName How do we name the exports in the plain C DLL -func GetCExportName (NameSpace string, ClassName string, method ComponentDefinitionMethod, isGlobal bool) (string) { - CMethodName := ""; - if isGlobal { - CMethodName = fmt.Sprintf("%s_%s%s", strings.ToLower(NameSpace), strings.ToLower(method.MethodName), method.DLLSuffix) - } else { - CMethodName = fmt.Sprintf("%s_%s_%s%s", strings.ToLower(NameSpace), strings.ToLower(ClassName), strings.ToLower(method.MethodName), method.DLLSuffix) - } - - return CMethodName; -} - - -// WriteCMethod writes a method as a C funtion -func WriteCMethod (method ComponentDefinitionMethod, w io.Writer, NameSpace string, ClassName string, isGlobal bool, writeCallbacks bool) (error) { - - CMethodName := ""; - CCallbackName := ""; - parameters := ""; - if (isGlobal) { - CMethodName = fmt.Sprintf ("%s_%s%s", strings.ToLower (NameSpace), strings.ToLower (method.MethodName), method.DLLSuffix); - CCallbackName = fmt.Sprintf ("P%s%sPtr", NameSpace, method.MethodName); - } else { - CMethodName = fmt.Sprintf ("%s_%s_%s%s", strings.ToLower (NameSpace), strings.ToLower (ClassName), strings.ToLower (method.MethodName), method.DLLSuffix); - CCallbackName = fmt.Sprintf ("P%s%s_%sPtr", NameSpace, ClassName, method.MethodName); - parameters = fmt.Sprintf ("%s_%s p%s", NameSpace, ClassName, ClassName); - } - - fmt.Fprintf (w, "\n"); - fmt.Fprintf (w, "/**\n"); - fmt.Fprintf (w, "* %s\n", method.MethodDescription); - fmt.Fprintf (w, "*\n"); - if (!isGlobal) { - fmt.Fprintf (w, "* @param[in] p%s - %s instance.\n", ClassName, ClassName); - } - - - for k := 0; k < len(method.Params); k++ { - param := method.Params [k]; - - cParams, err := generateCParameter(param, ClassName, method.MethodName, NameSpace); - if (err != nil) { - return err; - } - - for _, cParam := range cParams { - fmt.Fprintf (w, cParam.ParamComment); - if (parameters != "") { - parameters = parameters + ", "; - } - parameters = parameters + cParam.ParamType + " " + cParam.ParamName; - } - - } - - fmt.Fprintf (w, "* @return error code or 0 (success)\n"); - fmt.Fprintf (w, "*/\n"); - - if (writeCallbacks) { - fmt.Fprintf (w, "typedef %sResult (*%s) (%s);\n", NameSpace, CCallbackName, parameters); - } else { - fmt.Fprintf (w, "%s_DECLSPEC %sResult %s (%s);\n", strings.ToUpper(NameSpace), NameSpace, CMethodName, parameters); - } - - return nil; -} - - -func getCParameterTypeName(ParamTypeName string, NameSpace string, ParamClass string)(string, error) { - cParamTypeName := ""; - switch (ParamTypeName) { - case "uint8": - cParamTypeName = "unsigned char"; - - case "uint16": - cParamTypeName = "unsigned short"; - - case "uint32": - cParamTypeName = "unsigned int"; - - case "uint64": - cParamTypeName = "unsigned long long"; - - case "int8": - cParamTypeName = "char"; - - case "int16": - cParamTypeName = "short"; - - case "int32": - cParamTypeName = "int"; - - case "int64": - cParamTypeName = "long long"; - - case "bool": - cParamTypeName = "bool"; - - case "single": - cParamTypeName = "float"; - - case "double": - cParamTypeName = "double"; - - case "string": - cParamTypeName = "char *"; - - case "enum": - cParamTypeName = fmt.Sprintf ("e%s%s", NameSpace, ParamClass); - - case "struct": - cParamTypeName = fmt.Sprintf ("s%s%s *", NameSpace, ParamClass); - - case "basicarray": - basicTypeName, err := getCParameterTypeName(ParamClass, NameSpace, ""); - if (err != nil) { - return "", err; - } - cParamTypeName = fmt.Sprintf ("%s *", basicTypeName); - - case "structarray": - cParamTypeName = fmt.Sprintf ("s%s%s *", NameSpace, ParamClass) - - case "handle": - cParamTypeName = fmt.Sprintf ("%s_%s", NameSpace, ParamClass) - - case "functiontype": - cParamTypeName = fmt.Sprintf ("%s%s", NameSpace, ParamClass) - - default: - return "", fmt.Errorf ("invalid parameter type \"%s\" for C-parameter", ParamTypeName); - } - - return cParamTypeName, nil; -} - -// CParameter is a handy representation of a function parameter in C -type CParameter struct { - ParamType string - ParamName string - ParamComment string -} - - -func generateCParameter(param ComponentDefinitionParam, className string, methodName string, NameSpace string) ([]CParameter, error) { - cParams := make([]CParameter,1) - cParamTypeName, err := getCParameterTypeName(param.ParamType, NameSpace, param.ParamClass); - if (err != nil) { - return nil, err; - } - - switch (param.ParamPass) { - case "in": - switch (param.ParamType) { - case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "n" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "bool": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "b" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "single": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "f" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "double": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "d" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "string": - cParams[0].ParamType = "const " + cParamTypeName; - cParams[0].ParamName = "p" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "enum": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "e" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "struct": - cParams[0].ParamType = "const " + cParamTypeName; - cParams[0].ParamName = "p" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "basicarray", "structarray": - cParams = make([]CParameter,2) - cParams[0].ParamType = "const unsigned int"; - cParams[0].ParamName = "n" + param.ParamName + "BufferSize"; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - Number of elements in buffer\n", cParams[0].ParamName); - - cParams[1].ParamType = "const " + cParamTypeName; - cParams[1].ParamName = "p" + param.ParamName + "Buffer"; - cParams[1].ParamComment = fmt.Sprintf("* @param[in] %s - %s buffer of %s\n", cParams[1].ParamName, param.ParamClass, param.ParamDescription); - - case "handle": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "p" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "functiontype": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "p" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - default: - return nil, fmt.Errorf ("invalid method parameter type \"%s\" for %s.%s (%s)", param.ParamType, className, methodName, param.ParamName); - } - - case "out", "return": - - switch (param.ParamType) { - - case "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64", "bool", "single", "double", "enum": - cParams[0].ParamType = cParamTypeName + " *"; - cParams[0].ParamName = "p" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[out] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "struct": - cParams[0].ParamType = cParamTypeName; - cParams[0].ParamName = "p" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[out] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - case "basicarray", "structarray": - cParams = make([]CParameter,3) - cParams[0].ParamType = "const unsigned int"; - cParams[0].ParamName = "n" + param.ParamName + "BufferSize"; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - Number of elements in buffer\n", cParams[0].ParamName); - - cParams[1].ParamType = "unsigned int *"; - cParams[1].ParamName = "p" + param.ParamName + "NeededCount"; - cParams[1].ParamComment = fmt.Sprintf("* @param[out] %s - will be filled with the count of the written elements, or needed buffer size.\n", cParams[1].ParamName); - - cParams[2].ParamType = cParamTypeName; - cParams[2].ParamName = "p" + param.ParamName + "Buffer"; - cParams[2].ParamComment = fmt.Sprintf("* @param[out] %s - %s buffer of %s\n", cParams[2].ParamName, param.ParamClass, param.ParamDescription); - - case "string": - cParams = make([]CParameter,3) - cParams[0].ParamType = "const unsigned int"; - cParams[0].ParamName = "n" + param.ParamName + "BufferSize"; - cParams[0].ParamComment = fmt.Sprintf("* @param[in] %s - size of the buffer (including trailing 0)\n", cParams[0].ParamName); - - cParams[1].ParamType = "unsigned int *"; - cParams[1].ParamName = "p" + param.ParamName + "NeededChars"; - cParams[1].ParamComment = fmt.Sprintf("* @param[out] %s - will be filled with the count of the written bytes, or needed buffer size.\n", cParams[1].ParamName); - - cParams[2].ParamType = cParamTypeName; - cParams[2].ParamName = "p" + param.ParamName + "Buffer"; - cParams[2].ParamComment = fmt.Sprintf("* @param[out] %s - %s buffer of %s, may be NULL\n", cParams[2].ParamName, param.ParamClass, param.ParamDescription); - - case "handle": - cParams[0].ParamType = cParamTypeName + " *"; - cParams[0].ParamName = "p" + param.ParamName; - cParams[0].ParamComment = fmt.Sprintf("* @param[out] %s - %s\n", cParams[0].ParamName, param.ParamDescription); - - default: - return nil, fmt.Errorf ("invalid method parameter type \"%s\" for %s.%s (%s)", param.ParamType, className, methodName, param.ParamName); - } - - default: - return nil, fmt.Errorf ("invalid method parameter passing \"%s\" for %s.%s (%s)", param.ParamPass, className, methodName, param.ParamName); - } - - return cParams, nil; -} - -// GenerateCParameters generates an array of cParameters for a method -func GenerateCParameters(method ComponentDefinitionMethod, className string, NameSpace string) ([]CParameter, error) { - parameters := []CParameter{}; - for k := 0; k < len(method.Params); k++ { - param := method.Params [k]; - - cParam, err := generateCParameter(param, className, method.MethodName, NameSpace); - if err != nil { - return nil, err; - } - parameters = append(parameters, cParam...); - } - - return parameters, nil; -} \ No newline at end of file diff --git a/build.bat b/build.bat deleted file mode 100644 index a2c93974..00000000 --- a/build.bat +++ /dev/null @@ -1,11 +0,0 @@ -@echo off -cd Source -set Sources=actutils.go automaticcomponenttoolkit.go buildbindingcdynamic.go buildbindingcpp.go buildbindinggo.go buildbindingnode.go buildbindingpascal.go buildbindingpython.go buildimplementationcpp.go buildimplementationpascal.go componentdefinition.go languagewriter.go languagec.go languagepascal.go -set GOOS=windows -set GOARCH=amd64 -go build -o ..\act.exe %Sources% -set GOOS=linux -go build -o ..\act.linux %Sources% -set GOOS=darwin -go build -o ..\act.darwin %Sources% -cd .. \ No newline at end of file