binding/v8/jsi/geometry/GeometryFactory.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file GeometryFactory.cpp
22 
23  \brief Utility functions to register the GeometryFactory class into Google JavaScript V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../../geometry/GeometryFactory.h"
28 #include "../../common/Utils.h"
29 #include "Geometry.h"
30 
31 ::v8::Handle<::v8::Value> GeometryFactory_Make(const ::v8::Arguments& args)
32 {
33  ::v8::HandleScope hs;
34 
35 // check and get arguments
36  if((args.Length() < 2) ||
37  (args[0].IsEmpty()) ||
38  (args[1].IsEmpty()))
39  return ::v8::ThrowException(::v8::String::New("Missing parameter for TeGeometryFactory. The correct syntax is: var my_geom = TeGeometryFactory.make(geomtype, srid)"));
40 
41  int geomType = args[0]->Int32Value();
42  int srid = args[1]->Int32Value();
43 
44  std::auto_ptr<te::gm::Geometry> geom(te::gm::GeometryFactory::make(static_cast<te::gm::GeomType>(geomType), srid));
45 
46 // create JavaScript object
47  ::v8::Local<::v8::Object> jsgeom = te::v8::jsi::Geometry_Make(geom.get(), true);
48 
49  geom.release();
50 
51  return hs.Close(jsgeom);
52 }
53 
54 void te::v8::jsi::RegisterGeometryFactory(::v8::Local<::v8::Object>& global)
55 {
56  ::v8::HandleScope hs;
57 
58  ::v8::Handle<::v8::ObjectTemplate> gfactory = ::v8::ObjectTemplate::New();
59 
60  gfactory->Set(::v8::String::NewSymbol("make"), ::v8::FunctionTemplate::New(GeometryFactory_Make));
61 
62  global->Set(::v8::String::New("TeGeometryFactory"), gfactory->NewInstance());
63 }
64 
static Geometry * make(GeomType t, int srid)
It returns an instance according to the informed geometry type.
::v8::Local<::v8::Object > Geometry_Make(te::gm::Geometry *g, const bool isOwner)
Given a C++ geometry this function creates a new JavaScript geometry cast to the right geometry subty...
void RegisterGeometryFactory(::v8::Local<::v8::Object > &global)
It registers the GeometryFactory class.
::v8::Handle<::v8::Value > GeometryFactory_Make(const ::v8::Arguments &args)