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

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

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

  GitIndexEntry::GitIndexEntry(git_index_entry *raw, bool selfFreeing) {
    this->raw = raw;
    this->selfFreeing = selfFreeing;
  }

  GitIndexEntry::~GitIndexEntry() {
   }

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

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

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

         NODE_SET_PROTOTYPE_METHOD(tpl, "ctime", Ctime);
         NODE_SET_PROTOTYPE_METHOD(tpl, "mtime", Mtime);
         NODE_SET_PROTOTYPE_METHOD(tpl, "dev", Dev);
         NODE_SET_PROTOTYPE_METHOD(tpl, "ino", Ino);
         NODE_SET_PROTOTYPE_METHOD(tpl, "mode", Mode);
         NODE_SET_PROTOTYPE_METHOD(tpl, "uid", Uid);
         NODE_SET_PROTOTYPE_METHOD(tpl, "gid", Gid);
         NODE_SET_PROTOTYPE_METHOD(tpl, "fileSize", FileSize);
         NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id);
         NODE_SET_PROTOTYPE_METHOD(tpl, "flags", Flags);
         NODE_SET_PROTOTYPE_METHOD(tpl, "flagsExtended", FlagsExtended);
         NODE_SET_PROTOTYPE_METHOD(tpl, "path", Path);
  
    Local<Function> _constructor_template = tpl->GetFunction();
    NanAssignPersistent(constructor_template, _constructor_template);
    target->Set(NanNew<String>("IndexEntry"), _constructor_template);
  }

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

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

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

    NanReturnValue(args.This());
  }

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

  git_index_entry *GitIndexEntry::GetValue() {
    return this->raw;
  }

  git_index_entry **GitIndexEntry::GetRefValue() {
    return &this->raw;
  }

      NAN_METHOD(GitIndexEntry::Ctime) {
      NanScope();
      Handle<Value> to;

      git_index_time * ctime =
& ObjectWrap::Unwrap<GitIndexEntry>(args.This())->GetValue()->ctime;

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

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

      git_index_time * mtime =
& ObjectWrap::Unwrap<GitIndexEntry>(args.This())->GetValue()->mtime;

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

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

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

// start convert_to_v8 block
     to = NanNew<Number>(dev);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitIndexEntry::Ino) {
      NanScope();
      Handle<Value> to;

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

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

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

// start convert_to_v8 block
     to = NanNew<Number>(mode);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitIndexEntry::Uid) {
      NanScope();
      Handle<Value> to;

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

// start convert_to_v8 block
     to = NanNew<Number>(uid);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitIndexEntry::Gid) {
      NanScope();
      Handle<Value> to;

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

// start convert_to_v8 block
     to = NanNew<Number>(gid);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitIndexEntry::FileSize) {
      NanScope();
      Handle<Value> to;

      git_off_t  file_size =
 ObjectWrap::Unwrap<GitIndexEntry>(args.This())->GetValue()->file_size;

// start convert_to_v8 block
     to = NanNew<Number>(file_size);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitIndexEntry::Id) {
      NanScope();
      Handle<Value> to;

      git_oid * id =
& ObjectWrap::Unwrap<GitIndexEntry>(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(GitIndexEntry::Flags) {
      NanScope();
      Handle<Value> to;

      unsigned short  flags =
 ObjectWrap::Unwrap<GitIndexEntry>(args.This())->GetValue()->flags;

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

      unsigned short  flags_extended =
 ObjectWrap::Unwrap<GitIndexEntry>(args.This())->GetValue()->flags_extended;

// start convert_to_v8 block
     to = NanNew<Number>(flags_extended);
  // end convert_to_v8 block
      NanReturnValue(to);
    }
     NAN_METHOD(GitIndexEntry::Path) {
      NanScope();
      Handle<Value> to;

      const char *  path =
 ObjectWrap::Unwrap<GitIndexEntry>(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);
    }
    Persistent<Function> GitIndexEntry::constructor_template;
 