[mapguide-commits] r7636 - sandbox/jng/node/Oem/SWIGEx/Source/Modules
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Fri Jun 21 09:09:34 PDT 2013
Author: jng
Date: 2013-06-21 09:09:34 -0700 (Fri, 21 Jun 2013)
New Revision: 7636
Modified:
sandbox/jng/node/Oem/SWIGEx/Source/Modules/nodejs.cxx
Log:
This submission includes:
* Codegen for handling byte arrays and checking for byte array arguments. We use the node Buffer class for handling BYTE_ARRAY_OUT and BYTE_ARRAY_IN
Modified: sandbox/jng/node/Oem/SWIGEx/Source/Modules/nodejs.cxx
===================================================================
--- sandbox/jng/node/Oem/SWIGEx/Source/Modules/nodejs.cxx 2013-06-20 15:00:57 UTC (rev 7635)
+++ sandbox/jng/node/Oem/SWIGEx/Source/Modules/nodejs.cxx 2013-06-21 16:09:34 UTC (rev 7636)
@@ -237,6 +237,7 @@
Swig_banner(m_fOutputFile);
writeToFile("#include <node.h>\n\n\n");
+ writeToFile("#include <node_buffer.h>\n\n\n");
writeToFile("//TODO: Should learn how to process SWIG %module directive instead of hard-coding headers\n");
writeToFile("#include <map>\n");
@@ -1151,6 +1152,26 @@
frag.writeToFragment("}\n");
}
}
+ else if (Strcmp(type, "BYTE_ARRAY_IN") == 0 ||
+ Strcmp(type, "BYTE_ARRAY_OUT") == 0)
+ {
+ if (bThrowV8Exceptions)
+ {
+ frag.writeToFragment(NewStringf("if (!node::Buffer::HasInstance(%s[%d])) return v8::ThrowException(v8::Exception::Error(v8::String::New(\"Argument %d (%s: %s) is not a node Buffer\")));\n", ARGS_VAR, argNo, (argNo + 1), name, type));
+ }
+ else
+ {
+ frag.writeToFragment(NewStringf("if (!node::Buffer::HasInstance(%s[%d]))\n", ARGS_VAR, argNo));
+ frag.writeToFragment("{\n");
+ {
+ Indenter ind(m_indentationLevels);
+ frag.writeToFragment("MgStringCollection exArgs;\n");
+ frag.writeToFragment(NewStringf("exArgs.Add(L\"Argument %d (%s: %s) is not a node Buffer\");\n", (argNo + 1), name, type));
+ frag.writeToFragment(NewStringf("throw new MgInvalidArgumentException(L\"%s\", __LINE__, __WFILE__, NULL, L\"MgFormatInnerExceptionMessage\", &exArgs);\n", callingMethodName.c_str()));
+ }
+ frag.writeToFragment("}\n");
+ }
+ }
else if (Strcmp(type, "STRINGPARAM") == 0)
{
if (bThrowV8Exceptions)
@@ -1247,16 +1268,16 @@
//frag.writeToFragment(NewStringf("std::string str%d = args[%d]->ToString();\n", argNo, argNo));
//frag.writeToFragment(NewStringf("Ptr<MgByte> bytes%d = new MgByte((BYTE_ARRAY_IN)str%d);\n", argNo, argNo));
//frag.writeToFragment(NewStringf("STRING arg%d = MgUtil::MultiByteToWideChar(args[%d]->ToString());\n", argNo, argNo));
- frag.writeToFragment("//TODO: Case not handled: BYTE_ARRAY_OUT\n");
- frag.writeToFragment(NewStringf("BYTE_ARRAY_OUT arg%d = NULL;\n", argNo));
+ //frag.writeToFragment("//TODO: Case not handled: BYTE_ARRAY_OUT\n");
+ frag.writeToFragment(NewStringf("BYTE_ARRAY_OUT arg%d = (BYTE_ARRAY_OUT)node::Buffer::Data(%s[%d]->ToObject());\n", argNo, ARGS_VAR, argNo));
}
else if (Strcmp(type, "BYTE_ARRAY_IN") == 0)
{
//frag.writeToFragment(NewStringf("std::string str%d = args[%d]->ToString();\n", argNo, argNo));
//frag.writeToFragment(NewStringf("Ptr<MgByte> bytes%d = new MgByte((BYTE_ARRAY_IN)str%d);\n", argNo, argNo));
//frag.writeToFragment(NewStringf("STRING arg%d = MgUtil::MultiByteToWideChar(args[%d]->ToString());\n", argNo, argNo));
- frag.writeToFragment("//TODO: Case not handled: BYTE_ARRAY_IN\n");
- frag.writeToFragment(NewStringf("BYTE_ARRAY_IN arg%d = NULL;\n", argNo));
+ //frag.writeToFragment("//TODO: Case not handled: BYTE_ARRAY_IN\n");
+ frag.writeToFragment(NewStringf("BYTE_ARRAY_IN arg%d = (BYTE_ARRAY_IN)node::Buffer::Data(%s[%d]->ToObject());\n", argNo, ARGS_VAR, argNo));
}
else if (Strcmp(type, "STRINGPARAM") == 0)
{
More information about the mapguide-commits
mailing list