Skip to content

Commit 57a7c8a

Browse files
Version 1.2.0
1 parent 28e4263 commit 57a7c8a

19 files changed

+1691
-88
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*++
2+
3+
Copyright (C) 2018 Automatic Component Toolkit Developers
4+
5+
All rights reserved.
6+
7+
Abstract: This is an autogenerated C++ application that demonstrates the
8+
usage of the Dynamic C++ bindings of Prime Numbers Interface
9+
Interface version: 1.0.0
10+
11+
*/
12+
13+
#include <iostream>
14+
#include "libprimes_dynamic.hpp"
15+
16+
17+
void progressCallback(float progress, bool* shouldAbort)
18+
{
19+
std::cout << "Progress = " << round(progress * 100) << "%" << std::endl;
20+
if (shouldAbort) {
21+
*shouldAbort = progress > 0.5;
22+
}
23+
}
24+
25+
int main()
26+
{
27+
try
28+
{
29+
std::string libpath = ""; // TODO: put the location of the LibPrimes-library file here.
30+
auto wrapper = LibPrimes::CLibPrimesWrapper::loadLibrary(libpath + "/libprimes");
31+
wrapper->SetJournal("journal_cppdynamic.xml");
32+
33+
unsigned int nMajor, nMinor, nMicro;
34+
wrapper->GetLibraryVersion(nMajor, nMinor, nMicro);
35+
std::cout << "LibPrimes.Version = " << nMajor << "." << nMinor << "." << nMicro << std::endl;
36+
37+
auto factorization = wrapper->CreateFactorizationCalculator();
38+
factorization->SetValue(735);
39+
factorization->SetProgressCallback(progressCallback);
40+
factorization->Calculate();
41+
std::vector<sLibPrimesPrimeFactor> primeFactors;
42+
factorization->GetPrimeFactors(primeFactors);
43+
44+
std::cout << factorization->GetValue() << " = ";
45+
for (size_t i = 0; i < primeFactors.size(); i++) {
46+
auto pF = primeFactors[i];
47+
std::cout << pF.m_Prime << "^" << pF.m_Multiplicity << ((i < (primeFactors.size() - 1)) ? " * " : "");
48+
}
49+
std::cout << std::endl;
50+
}
51+
catch (std::exception &e)
52+
{
53+
std::cout << e.what() << std::endl;
54+
return 1;
55+
}
56+
return 0;
57+
}
58+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.lps
2+
bin
3+
lib
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CONFIG>
3+
<ProjectOptions>
4+
<Version Value="10"/>
5+
<PathDelim Value="\"/>
6+
<General>
7+
<Flags>
8+
<MainUnitHasCreateFormStatements Value="False" />
9+
<MainUnitHasTitleStatement Value="False" />
10+
<MainUnitHasScaledStatement Value="False" />
11+
</Flags>
12+
<SessionStorage Value="InProjectDir" />
13+
<MainUnit Value="0"/>
14+
<Title Value="LibPrimes_Example" />
15+
<UseAppBundle Value="False" />
16+
<ResourceType Value="res" />
17+
</General>
18+
<BuildModes Count="2">
19+
<Item1 Name="Release" Default="True"/>
20+
<Item2 Name="Debug">
21+
<CompilerOptions>
22+
<Version Value="11" />
23+
<PathDelim Value="\"/>
24+
<Target>
25+
<Filename Value="bin\$(TargetCPU)-$(TargetOS)\Release\LibPrimes_Example"/>
26+
</Target>
27+
<SearchPaths>
28+
<IncludeFiles Value="$(ProjOutDir)"/>
29+
<OtherUnitFiles Value="..\..\Bindings\Pascal"/>
30+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
31+
</SearchPaths>
32+
<Parsing>
33+
<SyntaxOptions>
34+
<IncludeAssertionCode Value="True"/>
35+
</SyntaxOptions>
36+
</Parsing>
37+
<CodeGeneration>
38+
<RelocatableUnit Value="True" />
39+
</CodeGeneration>
40+
<Linking>
41+
<Debugging>
42+
<UseExternalDbgSyms Value="True"/>
43+
</Debugging>
44+
<Options>
45+
<ExecutableType Value="Library"/>
46+
</Options>
47+
</Linking>
48+
</CompilerOptions>
49+
</Item2>
50+
</BuildModes>
51+
<PublishOptions>
52+
<Version Value="2"/>
53+
</PublishOptions>
54+
<RunParams>
55+
<local>
56+
<FormatVersion Value="1"/>
57+
</local>
58+
</RunParams>
59+
<Units Count="2">
60+
<Unit0>
61+
<Filename Value="LibPrimes_Example.lpr"/>
62+
<IsPartOfProject Value="True"/>
63+
</Unit0>
64+
<Unit1>
65+
<Filename Value="Unit_LibPrimes.pas"/>
66+
<IsPartOfProject Value="True"/>
67+
</Unit1>
68+
</Units>
69+
</ProjectOptions>
70+
<CompilerOptions>
71+
<Version Value="11"/>
72+
<PathDelim Value="\"/>
73+
<Target>
74+
<Filename Value="bin\$(TargetCPU)-$(TargetOS)\Release\LibPrimes_Example"/>
75+
</Target>
76+
<SearchPaths>
77+
<IncludeFiles Value="$(ProjOutDir)"/>
78+
<OtherUnitFiles Value="..\..\Bindings\Pascal"/>
79+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
80+
</SearchPaths>
81+
<Parsing>
82+
<SyntaxOptions>
83+
<IncludeAssertionCode Value="True"/>
84+
</SyntaxOptions>
85+
</Parsing>
86+
<CodeGeneration>
87+
<RelocatableUnit Value="True"/>
88+
</CodeGeneration>
89+
<Linking>
90+
<Debugging>
91+
<StripSymbols Value="True"/>
92+
<UseExternalDbgSyms Value="True"/>
93+
</Debugging>
94+
<Options>
95+
<ExecutableType Value="Library"/>
96+
</Options>
97+
</Linking>
98+
</CompilerOptions>
99+
<Debugging>
100+
<Exceptions Count="3">
101+
<Item1>
102+
<Name Value="EAbort"/>
103+
</Item1>
104+
<Item2>
105+
<Name Value="ECodetoolError"/>
106+
</Item2>
107+
<Item3>
108+
<Name Value="EFOpenError"/>
109+
</Item3>
110+
</Exceptions>
111+
</Debugging>
112+
</CONFIG>
113+
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
(*++
2+
3+
Copyright (C) 2018 Automatic Component Toolkit Developers
4+
5+
All rights reserved.
6+
7+
Abstract: This is an autogenerated Pascal application that demonstrates the
8+
usage of the Pascal bindings of Prime Numbers Interface
9+
Interface version: 1.0.0
10+
11+
*)
12+
13+
program LibPrimesPascalTest;
14+
15+
uses
16+
{$IFDEF UNIX}{$IFDEF UseCThreads}
17+
cthreads,
18+
{$ENDIF}{$ENDIF}
19+
Classes, SysUtils, CustApp,
20+
Unit_LibPrimes
21+
{ you can add units after this };
22+
23+
type
24+
25+
TLibPrimes_Example = class(TCustomApplication)
26+
protected
27+
procedure DoRun; override;
28+
procedure TestLibPrimes ();
29+
public
30+
constructor Create(TheOwner: TComponent); override;
31+
destructor Destroy; override;
32+
end;
33+
34+
35+
procedure TLibPrimes_Example.TestLibPrimes ();
36+
var
37+
ALibPrimesWrapper: TLibPrimesWrapper;
38+
AMajor, AMinor, AMicro: Cardinal;
39+
ALibPath: string;
40+
begin
41+
writeln ('loading DLL');
42+
ALibPath := ''; // TODO add the location of the shared library binary here
43+
ALibPrimesWrapper := TLibPrimesWrapper.Create (ALibPath + '/' + 'libprimes.dll');
44+
try
45+
writeln ('loading DLL Done');
46+
ALibPrimesWrapper.GetLibraryVersion(AMajor, AMinor, AMicro);
47+
writeln (Format('LibPrimes.version = %d.%d.%d', [AMajor, AMinor, AMicro]));
48+
finally
49+
FreeAndNil(ALibPrimesWrapper);
50+
end;
51+
end;
52+
53+
procedure TLibPrimes_Example.DoRun;
54+
begin
55+
try
56+
TestLibPrimes();
57+
except
58+
On E: Exception do
59+
writeln ('Fatal error: ', E.Message);
60+
end;
61+
Terminate
62+
end;
63+
64+
constructor TLibPrimes_Example.Create(TheOwner: TComponent);
65+
begin
66+
inherited Create(TheOwner);
67+
StopOnException:=True;
68+
end;
69+
70+
destructor TLibPrimes_Example.Destroy;
71+
begin
72+
inherited Destroy;
73+
end;
74+
75+
76+
var
77+
Application: TLibPrimes_Example;
78+
begin
79+
Application:=TLibPrimes_Example.Create(nil);
80+
Application.Run;
81+
Application.Free;
82+
end.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'''++
2+
3+
Copyright (C) 2018 Automatic Component Toolkit Developers
4+
5+
All rights reserved.
6+
7+
Abstract: This is an autogenerated Python application that demonstrates the
8+
usage of the Python bindings of Prime Numbers Interface
9+
Interface version: 1.0.0
10+
11+
'''
12+
13+
def progressCallback(progress, shouldAbort):
14+
print("Progress = {:d}%".format(round(progress*100)))
15+
if (shouldAbort is not None):
16+
shouldAbort[0] = progress > 0.5;
17+
18+
19+
import os
20+
import sys
21+
sys.path.append(os.path.join(os.path.realpath(__file__),"..", "..", "..", "Bindings", "Python"))
22+
import LibPrimes
23+
24+
25+
def main():
26+
libpath = '' # TODO add the location of the shared library binary here
27+
wrapper = LibPrimes.LibPrimesWrapper(os.path.join(libpath, "libprimes"))
28+
wrapper.SetJournal('journal_python.xml')
29+
30+
major, minor, micro = wrapper.GetLibraryVersion()
31+
print("LibPrimes version: {:d}.{:d}.{:d}".format(major, minor, micro))
32+
33+
factorization = wrapper.CreateFactorizationCalculator()
34+
factorization.SetValue(735)
35+
cTypesCallback = LibPrimes.LibPrimesProgressCallback(progressCallback)
36+
factorization.SetProgressCallback(cTypesCallback)
37+
factorization.Calculate()
38+
primeFactors = factorization.GetPrimeFactors()
39+
productString = "*"
40+
print("{:d} = ".format(factorization.GetValue()), end="")
41+
for i in range(0, len(primeFactors)):
42+
pF = primeFactors[i]
43+
if i == len(primeFactors) - 1:
44+
productString = "\n"
45+
print(" {:d}^{:d} ".format(pF.Prime, pF.Multiplicity), end=productString)
46+
47+
if __name__ == "__main__":
48+
try:
49+
main()
50+
except LibPrimes.ELibPrimesException as e:
51+
print(e)

