Permalink
Browse files

Initial Version of Nan-based wrapper

- Initial working version of Nan-based rewritten wrapper
- Add CMakeLists.txt for building with cmake/easier debug
- Fix package.json license field
- Fix build occurring before dependency install
- Add editorconfig file to maintain previous styles
- Change char* to const char* in genx core to be more
   standardized / have better compatibility with Cxx11
  • Loading branch information...
PMLavigne committed Dec 29, 2015
1 parent 4db47b4 commit 2e0dce57910926e3919ec9d0a0b52dea059129e7
Showing with 409 additions and 394 deletions.
  1. +13 −0 .editorconfig
  2. +1 −0 .gitignore
  3. +16 −0 CMakeLists.txt
  4. +2 −1 binding.gyp
  5. +8 −4 package.json
  6. +26 −14 src/attribute.cc
  7. +6 −9 src/attribute.h
  8. +28 −12 src/element.cc
  9. +6 −8 src/element.h
  10. +30 −30 src/genx.cc
  11. +7 −7 src/genx.h
  12. +32 −17 src/namespace.cc
  13. +7 −9 src/namespace.h
  14. +3 −2 src/node-genx.cc
  15. +11 −40 src/node-genx.h
  16. +175 −204 src/writer.cc
  17. +33 −32 src/writer.h
  18. +5 −5 test/writer_test.js
