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

  #include "../include/strarray.h"
 
#include <iostream>

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

  GitStrarray::GitStrarray(git_strarray *raw, bool selfFreeing) {
    this->raw = raw;
    this->selfFreeing = selfFreeing;
  }

  GitStrarray::~GitStrarray() {
      if (this->selfFreeing) {
        git_strarray_free(this->raw);
      }
   }

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

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

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

          NODE_SET_PROTOTYPE_METHOD(tpl, "copy", Copy);
           NODE_SET_PROTOTYPE_METHOD(tpl, "strings", Strings);
         NODE_SET_PROTOTYPE_METHOD(tpl, "count", Count);
  
    Local<Function> _constructor_template = tpl->GetFunction();
    NanAssignPersistent(constructor_template, _constructor_template);
    target->Set(NanNew<String>("Strarray"), _constructor_template);
  }

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

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

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

    NanReturnValue(args.This());
  }

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

  git_strarray *GitStrarray::GetValue() {
    return this->raw;
  }

  git_strarray **GitStrarray::GetRefValue() {
    return &this->raw;
  }

  
/*
       * @return Number  result    */
NAN_METHOD(GitStrarray::Copy) {
  NanEscapableScope();

  int result = git_strarray_copy(
ObjectWrap::Unwrap<GitStrarray>(args.This())->GetValue()
,ObjectWrap::Unwrap<GitStrarray>(args.This())->GetValue()
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
       NAN_METHOD(GitStrarray::Strings) {
      NanScope();
      Handle<Value> to;

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

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

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

      size_t  count =
 ObjectWrap::Unwrap<GitStrarray>(args.This())->GetValue()->count;

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