Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Quirk <chrisq@microsoft.com>2012-09-22 05:38:55 +0400
committerChris Quirk <chrisq@microsoft.com>2012-09-22 05:38:55 +0400
commit3261bceca70eae3a3bd9d4c9ccf0c2758e2ebefc (patch)
tree7124630bea02e5d3acaa3c0be6118ab065147313 /vowpalwabbit/vwdll.cpp
parent92f09900c56d1b7d83d69d40df56b92469215f79 (diff)
initial dll version and C# test code
Diffstat (limited to 'vowpalwabbit/vwdll.cpp')
-rw-r--r--vowpalwabbit/vwdll.cpp83
1 files changed, 83 insertions, 0 deletions
diff --git a/vowpalwabbit/vwdll.cpp b/vowpalwabbit/vwdll.cpp
new file mode 100644
index 00000000..3d13cb94
--- /dev/null
+++ b/vowpalwabbit/vwdll.cpp
@@ -0,0 +1,83 @@
+#include <memory>
+
+#include "vwdll.h"
+#include "parser.h"
+
+extern "C"
+{
+
+ VW_DLL_MEMBER VW_HANDLE VW_CALLING_CONV VW_Initialize(const char * pstrArgs)
+ {
+ std::auto_ptr<vw> inst(new vw);
+ try
+ {
+ string s(pstrArgs);
+ *(inst.get()) = VW::initialize(s);
+ initialize_parser_datastructures(*(inst.get()));
+ return static_cast<VW_HANDLE>(inst.release());
+ }
+ catch (...)
+ {
+ // BUGBUG: should report error here....
+ return INVALID_VW_HANDLE;
+ }
+ }
+
+ VW_DLL_MEMBER void VW_CALLING_CONV VW_Finish(VW_HANDLE handle)
+ {
+ try
+ {
+ vw * pointer = static_cast<vw*>(handle);
+ release_parser_datastructures(*pointer);
+ VW::finish(*pointer);
+ delete pointer;
+ }
+ catch (...)
+ {}
+ }
+
+ VW_DLL_MEMBER VW_EXAMPLE VW_CALLING_CONV VW_ReadExample(VW_HANDLE handle, const char * line)
+ {
+ try
+ {
+ vw * pointer = static_cast<vw*>(handle);
+ // BUGBUG: I really dislike this const_cast. should VW really change the input string?
+ return static_cast<VW_EXAMPLE>(VW::read_example(*pointer, const_cast<char*>(line)));
+ }
+ catch (...)
+ {
+ // BUGBUG: should report error here....
+ return INVALID_VW_EXAMPLE;
+ }
+ }
+
+ VW_DLL_MEMBER void VW_CALLING_CONV VW_FinishExample(VW_HANDLE handle, VW_EXAMPLE e)
+ {
+ try
+ {
+ vw * pointer = static_cast<vw*>(handle);
+ VW::finish_example(*pointer, static_cast<example*>(e));
+ }
+ catch (...)
+ {
+ // BUGBUG: should report error here....
+ }
+ }
+
+ VW_DLL_MEMBER float VW_CALLING_CONV VW_Learn(VW_HANDLE handle, VW_EXAMPLE e)
+ {
+ try
+ {
+ vw * pointer = static_cast<vw*>(handle);
+ example * ex = static_cast<example*>(e);
+ pointer->learn(pointer, ex);
+ return ex->final_prediction;
+ }
+ catch (...)
+ {
+ // BUGBUG: should report error here....
+ return std::numeric_limits<float>::quiet_NaN();
+ }
+ }
+
+} \ No newline at end of file