// 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/diff_file.h"

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

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

  GitDiffFile::GitDiffFile(git_diff_file *raw, bool selfFreeing) {
    this->raw = raw;
    this->selfFreeing = selfFreeing;
  }

  GitDiffFile::~GitDiffFile() {
   }

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

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

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

         NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id);
         NODE_SET_PROTOTYPE_METHOD(tpl, "path", Path);
         NODE_SET_PROTOTYPE_METHOD(tpl, "size", Size);
         NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags);
         NODE_SET_PROTOTYPE_METHOD(tpl, "mode", Mode);
  
    Local<Function> _constructor_template = tpl->GetFunction();
    NanAssignPersistent(constructor_template, _constructor_template);
    target->Set(NanNew<String>("DiffFile"), _constructor_template);
  }

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

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

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

    NanReturnValue(args.This());
  }

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

  git_diff_file *GitDiffFile::GetValue() {
    return this->raw;
  }

  git_diff_file **GitDiffFile::GetRefValue() {
    return &this->raw;
  }

      NAN_METHOD(GitDiffFile::Id) {
      NanScope();
      Handle<Value> to;

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

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

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

      const char *  path =
 ObjectWrap::Unwrap<GitDiffFile>(args.This())->GetValue()->path;

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

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

      git_off_t  size =
 ObjectWrap::Unwrap<GitDiffFile>(args.This())->GetValue()->size;

// start convert_to_v8 block
     to = NanNew<Number>(size);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitDiffFile::Flags) {
      NanScope();
      Handle<Value> to;

      uint32_t  flags =
 ObjectWrap::Unwrap<GitDiffFile>(args.This())->GetValue()->flags;

// start convert_to_v8 block
     to = NanNew<Number>(flags);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitDiffFile::Mode) {
      NanScope();
      Handle<Value> to;

      uint16_t  mode =
 ObjectWrap::Unwrap<GitDiffFile>(args.This())->GetValue()->mode;

// start convert_to_v8 block
     to = NanNew<Number>(mode);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
    Persistent<Function> GitDiffFile::constructor_template;
 