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

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


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


#include <iostream>

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

GitDiffPerfdata::GitDiffPerfdata(git_diff_perfdata *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitDiffPerfdata::~GitDiffPerfdata()
{
}

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

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

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

  NODE_SET_PROTOTYPE_METHOD(tpl, "version", Version);
  NODE_SET_PROTOTYPE_METHOD(tpl, "statCalls", StatCalls);
  NODE_SET_PROTOTYPE_METHOD(tpl, "oidCalculations", OidCalculations);

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

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

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

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

  NanReturnValue(args.This());
}

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

git_diff_perfdata *GitDiffPerfdata::GetValue()
{
  return this->raw;
}

git_diff_perfdata **GitDiffPerfdata::GetRefValue()
{
  return &this->raw;
}

NAN_METHOD(GitDiffPerfdata::Version)
{
  NanScope();
  Handle<Value> to;

  unsigned int  version =
    ObjectWrap::Unwrap<GitDiffPerfdata>(args.This())->GetValue()->version;

// start convert_to_v8 block
  to = NanNew<Number>(version);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffPerfdata::StatCalls)
{
  NanScope();
  Handle<Value> to;

  size_t  stat_calls =
    ObjectWrap::Unwrap<GitDiffPerfdata>(args.This())->GetValue()->stat_calls;

// start convert_to_v8 block
  to = NanNew<Number>(stat_calls);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitDiffPerfdata::OidCalculations)
{
  NanScope();
  Handle<Value> to;

  size_t  oid_calculations =
    ObjectWrap::Unwrap<GitDiffPerfdata>(args.This())->GetValue()->oid_calculations;

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