Examples/Primes/LibPrimes_component/Implementations/Cpp/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,3 @@ add_library(libprimes SHARED ${LIBPRIMES_SRC} ${LIBPRIMES_HDR})
3434
target_compile_options(libprimes PRIVATE "-D__LIBPRIMES_DLL")
3535
target_include_directories(libprimes PRIVATE ${CMAKE_CURRENT_AUTOGENERATED_DIR})
3636
target_include_directories(libprimes PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Stub)
37-
38-
39-
add_executable(primeuser "${CMAKE_CURRENT_SOURCE_DIR}/../../../PrimeUser/main.cpp")
40-
target_include_directories(primeuser PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/CppDynamic")
41-

Examples/Primes/LibPrimes_component/Implementations/Cpp/Stub/libprimes_factorizationcalculator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ void CLibPrimesFactorizationCalculator::Calculate()
2626

2727
unsigned long long nValue = m_value;
2828
for (unsigned long long i = 2; i <= nValue; i++) {
29+
30+
if (m_Callback) {
31+
bool shouldAbort = false;
32+
(*m_Callback)(1 - float(nValue) / m_value, &shouldAbort);
33+
if (shouldAbort) {
34+
throw ELibPrimesInterfaceException(LIBPRIMES_ERROR_CALCULATIONABORTED);
35+
}
36+
}
37+
2938
sLibPrimesPrimeFactor primeFactor;
3039
primeFactor.m_Prime = i;
3140
primeFactor.m_Multiplicity = 0;

0 commit comments

Comments
 (0)