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


#include <iostream>

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

GitDiffHunk::GitDiffHunk(git_diff_hunk *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitDiffHunk::~GitDiffHunk()
{
}

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

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

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

  NODE_SET_PROTOTYPE_METHOD(tpl, "oldStart", OldStart);
  NODE_SET_PROTOTYPE_METHOD(tpl, "oldLines", OldLines);
  NODE_SET_PROTOTYPE_METHOD(tpl, "newStart", NewStart);
  NODE_SET_PROTOTYPE_METHOD(tpl, "newLines", NewLines);
  NODE_SET_PROTOTYPE_METHOD(tpl, "headerLen", HeaderLen);
  NODE_SET_PROTOTYPE_METHOD(tpl, "header", Header);

  Local<Function> _constructor_template = tpl->GetFunction();
  NanAssignPersistent(constructor_template, _constructor_template);
  target->Set(NanNew<String>("DiffHunk"), _constructor_template);
}

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

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

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

  NanReturnValue(args.This());
}

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

git_diff_hunk *GitDiffHunk::GetValue()
{
  return this->raw;
}

git_diff_hunk **GitDiffHunk::GetRefValue()
{
  return &this->raw;
}

NAN_METHOD(GitDiffHunk::OldStart)
{
  NanScope();
  Handle<Value> to;

  int  old_start =
    ObjectWrap::Unwrap<GitDiffHunk>(args.This())->GetValue()->old_start;

// start convert_to_v8 block
  to = NanNew<Number>(old_start);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffHunk::OldLines)
{
  NanScope();
  Handle<Value> to;

  int  old_lines =
    ObjectWrap::Unwrap<GitDiffHunk>(args.This())->GetValue()->old_lines;

// start convert_to_v8 block
  to = NanNew<Number>(old_lines);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffHunk::NewStart)
{
  NanScope();
  Handle<Value> to;

  int  new_start =
    ObjectWrap::Unwrap<GitDiffHunk>(args.This())->GetValue()->new_start;

// start convert_to_v8 block
  to = NanNew<Number>(new_start);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffHunk::NewLines)
{
  NanScope();
  Handle<Value> to;

  int  new_lines =
    ObjectWrap::Unwrap<GitDiffHunk>(args.This())->GetValue()->new_lines;

// start convert_to_v8 block
  to = NanNew<Number>(new_lines);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffHunk::HeaderLen)
{
  NanScope();
  Handle<Value> to;

  size_t  header_len =
    ObjectWrap::Unwrap<GitDiffHunk>(args.This())->GetValue()->header_len;

// start convert_to_v8 block
  to = NanNew<Number>(header_len);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffHunk::Header)
{
  NanScope();
  Handle<Value> to;

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

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

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