binding/v8/jsi/dataaccess/UniqueKey.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 UniqueKey.cpp
22 
23  \brief Utility functions to register the UniqueKey class into the Google JavaScript V8 engine.
24  */
25 
26 // TerraLib
27 #include "../../../../dataaccess/dataset/UniqueKey.h"
28 #include "../../common/Utils.h"
29 #include "DataAccess.h"
30 
31 // Boost
32 #include <boost/cstdint.hpp>
33 
34 ::v8::Handle<::v8::Value> UniqueKey_GetProperties(const ::v8::Arguments& args)
35 {
36  return ::v8::Undefined();
37 }
38 
39 ::v8::Handle<::v8::Value> UniqueKey_SetProperties(const ::v8::Arguments& args)
40 {
41  return ::v8::Undefined();
42 }
43 
44 ::v8::Handle<::v8::Value> UniqueKey_Add(const ::v8::Arguments& args)
45 {
46  return ::v8::Undefined();
47 }
48 
49 ::v8::Handle<::v8::Value> UniqueKey_GetAssociatedIndex(const ::v8::Arguments& args)
50 {
51  return ::v8::Undefined();
52 }
53 
54 ::v8::Handle<::v8::Value> UniqueKey_SetAssociatedIndex(const ::v8::Arguments& args)
55 {
56  return ::v8::Undefined();
57 }
58 
59 ::v8::Handle<::v8::Value> UniqueKey_Replace(const ::v8::Arguments& args)
60 {
61  return ::v8::Undefined();
62 }
63 
64 ::v8::Handle<::v8::Value> UniqueKey_GetType(const ::v8::Arguments& args)
65 {
66  return ::v8::Undefined();
67 }
68 
69 ::v8::Handle<::v8::Value> UniqueKey_Clone(const ::v8::Arguments& args)
70 {
71  ::v8::HandleScope hs;
72 
73  if(args.Holder().IsEmpty())
74  return ::v8::ThrowException(::v8::String::New("In order to use the clone method, you must use the object notation: \"uk = obj.clone();\""));
75 
76  te::da::UniqueKey* uk = te::v8::common::Unwrap<te::da::UniqueKey>(args.Holder());
77 
78  if(uk == 0)
79  return ::v8::ThrowException(::v8::String::New("Invalid unique key in the clone method!"));
80 
81  te::da::Constraint* ukclone = uk->clone();
82 
83  ::v8::Local<::v8::Object> jukclone = te::v8::common::Make(ukclone, te::v8::jsi::GetUniqueKeyTemplate, true);
84 
85  return hs.Close(jukclone);
86 }
87 
88 ::v8::Handle<::v8::Value> UniqueKey_Constructor(const ::v8::Arguments& args)
89 {
90  //::v8::HandleScope hs;
91 
92  //if(!args.IsConstructCall())
93  // return ::v8::ThrowException(::v8::String::New("In order to create a check constraint, you need to call its constructor like: var c = new TeUniqueKey(dt, id);"));
94 
95  //if(args.Holder().IsEmpty())
96  // return ::v8::ThrowException(::v8::String::New("The UniqueKey constructor must use object notation!"));
97 
98  //if(args.Length() != 0)
99  // return ::v8::ThrowException(::v8::String::New("The UniqueKey constructor has no parameters!"));
100 
101  //std::auto_ptr<te::da::UniqueKey> catalog(new te::da::UniqueKey());
102 
103  //::v8::Local<::v8::Object> jcatalog = te::v8::common::Make(catalog.get(), te::v8::jsi::GetUniqueKeyTemplate, true);
104 
105  //catalog.release();
106 
107  //return hs.Close(jcatalog);
108 
109  return ::v8::Undefined();
110 }
111 
112 void te::v8::jsi::RegisterUniqueKey(::v8::Local<::v8::Object>& global)
113 {
114  ::v8::Local<::v8::FunctionTemplate> juk = ::v8::FunctionTemplate::New(UniqueKey_Constructor);
115 
116  global->Set(::v8::String::New("TeUniqueKey"), juk->GetFunction());
117 }
118 
119 static ::v8::Persistent<::v8::FunctionTemplate> sdset_uniquekey_template;
120 
121 ::v8::Persistent<::v8::FunctionTemplate>& te::v8::jsi::GetUniqueKeyTemplate()
122 {
123  if(sdset_uniquekey_template.IsEmpty())
124  {
125  ::v8::Persistent<::v8::FunctionTemplate>& cTpl = GetConstraintTemplate();
126  ::v8::Local<::v8::FunctionTemplate> result = ::v8::FunctionTemplate::New();
127  result->Inherit(cTpl);
128 
129  ::v8::Handle<::v8::ObjectTemplate> prototype = result->PrototypeTemplate();
130 
131  prototype->Set(::v8::String::NewSymbol("getProperties"), ::v8::FunctionTemplate::New(UniqueKey_GetProperties));
132  prototype->Set(::v8::String::NewSymbol("setProperties"), ::v8::FunctionTemplate::New(UniqueKey_SetProperties));
133  prototype->Set(::v8::String::NewSymbol("add"), ::v8::FunctionTemplate::New(UniqueKey_Add));
134  prototype->Set(::v8::String::NewSymbol("getAssociatedIndex"), ::v8::FunctionTemplate::New(UniqueKey_GetAssociatedIndex));
135  prototype->Set(::v8::String::NewSymbol("setAssociatedIndex"), ::v8::FunctionTemplate::New(UniqueKey_SetAssociatedIndex));
136  prototype->Set(::v8::String::NewSymbol("replace"), ::v8::FunctionTemplate::New(UniqueKey_Replace));
137  prototype->Set(::v8::String::NewSymbol("getType"), ::v8::FunctionTemplate::New(UniqueKey_GetType));
138  prototype->Set(::v8::String::NewSymbol("clone"), ::v8::FunctionTemplate::New(UniqueKey_Clone));
139 
140  sdset_uniquekey_template = ::v8::Persistent<::v8::FunctionTemplate>::New(result);
141  }
142 
144 }
::v8::Local<::v8::Object > Make(T *obj, TF tfunc, const bool isOwner)
It creates a new JavaScript object from a C++ object (obj).
::v8::Handle<::v8::Value > UniqueKey_GetAssociatedIndex(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > UniqueKey_GetProperties(const ::v8::Arguments &args)
void RegisterUniqueKey(::v8::Local<::v8::Object > &global)
It registers the UniqueKey class.
::v8::Handle<::v8::Value > UniqueKey_SetProperties(const ::v8::Arguments &args)
JavaScript exporting routine for the TerraLib Data Access module.
Constraint * clone()
It returns a clone of the object.
::v8::Handle<::v8::Value > UniqueKey_Clone(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > UniqueKey_Add(const ::v8::Arguments &args)
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
static::v8::Persistent<::v8::FunctionTemplate > sdset_uniquekey_template
::v8::Handle<::v8::Value > UniqueKey_SetAssociatedIndex(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > UniqueKey_Constructor(const ::v8::Arguments &args)
::v8::Handle<::v8::Value > UniqueKey_Replace(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetConstraintTemplate()
It returns a reference to the persistent template of a Constraint object.
::v8::Handle<::v8::Value > UniqueKey_GetType(const ::v8::Arguments &args)
::v8::Persistent<::v8::FunctionTemplate > & GetUniqueKeyTemplate()
It returns a reference to the persistent template of a UniqueKey object.