// This is a generated file, modify: generate/templates/class_content.cc.
#include <nan.h>
#include <string.h>

extern "C" {
  #include <git2.h>
 }


#include "../include/functions/copy.h"
#include "../include/macros.h"
#include "../include/tree_entry.h"

  #include "../include/oid.h"
 
#include <iostream>

using namespace std;
using namespace v8;
using namespace node;

  GitTreeEntry::GitTreeEntry(git_tree_entry *raw, bool selfFreeing) {
    this->raw = raw;
    this->selfFreeing = selfFreeing;
  }

  GitTreeEntry::~GitTreeEntry() {
   }

  void GitTreeEntry::InitializeComponent(Handle<v8::Object> target) {
    NanScope();

    Local<FunctionTemplate> tpl = NanNew<FunctionTemplate>(JSNewFunction);

    tpl->InstanceTemplate()->SetInternalFieldCount(1);
    tpl->SetClassName(NanNew<String>("TreeEntry"));

         NODE_SET_PROTOTYPE_METHOD(tpl, "removed", Removed);
         NODE_SET_PROTOTYPE_METHOD(tpl, "attr", Attr);
         NODE_SET_PROTOTYPE_METHOD(tpl, "oid", Oid);
         NODE_SET_PROTOTYPE_METHOD(tpl, "filenameLen", FilenameLen);
         NODE_SET_PROTOTYPE_METHOD(tpl, "filename", Filename);
  
    Local<Function> _constructor_template = tpl->GetFunction();
    NanAssignPersistent(constructor_template, _constructor_template);
    target->Set(NanNew<String>("TreeEntry"), _constructor_template);
  }

  NAN_METHOD(GitTreeEntry::JSNewFunction) {
    NanScope();

    if (args.Length() == 0 || !args[0]->IsExternal()) {
         return NanThrowError("A new GitTreeEntry cannot be instantiated.");
     }

    GitTreeEntry* object = new GitTreeEntry(static_cast<git_tree_entry *>(Handle<External>::Cast(args[0])->Value()), args[1]->BooleanValue());
    object->Wrap(args.This());

    NanReturnValue(args.This());
  }

  Handle<Value> GitTreeEntry::New(void *raw, bool selfFreeing) {
    NanEscapableScope();
    Handle<Value> argv[2] = { NanNew<External>((void *)raw), NanNew<Boolean>(selfFreeing) };
    return NanEscapeScope(NanNew<Function>(GitTreeEntry::constructor_template)->NewInstance(2, argv));
  }

  git_tree_entry *GitTreeEntry::GetValue() {
    return this->raw;
  }

  git_tree_entry **GitTreeEntry::GetRefValue() {
    return &this->raw;
  }

      NAN_METHOD(GitTreeEntry::Removed) {
      NanScope();
      Handle<Value> to;

      uint16_t  removed =
 ObjectWrap::Unwrap<GitTreeEntry>(args.This())->GetValue()->removed;

// start convert_to_v8 block
     to = NanNew<Number>(removed);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitTreeEntry::Attr) {
      NanScope();
      Handle<Value> to;

      uint16_t  attr =
 ObjectWrap::Unwrap<GitTreeEntry>(args.This())->GetValue()->attr;

// start convert_to_v8 block
     to = NanNew<Number>(attr);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitTreeEntry::Oid) {
      NanScope();
      Handle<Value> to;

      git_oid * oid =
& ObjectWrap::Unwrap<GitTreeEntry>(args.This())->GetValue()->oid;

// start convert_to_v8 block
  
  if (oid != NULL) {
    // GitOid oid
       to = GitOid::New((void *)oid, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitTreeEntry::FilenameLen) {
      NanScope();
      Handle<Value> to;

      size_t  filename_len =
 ObjectWrap::Unwrap<GitTreeEntry>(args.This())->GetValue()->filename_len;

// start convert_to_v8 block
     to = NanNew<Number>(filename_len);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitTreeEntry::Filename) {
      NanScope();
      Handle<Value> to;

      char *  filename =
 ObjectWrap::Unwrap<GitTreeEntry>(args.This())->GetValue()->filename;

// start convert_to_v8 block
  if (filename){
       to = NanNew<String>(filename);
   }
  else {
    to = NanNull();
  }

  // end convert_to_v8 block
      NanReturnValue(to);
    }
    Persistent<Function> GitTreeEntry::constructor_template;
 