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

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

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

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

    Local<Object> object = NanNew<Object>();

        NODE_SET_METHOD(object, "errClear", GiterrClear);
         NODE_SET_METHOD(object, "errDetach", GiterrDetach);
         NODE_SET_METHOD(object, "errLast", GiterrLast);
         NODE_SET_METHOD(object, "errSetOom", GiterrSetOom);
         NODE_SET_METHOD(object, "errSetString", GiterrSetStr);
  
    target->Set(NanNew<String>("Giterr"), object);
  }

  
/*
   */
NAN_METHOD(GitGiterr::GiterrClear) {
  NanEscapableScope();

giterr_clear(
  );
  NanReturnUndefined();
}
   
/*
 * @param Error cpy
     * @return Number  result    */
NAN_METHOD(GitGiterr::GiterrDetach) {
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsObject()) {
    return NanThrowError("Error cpy is required.");
  }

// start convert_from_v8 block
  git_error * from_cpy;
  from_cpy = ObjectWrap::Unwrap<GitError>(args[0]->ToObject())->GetValue();
// end convert_from_v8 block
  int result = giterr_detach(
from_cpy
  );

  Handle<Value> to;
// start convert_to_v8 block
     to = NanNew<Number>(result);
  // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   * @return Error  result    */
NAN_METHOD(GitGiterr::GiterrLast) {
  NanEscapableScope();

  const git_error * result = giterr_last(
  );
  // null checks on pointers
  if (!result) {
    NodeGitPsueodoNanReturnEscapingValue(NanUndefined());
  }

  Handle<Value> to;
// start convert_to_v8 block
  
  if (result != NULL) {
    // GitError result
       to = GitError::New((void *)result, false);
   }
  else {
    to = NanNull();
  }

 // end convert_to_v8 block
  NodeGitPsueodoNanReturnEscapingValue(to);
}
   
/*
   */
NAN_METHOD(GitGiterr::GiterrSetOom) {
  NanEscapableScope();

giterr_set_oom(
  );
  NanReturnUndefined();
}
   
/*
 * @param Number error_class
   * @param String string
     */
NAN_METHOD(GitGiterr::GiterrSetStr) {
  NanEscapableScope();

  if (args.Length() == 0 || !args[0]->IsNumber()) {
    return NanThrowError("Number error_class is required.");
  }

  if (args.Length() == 1 || !args[1]->IsString()) {
    return NanThrowError("String string is required.");
  }

// start convert_from_v8 block
  int from_error_class;
  from_error_class = (int)   args[0]->ToNumber()->Value();
// end convert_from_v8 block
// start convert_from_v8 block
  const char * from_string;

  String::Utf8Value string(args[1]->ToString());
  from_string = (const char *) strdup(*string);
// end convert_from_v8 block
giterr_set_str(
from_error_class
,from_string
  );
  NanReturnUndefined();
}
      Persistent<Function> GitGiterr::constructor_template;
 