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


#include <iostream>

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

GitIndexTime::GitIndexTime(git_index_time *raw, bool selfFreeing)
{
  this->raw = raw;
  this->selfFreeing = selfFreeing;
}

GitIndexTime::~GitIndexTime()
{
}

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

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

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

  NODE_SET_PROTOTYPE_METHOD(tpl, "seconds", Seconds);
  NODE_SET_PROTOTYPE_METHOD(tpl, "nanoseconds", Nanoseconds);

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

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

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

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

  NanReturnValue(args.This());
}

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

git_index_time *GitIndexTime::GetValue()
{
  return this->raw;
}

git_index_time **GitIndexTime::GetRefValue()
{
  return &this->raw;
}

NAN_METHOD(GitIndexTime::Seconds)
{
  NanScope();
  Handle<Value> to;

  git_time_t  seconds =
    ObjectWrap::Unwrap<GitIndexTime>(args.This())->GetValue()->seconds;

// start convert_to_v8 block
  to = NanNew<Number>(seconds);
  // end convert_to_v8 block
  NanReturnValue(to);
}
NAN_METHOD(GitIndexTime::Nanoseconds)
{
  NanScope();
  Handle<Value> to;

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

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