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

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

#include "../include/functions/copy.h"
#include "../include/strarray.h"

#include "../include/strarray.h"

using namespace v8;
using namespace node;

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

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

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

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

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

  
        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::New) {
  NanScope();

  if (args.Length() == 0 || !args[0]->IsExternal()) {
    return NanThrowError("git_strarray is required.");
  }
  GitStrarray* object = new GitStrarray(static_cast<git_strarray *>(Handle<External>::Cast(args[0])->Value()));
  object->Wrap(args.This());

  NanReturnValue(args.This());
}

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

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


  
NAN_METHOD(GitStrarray::Strings) {
  NanScope();
  Handle<Value> to;

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

    to = NanNew<String>(*strings);
  
    NanReturnValue(to);
}
    
NAN_METHOD(GitStrarray::Count) {
  NanScope();
  Handle<Value> to;

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

    to = NanNew<Uint32>((uint32_t)count);
    NanReturnValue(to);
}
  
Persistent<Function> GitStrarray::constructor_template;
