static NAN_METHOD(New) {
    NanScope();

    if (args.Length() != 1) {
      EIGENJS_THROW_ERROR_INVALID_ARGUMENT()
      NanReturnUndefined();
    }

    if (!args.IsConstructCall()) {
      v8::Local<v8::Value> argv[] ={ args[0] };
      NanReturnValue(
        base_type::new_instance(
          args
        , sizeof(argv) / sizeof(v8::Local<v8::Value>)
        , argv
        )
      );
    }

    if (Matrix::is_matrix(args[0])) {
      const Matrix* const& rhs_obj =
          node::ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
      const typename Matrix::value_type& rhs_matrix = **rhs_obj;

      if (rhs_matrix.rows() != rhs_matrix.cols()) {
        NanThrowError("PartialPivLU is only for square "
                      "(and moreover invertible) matrices");
        NanReturnUndefined();
      }

      PartialPivLU* obj = new PartialPivLU(rhs_matrix);
      obj->Wrap(args.This());
      NanReturnValue(args.This());
    } else if (MatrixBlock::is_matrixblock(args[0])) {
      const MatrixBlock* const& rhs_obj =
          node::ObjectWrap::Unwrap<MatrixBlock>(args[0]->ToObject());
      const typename MatrixBlock::value_type& rhs_matrixblock = **rhs_obj;

      if (rhs_matrixblock.rows() != rhs_matrixblock.cols()) {
        NanThrowError("PartialPivLU is only for square "
                      "(and moreover invertible) matrices");
        NanReturnUndefined();
      }

      PartialPivLU* obj = new PartialPivLU(rhs_matrixblock);
      obj->Wrap(args.This());
      NanReturnValue(args.This());
    }

    EIGENJS_THROW_ERROR_INVALID_ARGUMENT()
    NanReturnUndefined();
  }
Exemplo n.º 2
0
 static NAN_METHOD(GetPortCount)
 {
     NanScope();
     NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This());
     v8::Local<v8::Integer> result = NanNew<v8::Uint32>(output->out->getPortCount());
     NanReturnValue(result);
 }
static inline NAN_METHOD(register_datasource)
{
    NanScope();
    if (args.Length() != 1 || !args[0]->IsString())
    {
        NanThrowTypeError("first argument must be a path to a mapnik input plugin (.input)");
        NanReturnUndefined();
    }
    std::vector<std::string> names_before = mapnik::datasource_cache::instance().plugin_names();
    std::string path = TOSTR(args[0]);
    mapnik::datasource_cache::instance().register_datasource(path);
    std::vector<std::string> names_after = mapnik::datasource_cache::instance().plugin_names();
    if (names_after.size() > names_before.size())
        NanReturnValue(NanTrue());
    NanReturnValue(NanFalse());
}
Exemplo n.º 4
0
static inline NAN_METHOD(register_fonts)
{
    NanScope();

    try
    {
        if (args.Length() == 0 || !args[0]->IsString())
        {
            NanThrowTypeError("first argument must be a path to a directory of fonts");
            NanReturnUndefined();
        }

        bool found = false;

        std::vector<std::string> const names_before = mapnik::freetype_engine::face_names();

        // option hash
        if (args.Length() == 2){
            if (!args[1]->IsObject())
            {
                NanThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse:Boolean }");
                NanReturnUndefined();
            }

            Local<Object> options = args[1].As<Object>();
            if (options->Has(NanNew("recurse")))
            {
                Local<Value> recurse_opt = options->Get(NanNew("recurse"));
                if (!recurse_opt->IsBoolean())
                {
                    NanThrowTypeError("'recurse' must be a Boolean");
                    NanReturnUndefined();
                }

                bool recurse = recurse_opt->BooleanValue();
                std::string path = TOSTR(args[0]);
                found = mapnik::freetype_engine::register_fonts(path,recurse);
            }
        }
        else
        {
            std::string path = TOSTR(args[0]);
            found = mapnik::freetype_engine::register_fonts(path);
        }

        std::vector<std::string> const& names_after = mapnik::freetype_engine::face_names();
        if (names_after.size() == names_before.size())
            found = false;

        NanReturnValue(NanNew(found));
    }
    catch (std::exception const& ex)
    {
        NanThrowError(ex.what());
        NanReturnUndefined();
    }
}
static inline NAN_METHOD(available_input_plugins)
{
    NanScope();
    std::vector<std::string> names = mapnik::datasource_cache::instance().plugin_names();
    Local<Array> a = NanNew<Array>(names.size());
    for (unsigned i = 0; i < names.size(); ++i)
    {
        a->Set(i, NanNew(names[i].c_str()));
    }
    NanReturnValue(a);
}
Exemplo n.º 6
0
static inline NAN_METHOD(available_font_faces)
{
    NanScope();
    std::vector<std::string> const& names = mapnik::freetype_engine::face_names();
    Local<Array> a = NanNew<Array>(names.size());
    for (unsigned i = 0; i < names.size(); ++i)
    {
        a->Set(i, NanNew(names[i].c_str()));
    }
    NanReturnValue(a);
}
Exemplo n.º 7
0
    static NAN_METHOD(GetPortName)
    {
        NanScope();
        NodeMidiOutput* output = node::ObjectWrap::Unwrap<NodeMidiOutput>(args.This());
        if (args.Length() == 0 || !args[0]->IsUint32()) {
            return NanThrowTypeError("First argument must be an integer");
        }

        unsigned int portNumber = args[0]->Uint32Value();
        v8::Local<v8::String> result = NanNew<v8::String>(output->out->getPortName(portNumber).c_str());
        NanReturnValue(result);
    }