View
@@ -0,0 +1,13 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
[*.json]
indent_style = space
indent_size = 2
View
@@ -1,3 +1,4 @@
build/*
.lock-wscript
node_modules
.idea/
View
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.4)
project(genx)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/node_modules/node-cmake)
find_package(NodeJS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -Wall")
file(GLOB SOURCE_FILES "src/*.cc" "src/*.h")
add_nodejs_module(${PROJECT_NAME} SHARED ${SOURCE_FILES})
target_compile_definitions(${PROJECT_NAME} PUBLIC -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE)
View
@@ -10,7 +10,8 @@
"src/attribute.cc",
"src/writer.cc",
"src/node-genx.cc"
]
],
"include_dirs" : [ "<!(node -e \"require('nan')\")" ]
}
]
}
View
@@ -1,6 +1,6 @@
{
"name": "genx",
"version": "1.0.0",
"version": "1.1.0",
"description": "Evented XML generation using the Genx C library",
"keywords": [
"xml",
@@ -15,18 +15,22 @@
"engines": {
"node": ">=0.8.0"
},
"license": "BSD-3-Clause",
"licenses": [
{
"type": "BSD",
"url": "https://github.com/wezm/node-genx/blob/master/LICENSE"
}
],
"scripts": {
"preinstall": "node-gyp configure build",
"test": "mocha"
},
"devDependencies": {
"mocha" : ">=1.8.1",
"should" : ">=1.2.1"
"mocha": ">=1.8.1",
"node-cmake": "^1.1.0",
"should": ">=1.2.1"
},
"dependencies": {
"nan": "^2.1.0"
}
}
View
@@ -33,22 +33,35 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iostream>
#include <node.h>
#include <nan.h>
#include "attribute.h"
using namespace v8;
using namespace node;
using v8::Function;
using v8::FunctionTemplate;
using v8::Object;
using v8::Handle;
using v8::HandleScope;
using v8::Local;
using v8::Isolate;
using v8::String;
using v8::Value;
using v8::External;
Persistent<FunctionTemplate> Attribute::constructor_template;
Nan::Persistent<Function> Attribute::constructor;
void Attribute::Initialize(Handle<Object> target)
void Attribute::Initialize(Local<Object> exports)
{
HandleScope scope;
Nan::HandleScope scope;
Local <FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
Local<FunctionTemplate> t = FunctionTemplate::New(New);
tpl->SetClassName(Nan::New("Attribute").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Attribute"));
exports->Set(Nan::New("Attribute").ToLocalChecked(), tpl->GetFunction());
constructor.Reset(tpl->GetFunction());
}
Attribute::Attribute(genxAttribute attr) : attribute(attr)
@@ -59,14 +72,13 @@ Attribute::~Attribute()
{
}
Handle<Value> Attribute::New(const Arguments& args)
void Attribute::New(const Nan::FunctionCallbackInfo <Value> &args)
{
HandleScope scope;
REQ_EXT_ARG(0, attr);
REQ_EXT_ARG(0, args);
Attribute* a = new Attribute((genxAttribute)attr->Value());
Attribute *a = new Attribute((genxAttribute) args[0].As<External>()->Value());
a->Wrap(args.This());
return args.This();
args.GetReturnValue().Set(args.This());
}
genxStatus Attribute::add(constUtf8 value)
View
@@ -34,25 +34,22 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef NODE_GENX_ATTRIBUTE_H
#define NODE_GENX_ATTRIBUTE_H
#include <v8.h>
#include <node.h>
#include <nan.h>
extern "C" {
#include "genx.h"
}
#include "node-genx.h"
using namespace v8;
using namespace node;
class Attribute: ObjectWrap
class Attribute : public Nan::ObjectWrap
{
private:
genxAttribute attribute;
public:
static Persistent<FunctionTemplate> constructor_template;
static void Initialize(Handle<Object> target);
static Nan::Persistent <v8::Function> constructor;
static void Initialize(v8::Local <v8::Object> exports);
Attribute(genxAttribute attr);
@@ -61,7 +58,7 @@ class Attribute: ObjectWrap
genxStatus add(constUtf8 value);
protected:
static Handle<Value> New(const Arguments& args);
static void New(const Nan::FunctionCallbackInfo <v8::Value> &args);
};
#endif
View
@@ -31,19 +31,36 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <node.h>
#include <nan.h>
#include "element.h"
Persistent<FunctionTemplate> Element::constructor_template;
using v8::Function;
using v8::FunctionTemplate;
using v8::Object;
using v8::Handle;
using v8::HandleScope;
using v8::Local;
using v8::Isolate;
using v8::String;
using v8::Value;
using v8::External;
Nan::Persistent<Function> Element::constructor;
void Element::Initialize(Handle<Object> target)
void Element::Initialize(Local <Object> exports)
{
HandleScope scope;
Nan::HandleScope scope;
Local <FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Element").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<FunctionTemplate> t = FunctionTemplate::New(New);
exports->Set(Nan::New("Element").ToLocalChecked(), tpl->GetFunction());
constructor_template = Persistent<FunctionTemplate>::New(t);
constructor_template->InstanceTemplate()->SetInternalFieldCount(1);
constructor_template->SetClassName(String::NewSymbol("Element"));
constructor.Reset(tpl->GetFunction());
}
Element::Element(genxElement el) : element(el)
@@ -54,14 +71,13 @@ Element::~Element()
{
}
Handle<Value> Element::New(const Arguments& args)
void Element::New(const Nan::FunctionCallbackInfo <Value> &args)
{
HandleScope scope;
REQ_EXT_ARG(0, e);
REQ_EXT_ARG(0, args);
Element* el = new Element((genxElement)e->Value());
Element* el = new Element((genxElement) args[0].As<External>()->Value());
el->Wrap(args.This());
return args.This();
args.GetReturnValue().Set(args.This());
}
genxStatus Element::start()
View
@@ -34,25 +34,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef NODE_GENX_ELEMENT_H
#define NODE_GENX_ELEMENT_H
#include <v8.h>
#include <node.h>
#include <nan.h>
extern "C" {
#include "genx.h"
}
#include "node-genx.h"
using namespace v8;
using namespace node;
class Element: ObjectWrap
class Element : public Nan::ObjectWrap
{
private:
genxElement element;
public:
static Persistent<FunctionTemplate> constructor_template;
static Nan::Persistent<v8::Function> constructor;
static void Initialize(Handle<Object> target);
static void Initialize(v8::Local <v8::Object> exports);
Element(genxElement el);
@@ -61,7 +59,7 @@ class Element: ObjectWrap
genxStatus start();
protected:
static Handle<Value> New(const Arguments& args);
static void New(const Nan::FunctionCallbackInfo <v8::Value> &info);
};
#endif
Oops, something went wrong.

0 comments on commit 2e0dce5

Please sign in to comment.