binding/v8/jsi/dataaccess/Constraint.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 Constraint.cpp
22 
23  \brief Utility functions to register the Constraint class into the Google JavaScript V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../../dataaccess/dataset/Constraint.h"
28 #include "../../common/Utils.h"
29 #include "DataAccess.h"
30 
31 // Boost
32 #include <boost/cstdint.hpp>
33 
34 ::v8::Handle<::v8::Value> Constraint_GetId(const ::v8::Arguments& args)
35 {
36  ::v8::HandleScope hs;
37 
38  if(args.Holder().IsEmpty())
39  return ::v8::ThrowException(::v8::String::New("In order to use the getId method, you must use the object notation: \"id = obj.getId();\""));
40 
41  te::da::Constraint* c = te::v8::common::Unwrap<te::da::Constraint>(args.Holder());
42 
43  if(c == 0)
44  return ::v8::ThrowException(::v8::String::New("Invalid constraint in the getId method!"));
45 
46  unsigned int id = c->getId();
47 
48  ::v8::Local<::v8::Integer> jid = ::v8::Uint32::New(static_cast<boost::uint32_t>(id));
49 
50  return hs.Close(jid);
51 }
52 
53 ::v8::Handle<::v8::Value> Constraint_SetId(const ::v8::Arguments& args)
54 {
55  ::v8::HandleScope hs;
56 
57  if(args.Holder().IsEmpty())
58  return ::v8::ThrowException(::v8::String::New("In order to use setId method, you must use the object notation: \"obj.setId();\""));
59 
60  te::da::Constraint* c = te::v8::common::Unwrap<te::da::Constraint>(args.Holder());
61 
62  if(c == 0)
63  return ::v8::ThrowException(::v8::String::New("Invalid id in setId method!"));
64 
65  if((args.Length() != 1) || args[0].IsEmpty() || !args[0]->IsUint32())
66  return ::v8::ThrowException(::v8::String::New("Invalid id in setId method!"));
67 
68  unsigned int id = args[0]->ToUint32()->Value();
69  c->setId(id);
70 
71  return hs.Close(::v8::Undefined());
72 }
73 
74 ::v8::Handle<::v8::Value> Constraint_GetName(const ::v8::Arguments& args)
75 {
76  ::v8::HandleScope hs;
77 
78  if(args.Holder().IsEmpty())
79  return ::v8::ThrowException(::v8::String::New("In order to use the getName method you must use the object notation: \"name = obj.getName();\""));
80 
81  te::da::Constraint* c = te::v8::common::Unwrap<te::da::Constraint>(args.Holder());
82 
83  if(c == 0)
84  return ::v8::ThrowException(::v8::String::New("Invalid constraint in the getName method!"));
85 
86  const std::string& name = c->getName();
87 
88  ::v8::Local<::v8::String> jname = ::v8::String::New(name.c_str());
89 
90  return hs.Close(jname);
91 }
92 
93 ::v8::Handle<::v8::Value> Constraint_SetName(const ::v8::Arguments& args)
94 {
95  if(args.Length() != 1 || args[0].IsEmpty() || args.Holder().IsEmpty())
96  return ::v8::ThrowException(::v8::String::New("In order to use the setName method, you must use the object notation: \"obj.setName(\"name\");\""));
97 
98  te::da::Constraint* c = te::v8::common::Unwrap<te::da::Constraint>(args.Holder());
99 
100  if(c == 0)
101  return ::v8::ThrowException(::v8::String::New("Invalid constraint in the setName method!"));
102 
103  v8::String::Utf8Value jconnStr(args[0]->ToString());
104 
105  c->setName(*jconnStr);
106 
107  return ::v8::Undefined();
108 }
109 
110 ::v8::Handle<::v8::Value> Constraint_GetDataSetType(const ::v8::Arguments& /*args*/)
111 {
112  return ::v8::Undefined();
113 }
114 
115 ::v8::Handle<::v8::Value> Constraint_SetDataSetType(const ::v8::Arguments& /*args*/)
116 {
117  return ::v8::Undefined();
118 }
119 
120 ::v8::Handle<::v8::Value> Constraint_GetType(const ::v8::Arguments& args)
121 {
122  ::v8::HandleScope hs;
123 
124  if(args.Holder().IsEmpty())
125  return ::v8::ThrowException(::v8::String::New("In order to use the getType method you must use the object notation: \"t = obj.getType();\""));
126 
127  te::da::Constraint* c = te::v8::common::Unwrap<te::da::Constraint>(args.Holder());
128 
129  if(c == 0)
130  return ::v8::ThrowException(::v8::String::New("Invalid constraint in the getType method!"));
131 
133 
134  ::v8::Local<::v8::Integer> jtype = ::v8::Integer::New(static_cast<boost::int32_t>(type));
135 
136  return hs.Close(jtype);
137 }
138 
139 ::v8::Handle<::v8::Value> Constraint_Clone(const ::v8::Arguments& /*args*/)
140 {
141  return ::v8::Undefined();
142 }
143 
144 static ::v8::Persistent<::v8::FunctionTemplate> sg_constraint_template;
145 
146 ::v8::Persistent<::v8::FunctionTemplate>& te::v8::jsi::GetConstraintTemplate()
147 {
148  if(sg_constraint_template.IsEmpty())
149  {
150  ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
151 
152  ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
153 
154  prototype->Set(::v8::String::NewSymbol("getId"), ::v8::FunctionTemplate::New(Constraint_GetId));
155  prototype->Set(::v8::String::NewSymbol("setId"), ::v8::FunctionTemplate::New(Constraint_SetId));
156  prototype->Set(::v8::String::NewSymbol("getName"), ::v8::FunctionTemplate::New(Constraint_GetName));
157  prototype->Set(::v8::String::NewSymbol("setName"), ::v8::FunctionTemplate::New(Constraint_SetName));
158  prototype->Set(::v8::String::NewSymbol("getDataSetType"), ::v8::FunctionTemplate::New(Constraint_GetDataSetType));
159  prototype->Set(::v8::String::NewSymbol("setDataSetType"), ::v8::FunctionTemplate::New(Constraint_SetDataSetType));
160  prototype->Set(::v8::String::NewSymbol("getType"), ::v8::FunctionTemplate::New(Constraint_GetType));
161  prototype->Set(::v8::String::NewSymbol("clone"), ::v8::FunctionTemplate::New(Constraint_Clone));
162 
163  sg_constraint_template = ::v8::Persistent<::v8::FunctionTemplate>::New(result);
164  }
165 
166  return sg_constraint_template;
167 }
168 
virtual void setName(const std::string &name)
It sets the constraint name.
Definition: Constraint.h:126
::v8::Handle<::v8::Value > Constraint_GetDataSetType(const ::v8::Arguments &)
::v8::Handle<::v8::Value > Constraint_SetId(const ::v8::Arguments &args)
JavaScript exporting routine for the TerraLib Data Access module.
::v8::Handle<::v8::Value > Constraint_GetType(const ::v8::Arguments &args)
virtual void setId(unsigned int id)
It sets the constraint identifier.
Definition: Constraint.h:112
::v8::Handle<::v8::Value > Constraint_Clone(const ::v8::Arguments &)
::v8::Handle<::v8::Value > Constraint_GetId(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > Constraint_SetName(const ::v8::Arguments &args)
ConstraintType
A ConstraintType can have one of the following types:
virtual ConstraintType getType() const =0
It returns the constraint type.
virtual unsigned int getId() const
It returns the constraint identifier.
Definition: Constraint.h:103
::v8::Handle<::v8::Value > Constraint_SetDataSetType(const ::v8::Arguments &)
::v8::Persistent<::v8::FunctionTemplate > & GetConstraintTemplate()
It returns a reference to the persistent template of a Constraint object.
::v8::Handle<::v8::Value > Constraint_GetName(const ::v8::Arguments &args)
virtual const std::string & getName() const
It returns the constraint name.
Definition: Constraint.h:119
static::v8::Persistent<::v8::FunctionTemplate > sg_constraint_template
std::string ToString(const XMLCh *const value)
It converts the XML string to a standard C++ string.