Exemplo n.º 8
0
static inline NAN_METHOD(available_font_files)
{
    NanScope();
    std::map<std::string,std::pair<int,std::string> > const& mapping = mapnik::freetype_engine::get_mapping();
    Local<Object> obj = NanNew<Object>();
    std::map<std::string,std::pair<int,std::string> >::const_iterator itr;
    for (itr = mapping.begin();itr!=mapping.end();++itr)
    {
        obj->Set(NanNew(itr->first.c_str()), NanNew(itr->second.second.c_str()));
    }
    NanReturnValue(obj);
}
Exemplo n.º 9
0
    static NAN_METHOD(New)
    {
        NanScope();

        if (!args.IsConstructCall()) {
            return NanThrowTypeError("Use the new operator to create instances of this object.");
        }

        NodeMidiOutput* output = new NodeMidiOutput();
        output->Wrap(args.This());

        NanReturnValue(args.This());
    }
Exemplo n.º 10
0
  static NAN_METHOD(New) {
    NanScope();

    if (args.IsConstructCall()) {
      double value = args[0]->IsUndefined() ? 0 : args[0]->NumberValue();
      MyObject *obj = new MyObject(value);
      obj->Wrap(args.This());
      NanReturnThis();
    } else {
      const int argc = 1;
      v8::Local<v8::Value> argv[argc] = {args[0]};
      v8::Local<v8::Function> cons = NanNew(constructor);
      NanReturnValue(cons->NewInstance(argc, argv));
    }
  }
Exemplo n.º 11
0
    static NAN_METHOD(New)
    {
        NanScope();

        if (!args.IsConstructCall()) {
            return NanThrowTypeError("Use the new operator to create instances of this object.");
        }

        NodeMidiInput* input = new NodeMidiInput();
        input->message_async.data = input;
        uv_async_init(uv_default_loop(), &input->message_async, NodeMidiInput::EmitMessage);
        input->Wrap(args.This());

        NanReturnValue(args.This());
    }
Exemplo n.º 12
0
    static NAN_METHOD(Do) {
      NanScope();
      EscapeHTML* obj = Unwrap<EscapeHTML>(args.Holder());
      hoedown_buffer* ob = obj->ob;
      NanUtf8String input (args[0]);

      if (ob->asize > obj->maxSize) {
        free(ob->data);
        ob->data = (uint8_t*) malloc(obj->minSize);
        ob->asize = obj->minSize;
      }
      ob->size = 0;

      hoedown_escape_html(ob, (uint8_t*)*input, input.length(), obj->secure);
      NanReturnValue(NanNew<String>((char*)ob->data, ob->size));
    }
Exemplo n.º 13
0
 static NAN_METHOD(GetHandle) {
   NanScope();
   MyObject* obj = node::ObjectWrap::Unwrap<MyObject>(args.This());
   NanReturnValue(NanObjectWrapHandle(obj));
 }
