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


#include <iostream>

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

GitDiffLine::GitDiffLine(git_diff_line *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitDiffLine::~GitDiffLine()
{
}

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

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

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

  NODE_SET_PROTOTYPE_METHOD(tpl, "origin", Origin);
  NODE_SET_PROTOTYPE_METHOD(tpl, "oldLineno", OldLineno);
  NODE_SET_PROTOTYPE_METHOD(tpl, "newLineno", NewLineno);
  NODE_SET_PROTOTYPE_METHOD(tpl, "numLines", NumLines);
  NODE_SET_PROTOTYPE_METHOD(tpl, "contentLen", ContentLen);
  NODE_SET_PROTOTYPE_METHOD(tpl, "contentOffset", ContentOffset);
  NODE_SET_PROTOTYPE_METHOD(tpl, "content", Content);

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

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

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

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

  NanReturnValue(args.This());
}

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

git_diff_line *GitDiffLine::GetValue()
{
  return this->raw;
}

git_diff_line **GitDiffLine::GetRefValue()
{
  return &this->raw;
}

NAN_METHOD(GitDiffLine::Origin)
{
  NanScope();
  Handle<Value> to;

  int  origin =
    ObjectWrap::Unwrap<GitDiffLine>(args.This())->GetValue()->origin;

// start convert_to_v8 block
  to = NanNew<Number>(origin);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffLine::OldLineno)
{
  NanScope();
  Handle<Value> to;

  int  old_lineno =
    ObjectWrap::Unwrap<GitDiffLine>(args.This())->GetValue()->old_lineno;

// start convert_to_v8 block
  to = NanNew<Number>(old_lineno);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffLine::NewLineno)
{
  NanScope();
  Handle<Value> to;

  int  new_lineno =
    ObjectWrap::Unwrap<GitDiffLine>(args.This())->GetValue()->new_lineno;

// start convert_to_v8 block
  to = NanNew<Number>(new_lineno);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffLine::NumLines)
{
  NanScope();
  Handle<Value> to;

  int  num_lines =
    ObjectWrap::Unwrap<GitDiffLine>(args.This())->GetValue()->num_lines;

// start convert_to_v8 block
  to = NanNew<Number>(num_lines);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffLine::ContentLen)
{
  NanScope();
  Handle<Value> to;

  size_t  content_len =
    ObjectWrap::Unwrap<GitDiffLine>(args.This())->GetValue()->content_len;

// start convert_to_v8 block
  to = NanNew<Number>(content_len);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffLine::ContentOffset)
{
  NanScope();
  Handle<Value> to;

  git_off_t  content_offset =
    ObjectWrap::Unwrap<GitDiffLine>(args.This())->GetValue()->content_offset;

// start convert_to_v8 block
  to = NanNew<Number>(content_offset);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffLine::Content)
{
  NanScope();
  Handle<Value> to;

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

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

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