Exemplo n.º 14
0
  static NAN_METHOD(New) {
    const int& args_length = args.Length();

    NanScope();

    if (args_length == 1) {
      if (!args.IsConstructCall()) {
        v8::Local<v8::Value> argv[] = { args[0] };
        NanReturnValue(
          base_type::new_instance(
            args
          , sizeof(argv) / sizeof(v8::Local<v8::Value>)
          , argv
          )
        );
      }

      if (args[0]->IsNumber()) {
        typename value_type::Index size = args[0]->Int32Value();
        if (size >= 0) {
          Vector* obj = new Vector(size);
          obj->Wrap(args.This());
          NanReturnValue(args.This());
        }
      } else if (args[0]->IsArray()) {
        const v8::Local<v8::Array>& array = args[0].As<v8::Array>();
        uint32_t len = array->Length();
        Vector* obj = new Vector(len);
        Vector::value_type& vector = **obj;

        for (uint32_t i = 0; i < len; ++i) {
          const v8::Local<v8::Value>& elem = array->Get(i);
          vector(i, 0) = elem->NumberValue();
        }

        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (Matrix::is_matrix(args[0])) {
        const Matrix* const& rhs_obj =
            node::ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
        const typename Matrix::value_type& rhs_matrix = **rhs_obj;
        const typename Matrix::value_type::Index& rows = rhs_matrix.rows();
        const typename Matrix::value_type::Index& cols = rhs_matrix.cols();

        if (rows != 1 && cols != 1) {
          EIGENJS_THROW_ERROR_THE_MATRIX_SIZE_MUST_BE_1XN_OR_MX1()
          NanReturnUndefined();
        }

        Vector* obj = new Vector(0);

        if (rows > cols) {
          **obj = rhs_matrix;
        } else {
          **obj = rhs_matrix.transpose();
        }

        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (Vector::is_vector(args[0])) {
        const Vector* const& rhs_obj =
            node::ObjectWrap::Unwrap<Vector>(args[0]->ToObject());
        const typename Vector::value_type& rhs_vector = **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_vector;
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (RowVector::is_rowvector(args[0])) {
        const RowVector* const& rhs_obj =
            node::ObjectWrap::Unwrap<RowVector>(args[0]->ToObject());
        const typename RowVector::value_type& rhs_rowvector = **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_rowvector.transpose();
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (MatrixBlock::is_matrixblock(args[0])) {
        const MatrixBlock* const& rhs_obj =
            node::ObjectWrap::Unwrap<MatrixBlock>(args[0]->ToObject());
        const typename MatrixBlock::value_type& rhs_matrixblock = **rhs_obj;
        const typename MatrixBlock::value_type::Index& rows =
            rhs_matrixblock.rows();
        const typename MatrixBlock::value_type::Index& cols =
            rhs_matrixblock.cols();

        if (rows != 1 && cols != 1) {
          EIGENJS_THROW_ERROR_THE_MATRIX_SIZE_MUST_BE_1XN_OR_MX1()
          NanReturnUndefined();
        }

        Vector* obj = new Vector(0);

        if (rows > cols) {
          **obj = rhs_matrixblock;
        } else {
          **obj = rhs_matrixblock.transpose();
        }

        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (VectorBlock::is_vectorblock(args[0])) {
        const VectorBlock* const& rhs_obj =
            node::ObjectWrap::Unwrap<VectorBlock>(args[0]->ToObject());
        const typename VectorBlock::value_type& rhs_vectorblock = **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_vectorblock;
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      } else if (RowVectorBlock::is_rowvectorblock(args[0])) {
        const RowVectorBlock* const& rhs_obj =
            node::ObjectWrap::Unwrap<RowVectorBlock>(args[0]->ToObject());
        const typename RowVectorBlock::value_type& rhs_rowvectorblock =
            **rhs_obj;

        Vector* obj = new Vector(0);
        **obj = rhs_rowvectorblock.transpose();
        obj->Wrap(args.This());
        NanReturnValue(args.This());
      }
    } else if (args_length == 2) {
      if (args[0]->IsNumber() && args[1]->IsNumber()) {
        const typename value_type::Index& rows = args[0]->Int32Value();
        const typename value_type::Index& cols = args[1]->Int32Value();
        (void)cols;

        if (rows >= 0 && cols >= 0) {
          if (args.IsConstructCall()) {
            Vector* obj = new Vector(rows);
            obj->Wrap(args.This());
            NanReturnValue(args.This());
          } else {
           v8::Local<v8::Value> argv[] = { args[0], args[1] };

            NanReturnValue(
              base_type::new_instance(
                args
              , sizeof(argv) / sizeof(v8::Local<v8::Value>)
              , argv
              )
            );
          }
        }
      }
    }

    EIGENJS_THROW_ERROR_INVALID_ARGUMENT()
    NanReturnUndefined();
  }